MaRequest *maCreateRequest(MaConn *conn) { MaRequest *req; MprHeap *arena; arena = mprAllocHeap(conn->arena, "request", MA_REQ_MEM, 0, NULL); if (arena == 0) { return 0; } req = mprAllocObjWithDestructorZeroed(arena, MaRequest, destroyRequest); if (req == 0) { return 0; } req->conn = conn; req->arena = arena; req->length = -1; req->ifMatch = 1; req->ifModified = 1; req->host = conn->host; req->remainingContent = 0; req->method = 0; req->headers = mprCreateHash(req, MA_VAR_HASH_SIZE); req->formVars = mprCreateHash(req, MA_VAR_HASH_SIZE); req->httpProtocol = "HTTP/1.1"; return req; }
/* * Accept a new client connection. If multithreaded, this will come in on a worker thread dedicated to this connection. * This is called from the listen wait handler. */ int maAcceptConn(MprSocket *sock, MaServer *server, cchar *ip, int port) { MaHostAddress *address; MaHost *host; MaConn *conn; MprSocket *listenSock; MprHeap *arena; int rc; mprAssert(server); mprAssert(sock); mprAssert(ip); mprAssert(port > 0); rc = 0; listenSock = sock->listenSock; mprLog(server, 4, "New connection from %s:%d for %s:%d %s", ip, port, listenSock->ipAddr, listenSock->port, listenSock->sslSocket ? "(secure)" : ""); /* * Map the address onto a suitable host to initially serve the request initially until we can parse the Host header. */ address = (MaHostAddress*) maLookupHostAddress(server, listenSock->ipAddr, listenSock->port); if (address == 0 || (host = mprGetFirstItem(address->vhosts)) == 0) { mprError(server, "No host configured for request %s:%d", listenSock->ipAddr, listenSock->port); mprFree(sock); return 1; } arena = mprAllocHeap(host, "conn", 1, 0, NULL); if (arena == 0) { mprError(server, "Can't create connect arena object. Insufficient memory."); mprFree(sock); return 1; } conn = createConn(arena, host, sock, ip, port, address); if (conn == 0) { mprError(server, "Can't create connect object. Insufficient memory."); mprFree(sock); mprFree(arena); return 1; } conn->arena = arena; if (maAddConn(host, conn) < 0) { mprFree(sock); #if BLD_FEATURE_MULTITHREAD mprEnableSocketEvents(listenSock); #endif mprFree(arena); return 1; } mprSetSocketCallback(conn->sock, (MprSocketProc) ioEvent, conn, MPR_READABLE, MPR_NORMAL_PRIORITY); #if BLD_FEATURE_MULTITHREAD mprEnableSocketEvents(listenSock); #endif return rc; }
/* DB Constructor and also used for constructor for sub classes. function Debugger(connectionString: String) */ static EjsVar *debuggerConstructor(Ejs *ejs, EjsDebugger *db, int argc, EjsVar **argv) { debugger3 *sdb; cchar *path; path = ejsGetString(ejs, argv[0]); db->ejs = ejs; /* * Create a memory context for use by debugger. This is a virtual paged memory region. * TODO OPT - Could do better for running applications. */ #if MAP_ALLOC db->arena = mprAllocArena(ejs, "debugger", EJS_MAX_SQLITE_MEM, !USE_TLS, 0); if (db->arena == 0) { return 0; } SET_CTX(db->arena); #else db->arena = mprAllocHeap(ejs, "debugger", EJS_MAX_SQLITE_MEM, 1, 0); if (db->arena == 0) { return 0; } SET_CTX(db->arena); #endif #if UNUSED EjsDebugger **dbp; /* * Create a destructor object so we can cleanup and close the database. Must create after the arena so it will be * invoked before the arena is freed. */ if ((dbp = mprAllocWithDestructor(ejs, sizeof(void*), (MprDestructor) sqldbDestructor)) == 0) { ejsThrowMemoryError(ejs); return 0; } *dbp = db; #endif sdb = 0; if (debugger3_open(path, &sdb) != SQLITE_OK) { ejsThrowIOError(ejs, "Cannot open database %s", path); return 0; } db->sdb = sdb; debugger3_busy_timeout(sdb, ME_MAX_SQLITE_DURATION); debugger3_soft_heap_limit(ME_MAX_SQLITE_MEM); return 0; }