@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
$server = stream_socket_server('tcp://127.0.0.1:0', $errorCode, $errorMessage);
|
||||
if (! is_resource($server)) {
|
||||
fwrite(STDERR, 'Unable to bind local timeout fixture.');
|
||||
exit(1);
|
||||
}
|
||||
|
||||
echo stream_socket_get_name($server, false)."\n";
|
||||
fflush(STDOUT);
|
||||
for ($request = 0; $request < 3; $request++) {
|
||||
$connection = @stream_socket_accept($server, 5);
|
||||
if (! is_resource($connection)) {
|
||||
break;
|
||||
}
|
||||
|
||||
$command = stream_get_line($connection, 65536, "\0");
|
||||
if ($command === 'zPING') {
|
||||
fwrite($connection, "PONG\0");
|
||||
fclose($connection);
|
||||
continue;
|
||||
}
|
||||
if ($command === 'zVERSION') {
|
||||
fwrite($connection, 'ClamAV 1.5.4/999/'.gmdate('D M j H:i:s Y')."\0");
|
||||
fclose($connection);
|
||||
continue;
|
||||
}
|
||||
if ($command === 'zINSTREAM') {
|
||||
while (true) {
|
||||
$lengthBytes = '';
|
||||
while (strlen($lengthBytes) < 4) {
|
||||
$part = fread($connection, 4 - strlen($lengthBytes));
|
||||
if ($part === false || $part === '') {
|
||||
break 2;
|
||||
}
|
||||
$lengthBytes .= $part;
|
||||
}
|
||||
$length = unpack('Nlength', $lengthBytes)['length'];
|
||||
if ($length === 0) {
|
||||
sleep(4);
|
||||
break;
|
||||
}
|
||||
$remaining = $length;
|
||||
while ($remaining > 0) {
|
||||
$part = fread($connection, min(65536, $remaining));
|
||||
if ($part === false || $part === '') {
|
||||
break 3;
|
||||
}
|
||||
$remaining -= strlen($part);
|
||||
}
|
||||
}
|
||||
fclose($connection);
|
||||
break;
|
||||
}
|
||||
fclose($connection);
|
||||
}
|
||||
fclose($server);
|
||||
Reference in New Issue
Block a user