2013-02-28 13:42:53 +01:00
|
|
|
--TEST--
|
2014-01-03 19:58:02 +01:00
|
|
|
Check for poll read and close
|
2013-02-28 13:42:53 +01:00
|
|
|
--FILE--
|
|
|
|
<?php
|
2014-01-03 19:58:02 +01:00
|
|
|
$socket = stream_socket_server("tcp://0.0.0.0:9999", $errno, $errstr);
|
|
|
|
stream_set_blocking($socket, 0);
|
|
|
|
|
|
|
|
$poll = uv_poll_init(uv_default_loop(), $socket);
|
2015-01-18 02:58:40 +01:00
|
|
|
uv_poll_start($poll, UV::READABLE, function($poll, $stat, $ev, $socket) {
|
2014-01-03 19:58:02 +01:00
|
|
|
$conn = stream_socket_accept($socket);
|
|
|
|
|
|
|
|
uv_poll_stop($poll);
|
|
|
|
$pp = uv_poll_init(uv_default_loop(), $conn);
|
2015-01-18 02:58:40 +01:00
|
|
|
uv_poll_start($pp, UV::WRITABLE, function($poll, $stat, $ev, $conn) use (&$pp) {
|
2013-02-28 13:42:53 +01:00
|
|
|
uv_poll_stop($poll);
|
2014-01-03 19:58:02 +01:00
|
|
|
uv_fs_write(uv_default_loop(), $conn, "OK", -1, function($conn, $nwrite){
|
|
|
|
fclose($conn);
|
|
|
|
});
|
|
|
|
});
|
2013-02-28 13:42:53 +01:00
|
|
|
});
|
|
|
|
|
2014-01-03 19:58:02 +01:00
|
|
|
$address = uv_ip4_addr("0.0.0.0","9999");
|
|
|
|
$tcp = uv_tcp_init();
|
2015-01-18 02:58:40 +01:00
|
|
|
uv_tcp_connect($tcp, $address, function($client, $stat) {
|
2014-01-03 19:58:02 +01:00
|
|
|
$request = <<<EOF
|
|
|
|
HELO
|
|
|
|
EOF;
|
2015-01-18 02:58:40 +01:00
|
|
|
uv_write($client, $request, function($client, $stat) {
|
2014-01-03 19:58:02 +01:00
|
|
|
if ($stat == 0) {
|
2020-02-15 17:40:10 +01:00
|
|
|
uv_read_start($client, function($client, $buffer) {
|
2014-01-03 19:58:02 +01:00
|
|
|
echo "$buffer\n";
|
|
|
|
uv_close($client);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
uv_close($client);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-02-28 13:42:53 +01:00
|
|
|
uv_run();
|
|
|
|
--EXPECT--
|
|
|
|
OK
|