Skip to content

Commit 1184cb0

Browse files
committed
Fix GH-13025: sapi/cli Windows using SO_EXCLUSIVEADDRUSE flag.
With this, connections attempts when ip address and port already bound prior will be refused, thus the behaviod will be closer to unixes ; only little difference tough once the server shutdown the said binding might still be made unavailable for future connections for a little undetermined time.
1 parent 8f6610c commit 1184cb0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

sapi/cli/php_cli_server.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,16 @@ static php_socket_t php_network_listen_socket(const char *host, int *port, int s
12801280
setsockopt(retval, SOL_SOCKET, SO_REUSEADDR, (char*)&val, sizeof(val));
12811281
}
12821282
#endif
1283+
#ifdef SO_EXCLUSIVEADDRUSE
1284+
{
1285+
/**
1286+
* By default, windows allows multiple sockets to bind the same ip with the same port.
1287+
* SO_EXCLUSIVEADDRUSE prevents this while still allowing binding other different ip/port combinations.
1288+
**/
1289+
int val = 1;
1290+
setsockopt(retval, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char*)&val, sizeof(val));
1291+
}
1292+
#endif
12831293

12841294
if (bind(retval, sa, *socklen) == SOCK_CONN_ERR) {
12851295
err = php_socket_errno();

0 commit comments

Comments
 (0)