Skip to content

Commit 74888be

Browse files
valganikic
authored andcommitted
OpenSSL: Improve non-blocking eof test
1 parent 7a9c20f commit 74888be

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

ext/openssl/tests/ServerClientTestCase.inc

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ function phpt_notify($worker = WORKER_DEFAULT_NAME)
99
ServerClientTestCase::getInstance()->notify($worker);
1010
}
1111

12-
function phpt_wait($worker = WORKER_DEFAULT_NAME)
12+
function phpt_wait($worker = WORKER_DEFAULT_NAME, $timeout = null)
1313
{
14-
ServerClientTestCase::getInstance()->wait($worker);
14+
ServerClientTestCase::getInstance()->wait($worker, $timeout);
1515
}
1616

1717
/**
@@ -121,9 +121,24 @@ class ServerClientTestCase
121121
}
122122
}
123123

124-
public function wait($worker)
124+
public function wait($worker, $timeout = null)
125125
{
126-
fgets($this->isWorker ? STDIN : $this->workerStdOut[$worker]);
126+
$handle = $this->isWorker ? STDIN : $this->workerStdOut[$worker];
127+
if ($timeout === null) {
128+
fgets($handle);
129+
return true;
130+
}
131+
132+
stream_set_blocking($handle, false);
133+
$read = [$handle];
134+
$result = stream_select($read, $write, $except, $timeout);
135+
if (!$result) {
136+
return false;
137+
}
138+
139+
fgets($handle);
140+
stream_set_blocking($handle, true);
141+
return true;
127142
}
128143

129144
public function notify($worker)

ext/openssl/tests/bug77390.phpt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,21 @@ $clientCode = <<<'CODE'
2323
2424
$read = [$fp];
2525
$buf = '';
26-
$printed = false;
26+
$warmedUp = false;
2727
while (stream_select($read, $write, $except, 1000)) {
2828
$chunk = stream_get_contents($fp, 4096);
29-
if ($chunk !== "") {
30-
var_dump($chunk);
31-
$buf .= $chunk;
32-
} elseif (!$printed) {
33-
$printed = true;
34-
var_dump($chunk);
29+
$buf .= $chunk;
30+
phpt_notify('proxy');
31+
if (!$warmedUp) {
32+
if ($buf !== 'warmup') {
33+
continue;
34+
}
35+
$warmedUp = true;
36+
$buf = '';
37+
phpt_notify('server');
38+
continue;
3539
}
40+
var_dump($chunk);
3641
if ($buf === 'hello, world') {
3742
break;
3843
}
@@ -51,6 +56,8 @@ $serverCode = <<<'CODE'
5156
phpt_notify();
5257
5358
$conn = stream_socket_accept($fp);
59+
fwrite($conn, 'warmup');
60+
phpt_wait();
5461
fwrite($conn, 'hello, world');
5562
5663
phpt_wait();
@@ -82,7 +89,7 @@ $proxyCode = <<<'CODE'
8289
$parts = str_split($data, (int) ceil(strlen($data) / 3));
8390
foreach ($parts as $part) {
8491
fwrite($conn, $part);
85-
usleep(1000);
92+
phpt_wait(null, 1);
8693
}
8794
} else {
8895
fwrite($conn, $data);
@@ -116,4 +123,5 @@ ServerClientTestCase::getInstance()->run($clientCode, [
116123
?>
117124
--EXPECT--
118125
string(0) ""
126+
string(0) ""
119127
string(12) "hello, world"

0 commit comments

Comments
 (0)