libmicrohttpd

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

commit 9403196ad0b67b13d4fefdc4d3da6625d66be34e
parent 8ace389d37855f16c9bef7afd70304b8d5c7da4e
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Tue,  8 Dec 2015 20:48:44 +0000

Change default listen backlog size from 32 to SOMAXCONN, allow to specify required listen backlog size

Diffstat:
Msrc/include/microhttpd.h | 11+++++++++--
Msrc/microhttpd/daemon.c | 11++++++++++-
Msrc/microhttpd/internal.h | 5+++++
3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h @@ -130,7 +130,7 @@ typedef intptr_t ssize_t; * Current version of the library. * 0x01093001 = 1.9.30-1. */ -#define MHD_VERSION 0x00094701 +#define MHD_VERSION 0x00094703 /** * MHD-internal return code for "YES". @@ -967,8 +967,15 @@ enum MHD_OPTION * pointer to a closure to pass to the request completed callback. * The second pointer maybe NULL. */ - MHD_OPTION_NOTIFY_CONNECTION = 27 + MHD_OPTION_NOTIFY_CONNECTION = 27, + /** + * Allow to change maximum length of the queue of pending connections on + * listen socket. If not present than default platform-specific SOMAXCONN + * value is used. This option should be followed by an `unsigned int` + * argument. + */ + MHD_OPTION_LISTEN_BACKLOG_SIZE = 28 }; diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -3397,6 +3397,9 @@ parse_options_va (struct MHD_Daemon *daemon, case MHD_OPTION_LISTENING_ADDRESS_REUSE: daemon->listening_address_reuse = va_arg (ap, unsigned int) ? 1 : -1; break; + case MHD_OPTION_LISTEN_BACKLOG_SIZE: + daemon->listen_backlog_size = va_arg (ap, unsigned int); + break; case MHD_OPTION_ARRAY: oa = va_arg (ap, struct MHD_OptionItem*); i = 0; @@ -3423,6 +3426,7 @@ parse_options_va (struct MHD_Daemon *daemon, case MHD_OPTION_THREAD_POOL_SIZE: case MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE: case MHD_OPTION_LISTENING_ADDRESS_REUSE: + case MHD_OPTION_LISTEN_BACKLOG_SIZE: if (MHD_YES != parse_options (daemon, servaddr, opt, @@ -3731,6 +3735,11 @@ MHD_start_daemon_va (unsigned int flags, daemon->connection_timeout = 0; /* no timeout */ daemon->wpipe[0] = MHD_INVALID_PIPE_; daemon->wpipe[1] = MHD_INVALID_PIPE_; +#ifdef SOMAXCONN + daemon->listen_backlog_size = SOMAXCONN; +#else /* !SOMAXCONN */ + daemon->listen_backlog_size = 511; /* should be safe value */ +#endif /* !SOMAXCONN */ #if HAVE_MESSAGES daemon->custom_error_log = (MHD_LogCallback) &vfprintf; daemon->custom_error_log_cls = stderr; @@ -4098,7 +4107,7 @@ MHD_start_daemon_va (unsigned int flags, } } #endif - if (listen (socket_fd, 32) < 0) + if (listen (socket_fd, daemon->listen_backlog_size) < 0) { #if HAVE_MESSAGES MHD_DLOG (daemon, diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h @@ -1301,6 +1301,11 @@ struct MHD_Daemon */ unsigned int fastopen_queue_size; #endif + + /** + * The size of queue for listen socket. + */ + unsigned int listen_backlog_size; };