mirror of
https://github.com/danog/ext-uv.git
synced 2024-11-30 04:29:01 +01:00
fix test case: poll can't use for file descriptor on most platform
This commit is contained in:
parent
7d210d8033
commit
6af6b98664
@ -1,21 +1,45 @@
|
||||
--TEST--
|
||||
Check for fs read and close
|
||||
Check for poll read and close
|
||||
--FILE--
|
||||
<?php
|
||||
$fd = fopen("testfile","w+");
|
||||
$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);
|
||||
uv_poll_start($poll, UV::READABLE, function($poll, $stat, $ev, $socket){
|
||||
$conn = stream_socket_accept($socket);
|
||||
|
||||
uv_poll_stop($poll);
|
||||
$pp = uv_poll_init(uv_default_loop(), $conn);
|
||||
uv_poll_start($pp, UV::WRITABLE, function($poll, $stat, $ev, $conn) use (&$pp){
|
||||
|
||||
$poll = uv_poll_init(uv_default_loop(), $fd);
|
||||
uv_poll_start($poll, UV::WRITABLE, function($poll, $stat, $ev, $conn){
|
||||
fwrite($conn, "Hello");
|
||||
fclose($conn);
|
||||
$data = file_get_contents("testfile");
|
||||
if ($data == "Hello") {
|
||||
echo "OK";
|
||||
}
|
||||
unlink("testfile");
|
||||
uv_poll_stop($poll);
|
||||
uv_fs_write(uv_default_loop(), $conn, "OK", -1, function($conn, $nwrite){
|
||||
fclose($conn);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$address = uv_ip4_addr("0.0.0.0","9999");
|
||||
$tcp = uv_tcp_init();
|
||||
uv_tcp_connect($tcp, $address, function($client, $stat){
|
||||
$request = <<<EOF
|
||||
HELO
|
||||
EOF;
|
||||
uv_write($client,$request,function($client, $stat){
|
||||
if ($stat == 0) {
|
||||
uv_read_start($client,function($client, $nread, $buffer){
|
||||
echo "$buffer\n";
|
||||
//var_dump($buffer);
|
||||
uv_close($client);
|
||||
});
|
||||
} else {
|
||||
uv_close($client);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
uv_run();
|
||||
--EXPECT--
|
||||
OK
|
||||
|
Loading…
Reference in New Issue
Block a user