1--TEST-- 2swoole_socket_coro: readVectorAll with ssl 3--SKIPIF-- 4<?php require __DIR__ . '/../include/skipif.inc'; ?> 5--FILE-- 6<?php 7require __DIR__ . '/../include/bootstrap.php'; 8 9use Swoole\Coroutine\Socket; 10use Swoole\Server; 11 12use function Swoole\Coroutine\run; 13 14$totalLength = 0; 15$iovector = []; 16$packedStr = ''; 17 18for ($i = 0; $i < 10; $i++) { 19 $iovector[$i] = str_repeat(get_safe_random(1024), 128); 20 $totalLength += strlen($iovector[$i]); 21 $packedStr .= $iovector[$i]; 22} 23$totalLength2 = rand(strlen($packedStr) / 2, strlen($packedStr) - 1024 * 128); 24 25$pm = new ProcessManager; 26$pm->parentFunc = function ($pid) use ($pm) { 27 run(function () use ($pm) { 28 global $totalLength, $packedStr; 29 $conn = new Socket(AF_INET, SOCK_STREAM, IPPROTO_IP); 30 $conn->setProtocol([ 31 'open_ssl' => true, 32 ]); 33 $conn->connect('127.0.0.1', $pm->getFreePort()); 34 35 $ret = $conn->sendAll($packedStr); 36 Assert::eq($ret, $totalLength); 37 $conn->recv(); 38 echo "DONE\n"; 39 }); 40}; 41 42$pm->childFunc = function () use ($pm) { 43 run(function () use ($pm) { 44 global $totalLength, $iovector; 45 $socket = new Socket(AF_INET, SOCK_STREAM, IPPROTO_IP); 46 $socket->setProtocol([ 47 'open_ssl' => true, 48 'ssl_cert_file' => SSL_FILE_DIR . '/server.crt', 49 'ssl_key_file' => SSL_FILE_DIR . '/server.key', 50 ]); 51 Assert::assert($socket->bind('127.0.0.1', $pm->getFreePort())); 52 Assert::assert($socket->listen(MAX_CONCURRENCY)); 53 54 /** @var Socket */ 55 $conn = $socket->accept(); 56 $conn->sslHandshake(); 57 58 $iov = []; 59 for ($i = 0; $i < 10; $i++) { 60 $iov[] = 1024 * 128; 61 } 62 63 Assert::eq($conn->readVectorAll($iov), $iovector); 64 $conn->send('close'); 65 }); 66}; 67$pm->childFirst(); 68$pm->run(); 69?> 70--EXPECT-- 71DONE 72