Annotation of embedaddon/php/ext/sockets/tests/socket_sentto_recvfrom_unix.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test if socket_recvfrom() receives data sent by socket_sendto() through a Unix domain socket
3: --SKIPIF--
4: <?php
5: if (!extension_loaded('sockets')) {
6: die('SKIP The sockets extension is not loaded.');
7: }
8: --FILE--
9: <?php
10: $socket = socket_create(AF_UNIX, SOCK_DGRAM, SOL_UDP); // cause warning
11: $socket = socket_create(AF_UNIX, SOCK_DGRAM, 0);
12: if (!$socket) {
13: die('Unable to create AF_UNIX socket');
14: }
15: if (!socket_set_nonblock($socket)) {
16: die('Unable to set nonblocking mode for socket');
17: }
18: socket_recvfrom($socket, $buf, 12, 0, $from, $port); // cause warning
19: $address = sprintf("/tmp/%s.sock", uniqid());
20: if (!socket_bind($socket, $address)) {
21: die("Unable to bind to $address");
22: }
23:
24: $msg = "Ping!";
25: $len = strlen($msg);
26: $bytes_sent = socket_sendto($socket, $msg, $len, 0); // cause warning
27: $bytes_sent = socket_sendto($socket, $msg, $len, 0, $address);
28: if ($bytes_sent == -1) {
29: @unlink($address);
30: die('An error occured while sending to the socket');
31: } else if ($bytes_sent != $len) {
32: @unlink($address);
33: die($bytes_sent . ' bytes have been sent instead of the ' . $len . ' bytes expected');
34: }
35:
36: $from = "";
37: var_dump(socket_recvfrom($socket, $buf, 0, 0, $from)); // expect false
38: $bytes_received = socket_recvfrom($socket, $buf, 12, 0, $from);
39: if ($bytes_received == -1) {
40: @unlink($address);
41: die('An error occured while receiving from the socket');
42: } else if ($bytes_received != $len) {
43: @unlink($address);
44: die($bytes_received . ' bytes have been received instead of the ' . $len . ' bytes expected');
45: }
46: echo "Received $buf";
47:
48: socket_close($socket);
49: @unlink($address);
50: ?>
51: --EXPECTF--
52: Warning: socket_create(): Unable to create socket [%d]: Protocol not supported in %s on line %d
53:
54: Warning: socket_recvfrom(): unable to recvfrom [%d]: Resource temporarily unavailable in %s on line %d
55:
56: Warning: socket_sendto() expects at least 5 parameters, 4 given in %s on line %d
57: bool(false)
58: Received Ping!
59: --CREDITS--
60: Falko Menge <mail at falko-menge dot de>
61: PHP Testfest Berlin 2009-05-09
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>