@@ -1089,7 +1089,7 @@ static rem_port* listener_socket(rem_port* port, USHORT flag, const addrinfo* pa
1089
1089
* binds the socket and calls listen().
1090
1090
* For multi-client server (SuperServer or SuperClassic) return listener
1091
1091
* port.
1092
- * For classic server - accept incoming connections and fork worker
1092
+ * For Classic server - accept incoming connections and fork worker
1093
1093
* processes, return NULL at exit;
1094
1094
* On error throw exception.
1095
1095
*
@@ -1103,27 +1103,28 @@ static rem_port* listener_socket(rem_port* port, USHORT flag, const addrinfo* pa
1103
1103
if (n == -1 )
1104
1104
gds__log (" setsockopt: error setting IPV6_V6ONLY to %d" , ipv6_v6only);
1105
1105
1106
+ #ifndef WIN_NT
1107
+ // dimitr: on Windows, lack of SO_REUSEADDR works the same way as it was specified on POSIX,
1108
+ // i.e. it allows binding to a port in a TIME_WAIT/FIN_WAIT state. If this option
1109
+ // is turned on explicitly, then a port can be re-bound regardless of its state,
1110
+ // e.g. while it's listening. This is surely not what we want.
1111
+ // We set this options for any kind of listener, including standalone Classic.
1112
+
1113
+ int optval = TRUE ;
1114
+ n = setsockopt (port->port_handle , SOL_SOCKET, SO_REUSEADDR,
1115
+ (SCHAR*) &optval, sizeof (optval));
1116
+ if (n == -1 )
1117
+ {
1118
+ inet_error (true , port, " setsockopt REUSE" , isc_net_connect_listen_err, INET_ERRNO);
1119
+ }
1120
+ #endif
1121
+
1106
1122
if (flag & SRVR_multi_client)
1107
1123
{
1108
1124
struct linger lingerInfo;
1109
1125
lingerInfo.l_onoff = 0 ;
1110
1126
lingerInfo.l_linger = 0 ;
1111
1127
1112
- #ifndef WIN_NT
1113
- // dimitr: on Windows, lack of SO_REUSEADDR works the same way as it was specified on POSIX,
1114
- // i.e. it allows binding to a port in a TIME_WAIT/FIN_WAIT state. If this option
1115
- // is turned on explicitly, then a port can be re-bound regardless of its state,
1116
- // e.g. while it's listening. This is surely not what we want.
1117
-
1118
- int optval = TRUE ;
1119
- n = setsockopt (port->port_handle , SOL_SOCKET, SO_REUSEADDR,
1120
- (SCHAR*) &optval, sizeof (optval));
1121
- if (n == -1 )
1122
- {
1123
- inet_error (true , port, " setsockopt REUSE" , isc_net_connect_listen_err, INET_ERRNO);
1124
- }
1125
- #endif
1126
-
1127
1128
// Get any values for SO_LINGER so that they can be reset during
1128
1129
// disconnect. SO_LINGER should be set by default on the socket
1129
1130
0 commit comments