abyss_bool ConnProcess(TConn * const connectionP) { /*---------------------------------------------------------------------------- Drive the main processing of a connection -- run the connection's "job" function, which should read HTTP requests from the connection and send HTTP responses. If we succeed, we guarantee the connection's "done" function will get called some time after all processing is complete. It might be before we return or some time after. If we fail, we guarantee the "done" function will not be called. -----------------------------------------------------------------------------*/ abyss_bool retval; if (connectionP->hasOwnThread) { /* There's a background thread to handle this connection. Set it running. */ retval = ThreadRun(connectionP->threadP); } else { /* No background thread. We just handle it here while Caller waits. */ (connectionP->job)(connectionP); connDone(connectionP); retval = TRUE; } return retval; }
static void threadDone(void * const userHandle) { TConn * const connectionP = userHandle; connDone(connectionP); }
void Connection::doConnect() { // Check for errors in the connection process -- if they haven't // already been detected. if (! in_error_) { int error; socklen_t len = sizeof(error); getsockopt(client_fd_, SOL_SOCKET, SO_ERROR, &error, &len); if (error != 0) { error_string_.append("Connect failed"); error_string_.append(strerror(error)); in_error_ = true; } else { // Put the underlying descriptor in a state to accept reads and // writes. closed_ = false; Callback<void>* read_cb = makeCallableMany(&Connection::doRead, this); Callback<void>* write_cb = makeCallableMany(&Connection::doWrite, this); io_desc_->setUpCalls(read_cb, write_cb); } } // Run the sub-class's code for connection handling. connDone(); // This release() matches the acquire on the startConnect() call. release(); }