1--TEST--
2swoole_socket_coro: concurrency
3--SKIPIF--
4<?php require __DIR__ . '/../include/skipif.inc'; ?>
5--FILE--
6<?php
7require __DIR__ . '/../include/bootstrap.php';
8
9const N = 100;
10
11$socket = new Swoole\Coroutine\Socket(AF_INET, SOCK_STREAM, 0);
12$socket->bind('127.0.0.1', 9601);
13$socket->listen(128);
14
15go(function () use ($socket)
16{
17    for ($i = 0; $i < N; $i++)
18    {
19        $client = $socket->accept();
20        go(function () use ($client)
21        {
22            while (true)
23            {
24                $data = $client->recv();
25                if (empty($data))
26                {
27                    $client->close();
28                    break;
29                }
30                $client->send("Server: $data");
31            }
32        });
33    }
34});
35
36for ($i = 0; $i < N; $i++)
37{
38    go(function ()
39    {
40        $cli = new Swoole\Coroutine\Client(SWOOLE_SOCK_TCP);
41        $ret = $cli->connect('127.0.0.1', 9601);
42        if ($ret)
43        {
44            $cli->send("hello\n");
45            Assert::same($cli->recv(), 'Server: hello'."\n");
46            $cli->close();
47        }
48        else
49        {
50            echo "ERROR\n";
51        }
52    });
53}
54swoole_event_wait();
55?>
56--EXPECT--
57