-
Notifications
You must be signed in to change notification settings - Fork 7.8k
/
Copy pathsocket_sendto_zerocopy.phpt
55 lines (54 loc) · 1.46 KB
/
socket_sendto_zerocopy.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
--TEST--
Test socket_sendto with MSG_ZEROCOPY
--EXTENSIONS--
sockets
--SKIPIF--
<?php
$arch = php_uname('m');
if (!defined("SO_ZEROCOPY")) {
die('skip SO_ZEROCOPY');
}
if (strpos($arch, 'ppc') !== false || strpos($arch, 'powerpc') !== false) {
die('skip not for powerpc arch');
}
if (getenv('CIRRUS_CI') && strpos($arch, 'aarch64') !== false) {
die('xfail Broken on Cirrus + arm');
}
?>
--FILE--
<?php
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if (!$socket) {
die('Unable to create AF_UNIX socket');
}
$s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if (!$s) {
die('Unable to create AF_UNIX socket');
}
if (!socket_set_option($socket, SOL_SOCKET, SO_ZEROCOPY, 1)) {
die("Unable to set the socket option to SO_ZEROCOPY");
}
if (!socket_set_nonblock($s)) {
die('Unable to set nonblocking mode for socket');
}
$address = '127.0.0.1';
$port = 3001;
if (!socket_bind($s, $address, $port)) {
die("Unable to bind to $address");
}
$msg = str_repeat("0123456789abcdef", 1024);
$len = strlen($msg);
$bytes_recv = 0;
$bytes_sent = socket_sendto($socket, $msg, $len, MSG_ZEROCOPY, $address, $port);
if (socket_recvfrom($s, $resp, 0, MSG_ERRQUEUE, $address, $port) == -1) die ("recvfrom MSG_ERRQUEUE");
$bytes_recv = socket_recvfrom($s, $resp, 16, 0, $address, $port);
echo "$bytes_sent sent!\n";
echo "$bytes_recv received!\n";
echo "Received $resp!";
socket_close($s);
socket_close($socket);
?>
--EXPECTF--
16384 sent!
16 received!
Received 0123456789abcdef!