|
| 1 | +--TEST-- |
| 2 | +A stream poll handle takes the descriptor of a TLS stream without touching its buffers |
| 3 | +--EXTENSIONS-- |
| 4 | +openssl |
| 5 | +--SKIPIF-- |
| 6 | +<?php |
| 7 | +if (!function_exists("proc_open")) die("skip no proc_open"); |
| 8 | +?> |
| 9 | +--FILE-- |
| 10 | +<?php |
| 11 | +$certFile = __DIR__ . DIRECTORY_SEPARATOR . 'stream_poll_handle_cast.pem.tmp'; |
| 12 | + |
| 13 | +$serverCode = <<<'CODE' |
| 14 | + $serverCtx = stream_context_create(['ssl' => ['local_cert' => '%s']]); |
| 15 | + $sock = stream_socket_server("tls://127.0.0.1:0", $errno, $errstr, |
| 16 | + STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $serverCtx); |
| 17 | + phpt_notify_server_start($sock); |
| 18 | +
|
| 19 | + $link = stream_socket_accept($sock); |
| 20 | + /* One record of 100 bytes */ |
| 21 | + fwrite($link, str_repeat("x", 100)); |
| 22 | + phpt_wait(); |
| 23 | + fclose($link); |
| 24 | +CODE; |
| 25 | +$serverCode = sprintf($serverCode, $certFile); |
| 26 | + |
| 27 | +$clientCode = <<<'CODE' |
| 28 | + $clientCtx = stream_context_create(['ssl' => [ |
| 29 | + 'verify_peer' => false, |
| 30 | + 'verify_peer_name' => false, |
| 31 | + ]]); |
| 32 | + $sock = stream_socket_client("tls://{{ ADDR }}", $errno, $errstr, 2, STREAM_CLIENT_CONNECT, $clientCtx); |
| 33 | +
|
| 34 | + /* 10 of 100 bytes read, 90 stay inside OpenSSL */ |
| 35 | + stream_set_read_buffer($sock, 0); |
| 36 | + var_dump(strlen(fread($sock, 10))); |
| 37 | +
|
| 38 | + /* Adding the handle must not move them into the stream buffer */ |
| 39 | + $ctx = new Io\Poll\Context(); |
| 40 | + $w = $ctx->add(new StreamPollHandle($sock), [Io\Poll\Event::Read]); |
| 41 | + var_dump(stream_get_meta_data($sock)['unread_bytes']); |
| 42 | +
|
| 43 | + /* Not readiness of the socket */ |
| 44 | + var_dump(count($ctx->wait(Time\Duration::fromMilliseconds(100)))); |
| 45 | + var_dump(strlen(fread($sock, 90))); |
| 46 | +
|
| 47 | + /* The peer's close is */ |
| 48 | + phpt_notify(); |
| 49 | + $fired = $ctx->wait(Time\Duration::fromSeconds(2)); |
| 50 | + var_dump(count($fired), $fired[0] === $w); |
| 51 | + var_dump(fread($sock, 10), feof($sock)); |
| 52 | +CODE; |
| 53 | + |
| 54 | +include 'CertificateGenerator.inc'; |
| 55 | +(new CertificateGenerator())->saveNewCertAsFileWithKey('stream_poll_handle_cast', $certFile); |
| 56 | + |
| 57 | +include 'ServerClientTestCase.inc'; |
| 58 | +ServerClientTestCase::getInstance()->run($clientCode, $serverCode); |
| 59 | +?> |
| 60 | +--CLEAN-- |
| 61 | +<?php |
| 62 | +@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'stream_poll_handle_cast.pem.tmp'); |
| 63 | +?> |
| 64 | +--EXPECT-- |
| 65 | +int(10) |
| 66 | +int(0) |
| 67 | +int(0) |
| 68 | +int(90) |
| 69 | +int(1) |
| 70 | +bool(true) |
| 71 | +string(0) "" |
| 72 | +bool(true) |
0 commit comments