From 23ba840bfb19932f599e43b2615b2409ad18807c Mon Sep 17 00:00:00 2001 From: "William A. Rowe Jr" Date: Thu, 14 Mar 2002 04:06:02 +0000 Subject: [PATCH] Our ap_listeners were binding to IIS sockets, other Apache instances' listeners, the bottoms of peoples' shoes, etc. Wait to set SO_REUSEADDR on Win32 until the parent is certain the port is all ours. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@93924 13f79535-47bb-0310-9956-ffa450edef68 --- server/listen.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/server/listen.c b/server/listen.c index 770b79b500..a5b4b0c14e 100644 --- a/server/listen.c +++ b/server/listen.c @@ -91,6 +91,7 @@ static apr_status_t make_sock(apr_pool_t *p, ap_listen_rec *server) int one = 1; apr_status_t stat; +#ifndef WIN32 stat = apr_setsocketopt(s, APR_SO_REUSEADDR, one); if (stat != APR_SUCCESS && stat != APR_ENOTIMPL) { ap_log_perror(APLOG_MARK, APLOG_CRIT, stat, p, @@ -99,6 +100,7 @@ static apr_status_t make_sock(apr_pool_t *p, ap_listen_rec *server) apr_socket_close(s); return stat; } +#endif stat = apr_setsocketopt(s, APR_SO_KEEPALIVE, one); if (stat != APR_SUCCESS && stat != APR_ENOTIMPL) { @@ -160,6 +162,27 @@ static apr_status_t make_sock(apr_pool_t *p, ap_listen_rec *server) return stat; } +#ifdef WIN32 + /* I seriously doubt that this would work on Unix; I have doubts that + * it entirely solves the problem on Win32. However, since setting + * reuseaddr on the listener -prior- to binding the socket has allowed + * us to attach to the same port as an already running instance of + * Apache, or even another web server, we cannot identify that this + * port was exclusively granted to this instance of Apache. + * + * So set reuseaddr, but do not attempt to do so until we have the + * parent listeners successfully bound. + */ + stat = apr_setsocketopt(s, APR_SO_REUSEADDR, one); + if (stat != APR_SUCCESS && stat != APR_ENOTIMPL) { + ap_log_perror(APLOG_MARK, APLOG_CRIT, stat, p, + "make_sock: for address %pI, setsockopt: (SO_REUSEADDR)", + server->bind_addr); + apr_socket_close(s); + return stat; + } +#endif + #if APR_HAS_SO_ACCEPTFILTER #ifndef ACCEPT_FILTER_NAME #define ACCEPT_FILTER_NAME "dataready" -- 2.40.0