|
| 1 | +--TEST-- |
| 2 | +Bug #72333: fwrite() on non-blocking SSL sockets doesn't work |
| 3 | +--SKIPIF-- |
| 4 | +<?php |
| 5 | +if (!extension_loaded("openssl")) die("skip openssl not loaded"); |
| 6 | +if (!function_exists("proc_open")) die("skip no proc_open"); |
| 7 | +?> |
| 8 | +--FILE-- |
| 9 | +<?php |
| 10 | +$serverCode = <<<'CODE' |
| 11 | + $context = stream_context_create(['ssl' => ['local_cert' => __DIR__ . '/bug54992.pem']]); |
| 12 | +
|
| 13 | + $flags = STREAM_SERVER_BIND|STREAM_SERVER_LISTEN; |
| 14 | + $fp = stream_socket_server("ssl://127.0.0.1:10011", $errornum, $errorstr, $flags, $context); |
| 15 | + phpt_notify(); |
| 16 | + $conn = stream_socket_accept($fp); |
| 17 | +
|
| 18 | + for ($i = 0; $i < 5; $i++) { |
| 19 | + fread($conn, 100000); |
| 20 | + usleep(200000); |
| 21 | + } |
| 22 | +CODE; |
| 23 | + |
| 24 | +$clientCode = <<<'CODE' |
| 25 | + $context = stream_context_create(['ssl' => ['verify_peer' => false, 'peer_name' => 'bug54992.local']]); |
| 26 | +
|
| 27 | + phpt_wait(); |
| 28 | + $fp = stream_socket_client("ssl://127.0.0.1:10011", $errornum, $errorstr, 3000, STREAM_CLIENT_CONNECT, $context); |
| 29 | + stream_set_blocking($fp, 0); |
| 30 | +
|
| 31 | + function blocking_fwrite($fp, $buf) { |
| 32 | + $write = [$fp]; |
| 33 | + $total = 0; |
| 34 | + while (stream_select($read, $write, $except, 180)) { |
| 35 | + $result = fwrite($fp, $buf); |
| 36 | + $total += $result; |
| 37 | + if ($total >= strlen($buf)) { |
| 38 | + return $total; |
| 39 | + } |
| 40 | + $buf = substr($buf, $total); |
| 41 | + } |
| 42 | + } |
| 43 | +
|
| 44 | + $str1 = str_repeat("a", 5000000); |
| 45 | + blocking_fwrite($fp, $str1); |
| 46 | + echo "done"; |
| 47 | +CODE; |
| 48 | + |
| 49 | +include 'ServerClientTestCase.inc'; |
| 50 | +ServerClientTestCase::getInstance()->run($clientCode, $serverCode); |
| 51 | +?> |
| 52 | +--EXPECT-- |
| 53 | +done |
| 54 | + |
0 commit comments