diff options
Diffstat (limited to 'src/microhttpd/daemon.c')
-rw-r--r-- | src/microhttpd/daemon.c | 35 |
1 files changed, 8 insertions, 27 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 3e2d9109..ee43900d 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -5012,36 +5012,18 @@ MHD_start_daemon_va (unsigned int flags, | |||
5012 | { | 5012 | { |
5013 | /* User requested to allow reusing listening address:port. | 5013 | /* User requested to allow reusing listening address:port. |
5014 | * Use SO_REUSEADDR on Windows and SO_REUSEPORT on most platforms. | 5014 | * Use SO_REUSEADDR on Windows and SO_REUSEPORT on most platforms. |
5015 | * Fail if SO_REUSEPORT does not exist or setsockopt fails. | 5015 | * Fail if SO_REUSEPORT is not defined or setsockopt fails. |
5016 | */ | 5016 | */ |
5017 | #ifdef _WIN32 | ||
5018 | /* SO_REUSEADDR on W32 has the same semantics | 5017 | /* SO_REUSEADDR on W32 has the same semantics |
5019 | as SO_REUSEPORT on BSD/Linux */ | 5018 | as SO_REUSEPORT on BSD/Linux */ |
5019 | #if defined(_WIN32) || defined(SO_REUSEPORT) | ||
5020 | if (0 > setsockopt (socket_fd, | 5020 | if (0 > setsockopt (socket_fd, |
5021 | SOL_SOCKET, | 5021 | SOL_SOCKET, |
5022 | SO_REUSEADDR, | 5022 | #ifndef _WIN32 |
5023 | (void*)&on, sizeof (on))) | ||
5024 | { | ||
5025 | #ifdef HAVE_MESSAGES | ||
5026 | MHD_DLOG (daemon, | ||
5027 | "setsockopt failed: %s\n", | ||
5028 | MHD_socket_last_strerr_ ()); | ||
5029 | #endif | ||
5030 | goto free_and_fail; | ||
5031 | } | ||
5032 | #else | ||
5033 | #ifndef SO_REUSEPORT | ||
5034 | #ifdef LINUX | ||
5035 | /* Supported since Linux 3.9, but often not present (or commented out) | ||
5036 | in the headers at this time; but 15 is reserved for this and | ||
5037 | thus should be safe to use. */ | ||
5038 | #define SO_REUSEPORT 15 | ||
5039 | #endif | ||
5040 | #endif | ||
5041 | #ifdef SO_REUSEPORT | ||
5042 | if (0 > setsockopt (socket_fd, | ||
5043 | SOL_SOCKET, | ||
5044 | SO_REUSEPORT, | 5023 | SO_REUSEPORT, |
5024 | #else /* _WIN32 */ | ||
5025 | SO_REUSEADDR, | ||
5026 | #endif /* _WIN32 */ | ||
5045 | (void *) &on, | 5027 | (void *) &on, |
5046 | sizeof (on))) | 5028 | sizeof (on))) |
5047 | { | 5029 | { |
@@ -5052,7 +5034,7 @@ MHD_start_daemon_va (unsigned int flags, | |||
5052 | #endif | 5034 | #endif |
5053 | goto free_and_fail; | 5035 | goto free_and_fail; |
5054 | } | 5036 | } |
5055 | #else | 5037 | #else /* !_WIN32 && !SO_REUSEPORT */ |
5056 | /* we're supposed to allow address:port re-use, but | 5038 | /* we're supposed to allow address:port re-use, but |
5057 | on this platform we cannot; fail hard */ | 5039 | on this platform we cannot; fail hard */ |
5058 | #ifdef HAVE_MESSAGES | 5040 | #ifdef HAVE_MESSAGES |
@@ -5060,8 +5042,7 @@ MHD_start_daemon_va (unsigned int flags, | |||
5060 | _("Cannot allow listening address reuse: SO_REUSEPORT not defined\n")); | 5042 | _("Cannot allow listening address reuse: SO_REUSEPORT not defined\n")); |
5061 | #endif | 5043 | #endif |
5062 | goto free_and_fail; | 5044 | goto free_and_fail; |
5063 | #endif | 5045 | #endif /* !_WIN32 && !SO_REUSEPORT */ |
5064 | #endif | ||
5065 | } | 5046 | } |
5066 | else /* if (daemon->listening_address_reuse < 0) */ | 5047 | else /* if (daemon->listening_address_reuse < 0) */ |
5067 | { | 5048 | { |