1--TEST-- 2swoole_socket_coro: readv with eagain 3--SKIPIF-- 4<?php require __DIR__ . '/../include/skipif.inc'; ?> 5--FILE-- 6<?php 7 8use Swoole\Coroutine; 9use Swoole\Coroutine\Socket; 10 11use function Swoole\Coroutine\run; 12 13require __DIR__ . '/../include/bootstrap.php'; 14 15$totalLength = 0; 16$iovector = []; 17$packedStr = ''; 18 19 20for ($i = 0; $i < 10; $i++) { 21 $iovector[$i] = str_repeat(get_safe_random(1024), 128); 22 $totalLength += strlen($iovector[$i]); 23 $packedStr .= $iovector[$i]; 24} 25$totalLength2 = rand(strlen($packedStr) / 2, strlen($packedStr) - 1024 * 128); 26 27run(function () { 28 $server = new Socket(AF_INET, SOCK_STREAM, IPPROTO_IP); 29 $port = get_one_free_port(); 30 31 go(function () use ($server, $port) { 32 Assert::assert($server->bind('127.0.0.1', $port)); 33 Assert::assert($server->listen(512)); 34 $conn = $server->accept(); 35 Assert::assert($conn instanceof Socket); 36 Assert::assert($conn->fd > 0); 37 38 global $packedStr, $iovector, $totalLength2; 39 Assert::assert($conn instanceof Socket); 40 $iov = []; 41 for ($i = 0; $i < 10; $i++) { 42 $iov[] = 1024 * 128; 43 } 44 45 Assert::eq($conn->readVectorAll($iov), $iovector); 46 Assert::eq(implode('', $conn->readVectorAll($iov)), substr($packedStr, 0, $totalLength2)); 47 48 // has close 49 Assert::eq($conn->readVectorAll($iov), []); 50 }); 51 52 go(function () use ($server, $port) { 53 global $packedStr, $totalLength, $totalLength2; 54 55 $conn = new Socket(AF_INET, SOCK_STREAM, IPPROTO_IP); 56 Assert::assert($conn->connect('127.0.0.1', $port)); 57 58 // Let readVectorAll trigger EAGAIN (verify the correctness of the error returned by readVectorAll) 59 Coroutine::sleep(0.5); 60 61 $ret = $conn->sendAll($packedStr); 62 Assert::eq($ret, $totalLength); 63 64 $ret = $conn->sendAll(substr($packedStr, 0, $totalLength2)); 65 Assert::eq($ret, $totalLength2); 66 67 $server->close(); 68 }); 69}); 70 71echo "DONE\n"; 72?> 73--EXPECT-- 74DONE 75