mirror of
https://github.com/emikulic/darkhttpd.git
synced 2023-08-10 21:13:08 +03:00
We can handle a request from accept() to close() without having to go through a
single iteration of the select() loop. This commit re-orders the way state == DONE is handled so that keep-alive connections can go straight back into recv_request without visiting select(). Unfortunately, this doesn't fix the keep-alive performance.
This commit is contained in:
parent
5ab0496a9b
commit
008f6f5d4e
@ -2279,18 +2279,8 @@ static void httpd_poll(void)
|
|||||||
switch (conn->state)
|
switch (conn->state)
|
||||||
{
|
{
|
||||||
case DONE:
|
case DONE:
|
||||||
/* clean out stale connections while we're at it */
|
/* do nothing */
|
||||||
if (conn->conn_close)
|
break;
|
||||||
{
|
|
||||||
LIST_REMOVE(conn, entries);
|
|
||||||
free_connection(conn);
|
|
||||||
free(conn);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/* else */
|
|
||||||
recycle_connection(conn);
|
|
||||||
/* And enqueue as RECV_REQUEST. */
|
|
||||||
/* FALLTHROUGH */
|
|
||||||
|
|
||||||
case RECV_REQUEST:
|
case RECV_REQUEST:
|
||||||
MAX_FD_SET(conn->socket, &recv_set);
|
MAX_FD_SET(conn->socket, &recv_set);
|
||||||
@ -2328,26 +2318,45 @@ static void httpd_poll(void)
|
|||||||
/* poll connections that select() says need attention */
|
/* poll connections that select() says need attention */
|
||||||
if (FD_ISSET(sockin, &recv_set)) accept_connection();
|
if (FD_ISSET(sockin, &recv_set)) accept_connection();
|
||||||
|
|
||||||
LIST_FOREACH(conn, &connlist, entries)
|
LIST_FOREACH(conn, &connlist, entries) {
|
||||||
switch (conn->state)
|
switch (conn->state)
|
||||||
{
|
{
|
||||||
case RECV_REQUEST:
|
case RECV_REQUEST:
|
||||||
if (FD_ISSET(conn->socket, &recv_set)) poll_recv_request(conn);
|
if (FD_ISSET(conn->socket, &recv_set)) poll_recv_request(conn);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SEND_HEADER:
|
case SEND_HEADER:
|
||||||
if (FD_ISSET(conn->socket, &send_set)) poll_send_header(conn);
|
if (FD_ISSET(conn->socket, &send_set)) poll_send_header(conn);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SEND_REPLY:
|
case SEND_REPLY:
|
||||||
if (FD_ISSET(conn->socket, &send_set)) poll_send_reply(conn);
|
if (FD_ISSET(conn->socket, &send_set)) poll_send_reply(conn);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DONE:
|
case DONE:
|
||||||
/* do nothing (FIXME) */
|
/* (handled later; ignore for now as it's a valid state) */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: errx(1, "invalid state");
|
default: errx(1, "invalid state");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conn->state == DONE) {
|
||||||
|
/* clean out finished connection */
|
||||||
|
if (conn->conn_close)
|
||||||
|
{
|
||||||
|
LIST_REMOVE(conn, entries);
|
||||||
|
free_connection(conn);
|
||||||
|
free(conn);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* else */
|
||||||
|
recycle_connection(conn);
|
||||||
|
|
||||||
|
/* and go right back to recv_request without going through
|
||||||
|
* select() again.
|
||||||
|
*/
|
||||||
|
poll_recv_request(conn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user