libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 725f15796704e8a7655d8a7b83ebdc2451aa5957
parent 74cb555978b85abb46e8bb17eb222946da2585ad
Author: Christian Grothoff <christian@grothoff.org>
Date:   Mon, 16 Mar 2009 22:23:33 +0000

first half of Richard Alimi's patches

Diffstat:
MAUTHORS | 1+
Msrc/daemon/daemon.c | 44+++++++++++++++++++++++++++++---------------
2 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/AUTHORS b/AUTHORS @@ -1,6 +1,7 @@ Primary developers: Christian Grothoff <christian@grothoff.org> Sagie Amir (TLS/SSL support using GNUtls) +Richard Alimi <rich@velvetsea.net> (performance) Code contributions also came from: Chris GauthierDickey <chrisg@cs.du.edu> diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c @@ -658,6 +658,11 @@ MHD_select (struct MHD_Daemon *daemon, int may_block) /* single-threaded, go over everything */ if (MHD_NO == MHD_get_fdset (daemon, &rs, &ws, &es, &max)) return MHD_NO; + + /* If we're at the connection limit, no need to + accept new connections. */ + if ( (daemon->max_connections == 0) && (daemon->socket_fd != -1) ) + FD_CLR(daemon->socket_fd, &rs); } else { @@ -1044,7 +1049,29 @@ MHD_start_daemon_va (unsigned int options, } /** - * Shutdown an http daemon. + * Close all connections for the daemon + */ +static void +MHD_close_connections (struct MHD_Daemon *daemon) +{ + while (daemon->connections != NULL) + { + if (-1 != daemon->connections->socket_fd) + { +#if DEBUG_CLOSE +#if HAVE_MESSAGES + MHD_DLOG (daemon, "MHD shutdown, closing active connections\n"); +#endif +#endif + MHD_connection_close (daemon->connections, + MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN); + } + MHD_cleanup_connections (daemon); + } +} + +/** + * Shutdown an http daemon */ void MHD_stop_daemon (struct MHD_Daemon *daemon) @@ -1069,20 +1096,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) pthread_kill (daemon->pid, SIGALRM); pthread_join (daemon->pid, &unused); } - while (daemon->connections != NULL) - { - if (-1 != daemon->connections->socket_fd) - { -#if DEBUG_CLOSE -#if HAVE_MESSAGES - MHD_DLOG (daemon, "MHD shutdown, closing active connections\n"); -#endif -#endif - MHD_connection_close (daemon->connections, - MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN); - } - MHD_cleanup_connections (daemon); - } + MHD_close_connections (daemon); /* TLS clean up */ #if HTTPS_SUPPORT