Files
Investidor-V2/tests/Fixtures/ClamDStallServer.php
nala 1106509116
tests / ci (push) Canceled after 0s
vrsao 2
2026-10-08 14:02:01 +02:00

60 lines
1.7 KiB
PHP

<?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);