From: William A. Rowe Jr Date: Thu, 14 Mar 2002 04:06:02 +0000 (+0000) Subject: Our ap_listeners were binding to IIS sockets, other Apache instances' X-Git-Tag: CHANGES~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=92cf62dc0d30ba679518e0bb42ddb265f23c9c2d;p=thirdparty%2Fapache%2Fhttpd.git 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 --- diff --git a/server/listen.c b/server/listen.c index 770b79b5003..a5b4b0c14eb 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"