|
| 1 | +--TEST-- |
| 2 | +Test socket_sendto with MSG_ZEROCOPY |
| 3 | +--EXTENSIONS-- |
| 4 | +sockets |
| 5 | +--SKIPIF-- |
| 6 | +<?php |
| 7 | +if (!defined("SO_ZEROCOPY")) { |
| 8 | + die('skip SO_ZEROCOPY'); |
| 9 | +} |
| 10 | +--FILE-- |
| 11 | +<?php |
| 12 | +$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); |
| 13 | +if (!$socket) { |
| 14 | + die('Unable to create AF_UNIX socket'); |
| 15 | +} |
| 16 | +$s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); |
| 17 | +if (!$s) { |
| 18 | + die('Unable to create AF_UNIX socket'); |
| 19 | +} |
| 20 | +if (!socket_set_option($socket, SOL_SOCKET, SO_ZEROCOPY, 1)) { |
| 21 | + die("Unable to set the socket option to SO_ZEROCOPY"); |
| 22 | +} |
| 23 | +if (!socket_set_nonblock($s)) { |
| 24 | + die('Unable to set nonblocking mode for socket'); |
| 25 | +} |
| 26 | +$address = '127.0.0.1'; |
| 27 | +$port = 3001; |
| 28 | +if (!socket_bind($s, $address, $port)) { |
| 29 | + die("Unable to bind to $address"); |
| 30 | +} |
| 31 | + |
| 32 | +$msg = str_repeat("0123456789abcdef", 1024); |
| 33 | +$len = strlen($msg); |
| 34 | +$bytes_recv = 0; |
| 35 | +$bytes_sent = socket_sendto($socket, $msg, $len, MSG_ZEROCOPY, $address, $port); |
| 36 | +if (socket_recvfrom($s, $resp, 0, MSG_ERRQUEUE, $address, $port) == -1) die ("recvfrom MSG_ERRQUEUE"); |
| 37 | +$bytes_recv = socket_recvfrom($s, $resp, 16, 0, $address, $port); |
| 38 | +echo "$bytes_sent sent!\n"; |
| 39 | +echo "$bytes_recv received!\n"; |
| 40 | +echo "Received $resp!"; |
| 41 | +socket_close($s); |
| 42 | +socket_close($socket); |
| 43 | +?> |
| 44 | +--EXPECTF-- |
| 45 | +16384 sent! |
| 46 | +16 received! |
| 47 | +Received 0123456789abcdef! |
0 commit comments