xref: /php-uv/tests/330-poll.phpt (revision e76ac0dc)
1--TEST--
2Check for poll read and close
3--FILE--
4<?php
5$socket = stream_socket_server("tcp://0.0.0.0:9999", $errno, $errstr);
6stream_set_blocking($socket, 0);
7
8$poll = uv_poll_init(uv_default_loop(), $socket);
9uv_poll_start($poll, UV::READABLE, function($poll, $stat, $ev, $socket) {
10    $conn = stream_socket_accept($socket);
11
12    uv_poll_stop($poll);
13    $pp = uv_poll_init(uv_default_loop(), $conn);
14    uv_poll_start($pp, UV::WRITABLE, function($poll, $stat, $ev, $conn) use (&$pp) {
15        uv_poll_stop($poll);
16        uv_fs_write(uv_default_loop(), $conn, "OK", -1, function($conn, $nwrite){
17            fclose($conn);
18        });
19    });
20});
21
22$address = uv_ip4_addr("0.0.0.0","9999");
23$tcp = uv_tcp_init();
24uv_tcp_connect($tcp, $address, function($client, $stat) {
25    $request = <<<EOF
26HELO
27EOF;
28    uv_write($client, $request, function($client, $stat) {
29        if ($stat == 0) {
30            uv_read_start($client, function($client, $buffer) {
31                echo "$buffer\n";
32                uv_close($client);
33            });
34        } else {
35            uv_close($client);
36        }
37    });
38});
39
40
41uv_run();
42--EXPECT--
43OK
44