diff --git a/src/event_loop/event_loop_io.c b/src/event_loop/event_loop_io.c index 50c625f..233f852 100644 --- a/src/event_loop/event_loop_io.c +++ b/src/event_loop/event_loop_io.c @@ -68,29 +68,15 @@ void event_loop_conn_io_req(event_loop *el, event_loop_conn *conn) { return; } - // Any other negative error message means the read errored out - if (res < 0) { + // Any other negative error message means the read errored out. If res is 0, + // we've reached the end of the input which (usually) means the remote peer + // has closed the connection. Either way, we close the connection. + if (res <= 0) { conn->state = event_loop_conn_state_end; return; } - // Output of 0 and no error means we've reached the end of the input. We run - // try_one_request one more time and close the connection if this doesn't - // change the result. - if (res == 0) { - conn->state = event_loop_conn_state_end; - - return; - } - - // We switch to processing mode if we've reached the end of the data stream, - // or if the read buffer is filled - /* if (res == 0 || c->rbuf_size == MAX_MSG_SIZE) { */ - /* c->state = STATE_PROCESS; */ - /* return false; */ - /* } */ - conn->rbuf_size += (size_t)res; // This loop allows processing multiple requests from a single read buffer diff --git a/src/http_loop/http_loop.c b/src/http_loop/http_loop.c index 407810b..058d631 100644 --- a/src/http_loop/http_loop.c +++ b/src/http_loop/http_loop.c @@ -37,6 +37,8 @@ bool http_loop_handle_request(event_loop_conn *conn) { return false; } + conn->rbuf_read += res; + // If the routing fails, we exit the handler if (!http_loop_route_request(conn)) { return false;