. Keep-alive connections work now.

. free_connection() now calls log_connection() for us.
. keepalive_connection() -> recycle_connection().
. recycle_connection() calls free_connection() (results in logging).
. Don't reset conn->client in recycle.
. Before main select loop, recycle keep-alive DONE connections.
This commit is contained in:
Emil Mikulic 2003-11-18 09:32:39 +00:00
parent a07492c1a8
commit 3389cc39d4

View File

@ -16,7 +16,7 @@
* x Partial content. * x Partial content.
* x If-Modified-Since. * x If-Modified-Since.
* x Test If-Mod-Since with IE, Phoenix, lynx, links, Opera * x Test If-Mod-Since with IE, Phoenix, lynx, links, Opera
* . Keep-alive connections. * x Keep-alive connections.
* . Chroot, set{uid|gid}. * . Chroot, set{uid|gid}.
* . Port to Win32. * . Port to Win32.
* x Detect Content-Type from a list of content types. * x Detect Content-Type from a list of content types.
@ -949,12 +949,15 @@ static void accept_connection(void)
static void log_connection(const struct connection *conn);
/* --------------------------------------------------------------------------- /* ---------------------------------------------------------------------------
* Cleanly deallocate the internals of a struct connection * Cleanly deallocate the internals of a struct connection
*/ */
static void free_connection(struct connection *conn) static void free_connection(struct connection *conn)
{ {
debugf("free_connection(%d)\n", conn->socket); debugf("free_connection(%d)\n", conn->socket);
log_connection(conn);
if (conn->socket != -1) close(conn->socket); if (conn->socket != -1) close(conn->socket);
if (conn->request != NULL) free(conn->request); if (conn->request != NULL) free(conn->request);
if (conn->method != NULL) free(conn->method); if (conn->method != NULL) free(conn->method);
@ -969,21 +972,17 @@ static void free_connection(struct connection *conn)
/* --------------------------------------------------------------------------- /* ---------------------------------------------------------------------------
* Turn a finished connection around for HTTP/1.1 Keep-Alive. * Recycle a finished connection for HTTP/1.1 Keep-Alive.
*/ */
static void keepalive_connection(struct connection *conn) static void recycle_connection(struct connection *conn)
{ {
debugf("keepalive_connection(%d)\n", conn->socket); int socket_tmp = conn->socket;
if (conn->request != NULL) free(conn->request); debugf("recycle_connection(%d)\n", socket_tmp);
if (conn->method != NULL) free(conn->method); conn->socket = -1; /* so free_connection() doesn't close it */
if (conn->uri != NULL) free(conn->uri); free_connection(conn);
if (conn->referer != NULL) free(conn->referer); conn->socket = socket_tmp;
if (conn->user_agent != NULL) free(conn->user_agent);
if (conn->header != NULL && !conn->header_dont_free) free(conn->header);
if (conn->reply != NULL && !conn->reply_dont_free) free(conn->reply);
if (conn->reply_file != NULL) fclose(conn->reply_file);
conn->client = INADDR_ANY; /* don't reset conn->client */
conn->request = NULL; conn->request = NULL;
conn->request_length = 0; conn->request_length = 0;
conn->method = NULL; conn->method = NULL;
@ -1009,7 +1008,7 @@ static void keepalive_connection(struct connection *conn)
conn->reply_sent = 0; conn->reply_sent = 0;
conn->total_sent = 0; conn->total_sent = 0;
conn->state = RECV_REQUEST; /* ready */ conn->state = RECV_REQUEST; /* ready for another */
} }
@ -1723,10 +1722,21 @@ static void httpd_poll(void)
case DONE: case DONE:
/* clean out stale connections while we're at it */ /* clean out stale connections while we're at it */
LIST_REMOVE(conn, entries); if (conn->conn_close)
log_connection(conn); {
free_connection(conn); LIST_REMOVE(conn, entries);
free(conn); free_connection(conn);
free(conn);
}
else
{
recycle_connection(conn);
/* FIXME: could this be done smarter?
* (lines stolen from `case RECV_REQUEST')
*/
MAX_FD_SET(conn->socket, &recv_set);
bother_with_timeout = 1;
}
break; break;
default: errx(1, "invalid state"); default: errx(1, "invalid state");
@ -1784,7 +1794,6 @@ static void exit_quickly(int sig)
LIST_FOREACH_SAFE(conn, &connlist, entries, next) LIST_FOREACH_SAFE(conn, &connlist, entries, next)
{ {
LIST_REMOVE(conn, entries); LIST_REMOVE(conn, entries);
log_connection(conn);
free_connection(conn); free_connection(conn);
free(conn); free(conn);
} }