@@ -1074,7 +1074,7 @@ static rem_port* listener_socket(rem_port* port, USHORT flag, const addrinfo* pa
10741074 * binds the socket and calls listen().
10751075 * For multi-client server (SuperServer or SuperClassic) return listener
10761076 * port.
1077- * For classic server - accept incoming connections and fork worker
1077+ * For Classic server - accept incoming connections and fork worker
10781078 * processes, return NULL at exit;
10791079 * On error throw exception.
10801080 *
@@ -1088,27 +1088,28 @@ static rem_port* listener_socket(rem_port* port, USHORT flag, const addrinfo* pa
10881088 if (n == -1 )
10891089 gds__log (" setsockopt: error setting IPV6_V6ONLY to %d" , ipv6_v6only);
10901090
1091+ #ifndef WIN_NT
1092+ // dimitr: on Windows, lack of SO_REUSEADDR works the same way as it was specified on POSIX,
1093+ // i.e. it allows binding to a port in a TIME_WAIT/FIN_WAIT state. If this option
1094+ // is turned on explicitly, then a port can be re-bound regardless of its state,
1095+ // e.g. while it's listening. This is surely not what we want.
1096+ // We set this options for any kind of listener, including standalone Classic.
1097+
1098+ int optval = TRUE ;
1099+ n = setsockopt (port->port_handle , SOL_SOCKET, SO_REUSEADDR,
1100+ (SCHAR*) &optval, sizeof (optval));
1101+ if (n == -1 )
1102+ {
1103+ inet_error (true , port, " setsockopt REUSE" , isc_net_connect_listen_err, INET_ERRNO);
1104+ }
1105+ #endif
1106+
10911107 if (flag & SRVR_multi_client)
10921108 {
10931109 struct linger lingerInfo;
10941110 lingerInfo.l_onoff = 0 ;
10951111 lingerInfo.l_linger = 0 ;
10961112
1097- #ifndef WIN_NT
1098- // dimitr: on Windows, lack of SO_REUSEADDR works the same way as it was specified on POSIX,
1099- // i.e. it allows binding to a port in a TIME_WAIT/FIN_WAIT state. If this option
1100- // is turned on explicitly, then a port can be re-bound regardless of its state,
1101- // e.g. while it's listening. This is surely not what we want.
1102-
1103- int optval = TRUE ;
1104- n = setsockopt (port->port_handle , SOL_SOCKET, SO_REUSEADDR,
1105- (SCHAR*) &optval, sizeof (optval));
1106- if (n == -1 )
1107- {
1108- inet_error (true , port, " setsockopt REUSE" , isc_net_connect_listen_err, INET_ERRNO);
1109- }
1110- #endif
1111-
11121113 // Get any values for SO_LINGER so that they can be reset during
11131114 // disconnect. SO_LINGER should be set by default on the socket
11141115
0 commit comments