/* * Create a new connection object. */ static MaConn *createConn(MprCtx ctx, MaHost *host, MprSocket *sock, cchar *ipAddr, int port, MaHostAddress *address) { MaConn *conn; conn = mprAllocObjWithDestructorZeroed(ctx, MaConn, connectionDestructor); if (conn == 0) { return 0; } if (host->keepAlive) { conn->keepAliveCount = host->maxKeepAlive; } conn->http = host->server->http; conn->sock = sock; mprStealBlock(conn, sock); conn->state = MPR_HTTP_STATE_BEGIN; conn->timeout = host->timeout; conn->remotePort = port; conn->remoteIpAddr = mprStrdup(conn, ipAddr); conn->address = address; conn->host = host; conn->originalHost = host; conn->expire = mprGetTime(conn) + host->timeout; conn->eventMask = -1; maInitSchedulerQueue(&conn->serviceq); #if BLD_FEATURE_MULTITHREAD conn->mutex = mprCreateLock(conn); #endif return conn; }
/* * Createa a new queue for the given stage. If prev is given, then link the new queue after the previous queue. */ MaQueue *maCreateQueue(MaConn *conn, MaStage *stage, int direction, MaQueue *prev) { MaQueue *q; MaResponse *resp; MaLimits *limits; resp = conn->response; limits = &conn->http->limits; q = mprAllocObjZeroed(resp, MaQueue); if (q == 0) { return 0; } maInitQueue(conn->http, q, stage->name); maInitSchedulerQueue(q); q->conn = conn; q->stage = stage; q->close = stage->close; q->open = stage->open; q->start = stage->start; q->direction = direction; q->max = limits->maxStageBuffer; q->packetSize = limits->maxStageBuffer; if (direction == MA_QUEUE_SEND) { q->put = stage->outgoingData; q->service = stage->outgoingService; } else { q->put = stage->incomingData; q->service = stage->incomingService; } if (prev) { maInsertQueue(prev, q); } return q; }