1--TEST--
2swoole_socket_coro: writeVector all
3--SKIPIF--
4<?php require __DIR__ . '/../include/skipif.inc'; ?>
5--FILE--
6<?php
7
8use Swoole\Coroutine\Socket;
9
10use function Swoole\Coroutine\run;
11
12require __DIR__ . '/../include/bootstrap.php';
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
24run(function () {
25    $server = new Socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
26    $port = get_one_free_port();
27
28    go(function () use ($server, $port) {
29        Assert::assert($server->bind('127.0.0.1', $port));
30        Assert::assert($server->listen(512));
31        $conn = $server->accept();
32        Assert::assert($conn instanceof  Socket);
33        Assert::assert($conn->fd > 0);
34
35        global $totalLength, $packedStr;
36        Assert::assert($conn instanceof Socket);
37        Assert::eq($conn->recvAll($totalLength), $packedStr);
38    });
39
40    go(function () use ($server, $port) {
41        global $iovector, $totalLength;
42
43        $conn = new Socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
44        Assert::assert($conn->connect('127.0.0.1', $port));
45        $ret = $conn->writeVectorAll($iovector);
46        Assert::eq($ret, $totalLength);
47        $server->close();
48    });
49});
50
51echo "DONE\n";
52?>
53--EXPECT--
54DONE
55