Skip to content

Commit 88230f3

Browse files
committed
#53: * change 005-socket_accept_multiple.phpt
1 parent 0e2f9d9 commit 88230f3

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

tests/socket_ext/005-socket_accept_multiple.phpt

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if (!extension_loaded('sockets')) {
1010
<?php
1111

1212
use function Async\spawn;
13-
use function Async\awaitAll;
13+
use function Async\awaitAllOrFail;
1414
use function Async\delay;
1515

1616
echo "Start\n";
@@ -27,56 +27,61 @@ $server = spawn(function() use (&$port, &$output) {
2727
socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);
2828
socket_bind($socket, '127.0.0.1', 0);
2929
socket_listen($socket, 5);
30-
30+
3131
$addr = '';
3232
socket_getsockname($socket, $addr, $port);
3333
$output[] = "Server: listening on port $port";
34-
34+
3535
$clients = [];
36-
36+
3737
// Accept 3 clients
3838
for ($i = 1; $i <= 3; $i++) {
3939
$output[] = "Server: waiting for client $i";
4040
$client = socket_accept($socket);
4141
$output[] = "Server: client $i connected";
4242
$clients[] = $client;
4343
}
44-
44+
4545
// Send responses to all clients
4646
foreach ($clients as $i => $client) {
4747
$clientNum = $i + 1;
4848
socket_write($client, "Response to client $clientNum");
4949
socket_close($client);
5050
}
51-
51+
5252
socket_close($socket);
5353
});
5454

5555
// Multiple client coroutines
5656
$clients = [];
5757
for ($i = 1; $i <= 3; $i++) {
5858
$clients[] = spawn(function() use (&$port, $i, &$output) {
59-
while ($port === null) {
60-
delay(1);
59+
60+
for ($i = 0; $i < 3 && $port === null; $i++) {
61+
delay(10);
6162
}
62-
63+
64+
if(empty($port)) {
65+
throw new Exception("Server port is not provided...");
66+
}
67+
6368
// Small delay to stagger connections
6469
delay($i);
65-
70+
6671
$output[] = "Client$i: connecting";
6772
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
68-
73+
6974
if (socket_connect($socket, '127.0.0.1', $port)) {
7075
$output[] = "Client$i: connected";
7176
$data = socket_read($socket, 1024);
7277
$output[] = "Client$i: received '$data'";
7378
}
74-
79+
7580
socket_close($socket);
7681
});
7782
}
7883

79-
awaitAll(array_merge([$server], $clients));
84+
awaitAllOrFail(array_merge([$server], $clients));
8085

8186
// Sort and output results
8287
sort($output);
@@ -106,4 +111,4 @@ Server: listening on port %d
106111
Server: waiting for client 1
107112
Server: waiting for client 2
108113
Server: waiting for client 3
109-
End
114+
End

tests/stream/027-ssl_concurrent_accept.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ $monitor = spawn(function() use (&$servers_ready, &$servers_completed) {
7474
echo "Monitor: waiting for servers to be ready\n";
7575

7676
while ($servers_ready < 3) {
77-
delay(50);
77+
delay(10);
7878
}
7979

8080
echo "Monitor: all servers ready, waiting for completion\n";
8181

8282
while ($servers_completed < 3) {
83-
delay(50);
83+
delay(10);
8484
}
8585

8686
echo "Monitor: all servers completed\n";

0 commit comments

Comments
 (0)