/* * Process a socket readable event */ static void readEvent(MaConn *conn) { MaPacket *packet; MprBuf *content; int nbytes, len; do { if ((packet = getPacket(conn, &len)) == 0) { break; } mprAssert(len > 0); content = packet->content; nbytes = mprReadSocket(conn->sock, mprGetBufEnd(content), len); showRequest(content, nbytes, len); if (nbytes > 0) { mprAdjustBufEnd(content, nbytes); maProcessReadEvent(conn, packet); } else { if (mprIsSocketEof(conn->sock)) { conn->dedicated = 0; if (conn->request) { maProcessReadEvent(conn, packet); } } else if (nbytes < 0) { maFailConnection(conn, MPR_HTTP_CODE_COMMS_ERROR, "Communications read error"); } } } while (!conn->disconnected && conn->dedicated); }
/* Read data from the peer. This will use the existing conn->input packet or allocate a new packet if required to hold the data. The number of bytes read is stored in conn->lastRead. SSL connections are traced. Socket error messages are stored in conn->errorMsg. */ static void readPeerData(HttpConn *conn) { HttpPacket *packet; ssize size; if ((packet = getPacket(conn, &size)) != 0) { conn->lastRead = mprReadSocket(conn->sock, mprGetBufEnd(packet->content), size); if (conn->lastRead > 0) { mprAdjustBufEnd(packet->content, conn->lastRead); } else if (conn->lastRead < 0 && mprIsSocketEof(conn->sock)) { if (conn->state < HTTP_STATE_PARSED) { conn->error = 1; conn->rx->eof = 1; } conn->errorMsg = conn->sock->errorMsg ? conn->sock->errorMsg : sclone("Connection reset"); conn->keepAliveCount = 0; conn->lastRead = 0; httpTrace(conn, "connection.close", "context", "msg:'%s'", conn->errorMsg); } } }