@@ -12,97 +12,101 @@ $cacertFile = __DIR__ . DIRECTORY_SEPARATOR . 'bug77390-ca.pem.tmp';
12
12
13
13
$ peerName = 'bug77390 ' ;
14
14
$ clientCode = <<<'CODE'
15
- $context = stream_context_create(['ssl' => ['verify_peer' => false, 'peer_name' => '%s']]);
16
-
17
- phpt_wait('server');
18
- phpt_notify('proxy');
19
-
20
- phpt_wait('proxy');
21
- $fp = stream_socket_client("ssl://127.0.0.1:10012", $errornum, $errorstr, 3000, STREAM_CLIENT_CONNECT, $context);
22
- stream_set_blocking($fp, false);
23
-
24
- $read = [$fp];
25
- $buf = '';
26
- $warmedUp = false;
27
- while (stream_select($read, $write, $except, 1000)) {
28
- $chunk = stream_get_contents($fp, 4096);
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;
39
- }
40
- var_dump($chunk);
41
- if ($buf === 'hello, world') {
42
- break;
43
- }
44
- }
45
-
46
- phpt_notify('server');
47
- phpt_notify('proxy');
15
+ $context = stream_context_create(['ssl' => ['verify_peer' => false, 'peer_name' => '%s']]);
16
+
17
+ phpt_wait('server');
18
+ phpt_notify('proxy');
19
+
20
+ phpt_wait('proxy');
21
+ $fp = stream_socket_client("ssl://127.0.0.1:10012", $errornum, $errorstr, 3000, STREAM_CLIENT_CONNECT, $context);
22
+ stream_set_blocking($fp, false);
23
+
24
+ $read = [$fp];
25
+ $buf = '';
26
+ $emptyChunkPrinted = false;
27
+ $warmedUp = false;
28
+ while (stream_select($read, $write, $except, 1000)) {
29
+ $chunk = stream_get_contents($fp, 4096);
30
+ $buf .= $chunk;
31
+ phpt_notify('proxy');
32
+ if (!$warmedUp) {
33
+ if ($buf !== 'warmup') {
34
+ continue;
35
+ }
36
+ $warmedUp = true;
37
+ $buf = '';
38
+ phpt_notify('server');
39
+ continue;
40
+ }
41
+ if ($chunk !== '' || !$emptyChunkPrinted) {
42
+ $emptyChunkPrinted = true;
43
+ var_dump($chunk);
44
+ }
45
+ if ($buf === 'hello, world') {
46
+ break;
47
+ }
48
+ }
49
+
50
+ phpt_notify('server');
51
+ phpt_notify('proxy');
48
52
CODE;
49
53
$ clientCode = sprintf ($ clientCode , $ peerName );
50
54
51
55
$ serverCode = <<<'CODE'
52
- $context = stream_context_create(['ssl' => ['local_cert' => '%s']]);
53
-
54
- $flags = STREAM_SERVER_BIND|STREAM_SERVER_LISTEN;
55
- $fp = stream_socket_server("ssl://127.0.0.1:10011", $errornum, $errorstr, $flags, $context);
56
- phpt_notify();
57
-
58
- $conn = stream_socket_accept($fp);
59
- fwrite($conn, 'warmup');
60
- phpt_wait();
61
- fwrite($conn, 'hello, world');
62
-
63
- phpt_wait();
64
- fclose($conn);
56
+ $context = stream_context_create(['ssl' => ['local_cert' => '%s']]);
57
+
58
+ $flags = STREAM_SERVER_BIND|STREAM_SERVER_LISTEN;
59
+ $fp = stream_socket_server("ssl://127.0.0.1:10011", $errornum, $errorstr, $flags, $context);
60
+ phpt_notify();
61
+
62
+ $conn = stream_socket_accept($fp);
63
+ fwrite($conn, 'warmup');
64
+ phpt_wait();
65
+ fwrite($conn, 'hello, world');
66
+
67
+ phpt_wait();
68
+ fclose($conn);
65
69
CODE;
66
70
$ serverCode = sprintf ($ serverCode , $ certFile );
67
71
68
72
$ proxyCode = <<<'CODE'
69
- phpt_wait();
70
-
71
- $upstream = stream_socket_client("tcp://127.0.0.1:10011", $errornum, $errorstr, 3000, STREAM_CLIENT_CONNECT);
72
- stream_set_blocking($upstream, false);
73
-
74
- $flags = STREAM_SERVER_BIND|STREAM_SERVER_LISTEN;
75
- $server = stream_socket_server("tcp://127.0.0.1:10012", $errornum, $errorstr, $flags);
76
- phpt_notify();
77
-
78
- $conn = stream_socket_accept($server);
79
- stream_set_blocking($conn, false);
80
-
81
- $read = [$upstream, $conn];
82
- while (stream_select($read, $write, $except, 1)) {
83
- foreach ($read as $fp) {
84
- $data = stream_get_contents($fp);
85
- if ($fp === $conn) {
86
- fwrite($upstream, $data);
87
- } else {
88
- if ($data !== '' && $data[0] === chr(23)) {
89
- $parts = str_split($data, (int) ceil(strlen($data) / 3));
90
- foreach ($parts as $part) {
91
- fwrite($conn, $part);
92
- phpt_wait(null, 1);
93
- }
94
- } else {
95
- fwrite($conn, $data);
96
- }
97
- }
98
- }
99
- if (feof($upstream)) {
100
- break;
101
- }
102
- $read = [$upstream, $conn];
103
- }
104
-
105
- phpt_wait();
73
+ phpt_wait();
74
+
75
+ $upstream = stream_socket_client("tcp://127.0.0.1:10011", $errornum, $errorstr, 3000, STREAM_CLIENT_CONNECT);
76
+ stream_set_blocking($upstream, false);
77
+
78
+ $flags = STREAM_SERVER_BIND|STREAM_SERVER_LISTEN;
79
+ $server = stream_socket_server("tcp://127.0.0.1:10012", $errornum, $errorstr, $flags);
80
+ phpt_notify();
81
+
82
+ $conn = stream_socket_accept($server);
83
+ stream_set_blocking($conn, false);
84
+
85
+ $read = [$upstream, $conn];
86
+ while (stream_select($read, $write, $except, 1)) {
87
+ foreach ($read as $fp) {
88
+ $data = stream_get_contents($fp);
89
+ if ($fp === $conn) {
90
+ fwrite($upstream, $data);
91
+ } else {
92
+ if ($data !== '' && $data[0] === chr(23)) {
93
+ $parts = str_split($data, (int) ceil(strlen($data) / 3));
94
+ foreach ($parts as $part) {
95
+ fwrite($conn, $part);
96
+ phpt_wait(null, 1);
97
+ }
98
+ } else {
99
+ fwrite($conn, $data);
100
+ }
101
+ }
102
+ }
103
+ if (feof($upstream)) {
104
+ break;
105
+ }
106
+ $read = [$upstream, $conn];
107
+ }
108
+
109
+ phpt_wait();
106
110
CODE;
107
111
108
112
include 'CertificateGenerator.inc ' ;
@@ -112,8 +116,8 @@ $certificateGenerator->saveNewCertAsFileWithKey($peerName, $certFile);
112
116
113
117
include 'ServerClientTestCase.inc ' ;
114
118
ServerClientTestCase::getInstance ()->run ($ clientCode , [
115
- 'server ' => $ serverCode ,
116
- 'proxy ' => $ proxyCode ,
119
+ 'server ' => $ serverCode ,
120
+ 'proxy ' => $ proxyCode ,
117
121
]);
118
122
?>
119
123
--CLEAN--
@@ -123,5 +127,4 @@ ServerClientTestCase::getInstance()->run($clientCode, [
123
127
?>
124
128
--EXPECT--
125
129
string(0) ""
126
- string(0) ""
127
130
string(12) "hello, world"
0 commit comments