Skip to content

Commit 41cd552

Browse files
committed
Close the server socket in php bind stager
This was previously left dangling, which leaves the port open, but doesn't do anything with subsequent connections.
1 parent 9246f7a commit 41cd552

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

data/php/bind_tcp.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,27 @@
99
$srvsock = stream_socket_server("tcp://{$ipaddr}:{$port}");
1010
if (!$srvsock) { die(); }
1111
$s = stream_socket_accept($srvsock, -1);
12+
fclose($srvsock);
1213
$s_type = 'stream';
1314
} elseif (is_callable('socket_create_listen')) {
1415
$srvsock = socket_create_listen(AF_INET, SOCK_STREAM, SOL_TCP);
1516
if (!$res) { die(); }
1617
$s = socket_accept($srvsock);
18+
socket_close($srvsock);
1719
$s_type = 'socket';
1820
} elseif (is_callable('socket_create')) {
1921
$srvsock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
2022
$res = socket_bind($srvsock, $ipaddr, $port);
2123
if (!$res) { die(); }
2224
$s = socket_accept($srvsock);
25+
socket_close($srvsock);
2326
$s_type = 'socket';
2427
} else {
2528
die();
2629
}
2730
if (!$s) { die(); }
2831

29-
switch ($s_type) {
32+
switch ($s_type) {
3033
case 'stream': $len = fread($s, 4); break;
3134
case 'socket': $len = socket_read($s, 4); break;
3235
}
@@ -40,7 +43,7 @@
4043

4144
$b = '';
4245
while (strlen($b) < $len) {
43-
switch ($s_type) {
46+
switch ($s_type) {
4447
case 'stream': $b .= fread($s, $len-strlen($b)); break;
4548
case 'socket': $b .= socket_read($s, $len-strlen($b)); break;
4649
}

0 commit comments

Comments
 (0)