1--TEST-- 2swoole_socket_coro: recvAll timeout (slow network) 3--SKIPIF-- 4<?php require __DIR__ . '/../include/skipif.inc'; ?> 5--FILE-- 6<?php 7require __DIR__ . '/../include/bootstrap.php'; 8$pm = new ProcessManager; 9$pm->initRandomDataEx(MAX_CONCURRENCY_MID, 1, 1024); 10$pm->parentFunc = function ($pid) use ($pm) { 11 for ($c = MAX_CONCURRENCY_MID; $c--;) { 12 go(function () use ($pm, $c) { 13 $conn = new Swoole\Coroutine\Socket(AF_INET, SOCK_STREAM, IPPROTO_IP); 14 Assert::assert($conn->connect('127.0.0.1', $pm->getFreePort())); 15 $conn->send($c); 16 $timeout = ms_random(0.1, 1); 17 $s = microtime(true); 18 $data = $conn->recvAll(1024, $timeout); 19 time_approximate($timeout, microtime(true) - $s); 20 Assert::assert(strlen($data) > 0); 21 Assert::assert(strlen($data) != 1024); 22 Assert::assert(strpos($pm->getRandomDataEx($c), $data) === 0); 23 Assert::assert($conn->errCode == SOCKET_ETIMEDOUT); 24 Assert::assert($conn->errMsg == swoole_strerror(SOCKET_ETIMEDOUT)); 25 }); 26 } 27 Swoole\Event::wait(); 28 $pm->kill(); 29 echo "DONE\n"; 30}; 31$pm->childFunc = function () use ($pm) { 32 $server = new Swoole\Server('127.0.0.1', $pm->getFreePort(), SWOOLE_BASE); 33 $server->on('WorkerStart', function () use ($pm) { 34 $pm->wakeup(); 35 }); 36 $server->on('Receive', function (Swoole\Server $server, int $fd, int $rid, string $data) use ($pm) { 37 $s = $pm->getRandomDataEx($data); 38 while ($server->exists($fd)) { 39 $server->send($fd, string_pop_front($s, 1)); 40 Co::sleep(0.005); 41 } 42 }); 43 $server->start(); 44}; 45$pm->childFirst(); 46$pm->run(); 47?> 48--EXPECT-- 49DONE 50