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.
bug/bundler_fix
James Lee 2014-07-03 16:52:09 -05:00
parent 9246f7a0ce
commit 41cd5527c8
No known key found for this signature in database
GPG Key ID: 2D6094C7CEA0A321
1 changed files with 5 additions and 2 deletions

View File

@ -9,24 +9,27 @@ if (is_callable('stream_socket_server')) {
$srvsock = stream_socket_server("tcp://{$ipaddr}:{$port}"); $srvsock = stream_socket_server("tcp://{$ipaddr}:{$port}");
if (!$srvsock) { die(); } if (!$srvsock) { die(); }
$s = stream_socket_accept($srvsock, -1); $s = stream_socket_accept($srvsock, -1);
fclose($srvsock);
$s_type = 'stream'; $s_type = 'stream';
} elseif (is_callable('socket_create_listen')) { } elseif (is_callable('socket_create_listen')) {
$srvsock = socket_create_listen(AF_INET, SOCK_STREAM, SOL_TCP); $srvsock = socket_create_listen(AF_INET, SOCK_STREAM, SOL_TCP);
if (!$res) { die(); } if (!$res) { die(); }
$s = socket_accept($srvsock); $s = socket_accept($srvsock);
socket_close($srvsock);
$s_type = 'socket'; $s_type = 'socket';
} elseif (is_callable('socket_create')) { } elseif (is_callable('socket_create')) {
$srvsock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $srvsock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$res = socket_bind($srvsock, $ipaddr, $port); $res = socket_bind($srvsock, $ipaddr, $port);
if (!$res) { die(); } if (!$res) { die(); }
$s = socket_accept($srvsock); $s = socket_accept($srvsock);
socket_close($srvsock);
$s_type = 'socket'; $s_type = 'socket';
} else { } else {
die(); die();
} }
if (!$s) { die(); } if (!$s) { die(); }
switch ($s_type) { switch ($s_type) {
case 'stream': $len = fread($s, 4); break; case 'stream': $len = fread($s, 4); break;
case 'socket': $len = socket_read($s, 4); break; case 'socket': $len = socket_read($s, 4); break;
} }
@ -40,7 +43,7 @@ $len = $a['len'];
$b = ''; $b = '';
while (strlen($b) < $len) { while (strlen($b) < $len) {
switch ($s_type) { switch ($s_type) {
case 'stream': $b .= fread($s, $len-strlen($b)); break; case 'stream': $b .= fread($s, $len-strlen($b)); break;
case 'socket': $b .= socket_read($s, $len-strlen($b)); break; case 'socket': $b .= socket_read($s, $len-strlen($b)); break;
} }