apr_status_t h2_conn_io_read(h2_conn_io *io, apr_read_type_e block, h2_conn_io_on_read_cb on_read_cb, void *puser) { apr_status_t status; int done = 0; ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, io->connection, "h2_conn_io: try read, block=%d", block); if (!APR_BRIGADE_EMPTY(io->input)) { /* Seems something is left from a previous read, lets * satisfy our caller with the data we already have. */ status = h2_conn_io_bucket_read(io, block, on_read_cb, puser, &done); apr_brigade_cleanup(io->input); if (status != APR_SUCCESS || done) { return status; } } /* We only do a blocking read when we have no streams to process. So, * in httpd scoreboard lingo, we are in a KEEPALIVE connection state. * When reading non-blocking, we do have streams to process and update * child with NULL request. That way, any current request information * in the scoreboard is preserved. */ if (block == APR_BLOCK_READ) { ap_update_child_status_from_conn(io->connection->sbh, SERVER_BUSY_KEEPALIVE, io->connection); } else { ap_update_child_status(io->connection->sbh, SERVER_BUSY_READ, NULL); } /* TODO: replace this with a connection filter itself, so that we * no longer need to transfer incoming buckets to our own brigade. */ status = ap_get_brigade(io->connection->input_filters, io->input, AP_MODE_READBYTES, block, 64 * 4096); switch (status) { case APR_SUCCESS: return h2_conn_io_bucket_read(io, block, on_read_cb, puser, &done); case APR_EOF: case APR_EAGAIN: break; default: ap_log_cerror(APLOG_MARK, APLOG_DEBUG, status, io->connection, "h2_conn_io: error reading"); break; } return status; }
static int ap_process_http_async_connection(conn_rec *c) { request_rec *r; conn_state_t *cs = c->cs; AP_DEBUG_ASSERT(cs != NULL); AP_DEBUG_ASSERT(cs->state == CONN_STATE_READ_REQUEST_LINE); while (cs->state == CONN_STATE_READ_REQUEST_LINE) { ap_update_child_status_from_conn(c->sbh, SERVER_BUSY_READ, c); if ((r = ap_read_request(c))) { c->keepalive = AP_CONN_UNKNOWN; /* process the request if it was read without error */ ap_update_child_status(c->sbh, SERVER_BUSY_WRITE, r); if (r->status == HTTP_OK) { cs->state = CONN_STATE_HANDLER; ap_process_async_request(r); /* After the call to ap_process_request, the * request pool may have been deleted. We set * r=NULL here to ensure that any dereference * of r that might be added later in this function * will result in a segfault immediately instead * of nondeterministic failures later. */ r = NULL; } if (cs->state != CONN_STATE_WRITE_COMPLETION && cs->state != CONN_STATE_SUSPENDED) { /* Something went wrong; close the connection */ cs->state = CONN_STATE_LINGER; } } else { /* ap_read_request failed - client may have closed */ cs->state = CONN_STATE_LINGER; } } return OK; }
static int ap_process_http_sync_connection(conn_rec *c) { request_rec *r; conn_state_t *cs = c->cs; apr_socket_t *csd = NULL; int mpm_state = 0; /* * Read and process each request found on our connection * until no requests are left or we decide to close. */ ap_update_child_status_from_conn(c->sbh, SERVER_BUSY_READ, c); while ((r = ap_read_request(c)) != NULL) { c->keepalive = AP_CONN_UNKNOWN; /* process the request if it was read without error */ ap_update_child_status(c->sbh, SERVER_BUSY_WRITE, r); if (r->status == HTTP_OK) { if (cs) cs->state = CONN_STATE_HANDLER; ap_process_request(r); /* After the call to ap_process_request, the * request pool will have been deleted. We set * r=NULL here to ensure that any dereference * of r that might be added later in this function * will result in a segfault immediately instead * of nondeterministic failures later. */ r = NULL; } if (c->keepalive != AP_CONN_KEEPALIVE || c->aborted) break; ap_update_child_status(c->sbh, SERVER_BUSY_KEEPALIVE, NULL); if (ap_mpm_query(AP_MPMQ_MPM_STATE, &mpm_state)) { break; } if (mpm_state == AP_MPMQ_STOPPING) { break; } if (!csd) { csd = ap_get_conn_socket(c); } apr_socket_opt_set(csd, APR_INCOMPLETE_READ, 1); apr_socket_timeout_set(csd, c->base_server->keep_alive_timeout); /* Go straight to select() to wait for the next request */ /* * ******* begin amiya 20140224 ******** */ //ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, APLOGNO(0999) // "After processing request, setting kat: %d",apr_time_sec(c->base_server->keep_alive_timeout)); } return OK; }