libmicrohttpd

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

commit 0af992b3a2aee012ae06ad9873694f581549d0c7
parent 8f6c5894b30ea08e9b03b4fcf0d154ddfec124a9
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Mon, 14 Nov 2016 21:27:22 +0300

Fixed usage of MHD with MHD_OPTION_LISTENING_ADDRESS_REUSE on Linux 3.2, 3.4 (longterm)

Diffstat:
MChangeLog | 9++++++++-
Msrc/include/microhttpd.h | 2+-
Msrc/microhttpd/daemon.c | 35++++++++---------------------------
3 files changed, 17 insertions(+), 29 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,10 @@ +Mon Nov 14 22:18:30 MSK 2016 + Fixed unintentional usage of SO_REUSEADDR on W32. + Added support for SO_EXCLBIND on Solaris. + Fixed using MHD with MHD_OPTION_LISTENING_ADDRESS_REUSE + on Linux kernels before 3.9 (longterm 3.2 and 3.4 + are still supported). -EG + Sun Nov 13 19:16:38 CET 2016 Fixed a few race issues on suspend-resume in cases where the application uses threads even though MHD did not (or at least @@ -5,7 +12,7 @@ Sun Nov 13 19:16:38 CET 2016 the timeout list, avoiding manipulating it for suspended connections. Finally, eliminated calling application logic on suspended connections (which before could happen under - certain circumstances). + certain circumstances). -CG Thu Nov 11 20:49:23 MSK 2016 Added support for various forms of diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h @@ -126,7 +126,7 @@ typedef intptr_t ssize_t; * Current version of the library. * 0x01093001 = 1.9.30-1. */ -#define MHD_VERSION 0x00095209 +#define MHD_VERSION 0x00095210 /** * MHD-internal return code for "YES". diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -5012,36 +5012,18 @@ MHD_start_daemon_va (unsigned int flags, { /* User requested to allow reusing listening address:port. * Use SO_REUSEADDR on Windows and SO_REUSEPORT on most platforms. - * Fail if SO_REUSEPORT does not exist or setsockopt fails. + * Fail if SO_REUSEPORT is not defined or setsockopt fails. */ -#ifdef _WIN32 /* SO_REUSEADDR on W32 has the same semantics as SO_REUSEPORT on BSD/Linux */ +#if defined(_WIN32) || defined(SO_REUSEPORT) if (0 > setsockopt (socket_fd, SOL_SOCKET, - SO_REUSEADDR, - (void*)&on, sizeof (on))) - { -#ifdef HAVE_MESSAGES - MHD_DLOG (daemon, - "setsockopt failed: %s\n", - MHD_socket_last_strerr_ ()); -#endif - goto free_and_fail; - } -#else -#ifndef SO_REUSEPORT -#ifdef LINUX -/* Supported since Linux 3.9, but often not present (or commented out) - in the headers at this time; but 15 is reserved for this and - thus should be safe to use. */ -#define SO_REUSEPORT 15 -#endif -#endif -#ifdef SO_REUSEPORT - if (0 > setsockopt (socket_fd, - SOL_SOCKET, +#ifndef _WIN32 SO_REUSEPORT, +#else /* _WIN32 */ + SO_REUSEADDR, +#endif /* _WIN32 */ (void *) &on, sizeof (on))) { @@ -5052,7 +5034,7 @@ MHD_start_daemon_va (unsigned int flags, #endif goto free_and_fail; } -#else +#else /* !_WIN32 && !SO_REUSEPORT */ /* we're supposed to allow address:port re-use, but on this platform we cannot; fail hard */ #ifdef HAVE_MESSAGES @@ -5060,8 +5042,7 @@ MHD_start_daemon_va (unsigned int flags, _("Cannot allow listening address reuse: SO_REUSEPORT not defined\n")); #endif goto free_and_fail; -#endif -#endif +#endif /* !_WIN32 && !SO_REUSEPORT */ } else /* if (daemon->listening_address_reuse < 0) */ {