adjust poll example [ci skip]

This commit is contained in:
Shuhei Tanuma 2012-07-16 00:10:55 +09:00
parent 01ba787a36
commit 32ea5e154f

View File

@ -1,21 +1,25 @@
<?php <?php
$socket = stream_socket_server("tcp://0.0.0.0:9999", $errno, $errstr); $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); $poll = uv_poll_init(uv_default_loop(), $socket);
uv_poll_start($poll, UV::READABLE, function($poll, $stat, $ev, $socket){ uv_poll_start($poll, UV::READABLE, function($poll, $stat, $ev, $socket){
echo "parent poll:\n";
var_dump($stat);
$conn = stream_socket_accept($socket); $conn = stream_socket_accept($socket);
echo "poll";
$pp = uv_poll_init(uv_default_loop(), $conn); $pp = uv_poll_init(uv_default_loop(), $conn);
uv_poll_start($pp, UV::READABLE | UV::WRITABLE, function($poll, $stat, $ev, $conn){ uv_poll_start($pp, UV::WRITABLE, function($poll, $stat, $ev, $conn){
echo "cb"; echo " cb";
var_dump($stat);
uv_fs_write(uv_default_loop(), $conn, "echo", -1, function($fs, $conn){ var_dump($conn);
var_dump($fs);
}); uv_poll_stop($poll);
uv_fs_write(uv_default_loop(), $conn, "Hello World", -1, function($conn, $nwrite){
uv_fs_close(uv_default_loop(), $conn, function(){ var_dump($conn);
echo "close"; fclose($conn);
}); });
}); });
}); });