Annotation of embedaddon/php/ext/sockets/tests/socket_sentto_recvfrom_ipv6_udp.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Test if socket_recvfrom() receives data sent by socket_sendto() via IPv6 UDP
        !             3: --SKIPIF--
        !             4: <?php
        !             5: if (!extension_loaded('sockets')) {
        !             6:     die('SKIP The sockets extension is not loaded.');
        !             7: }
        !             8: require 'ipv6_skipif.inc';
        !             9: --FILE--
        !            10: <?php
        !            11:     $socket = socket_create(AF_INET6, SOCK_DGRAM, SOL_UDP);
        !            12:     if (!$socket) {
        !            13:         die('Unable to create AF_INET6 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 = '::1';
        !            20:     socket_sendto($socket, '', 1, 0, $address); // cause warning
        !            21:     if (!socket_bind($socket, $address, 1223)) {
        !            22:         die("Unable to bind to $address:1223");
        !            23:     }
        !            24: 
        !            25:     $msg = "Ping!";
        !            26:     $len = strlen($msg);
        !            27:     $bytes_sent = socket_sendto($socket, $msg, $len, 0, $address, 1223);
        !            28:     if ($bytes_sent == -1) {
        !            29:         die('An error occured while sending to the socket');
        !            30:     } else if ($bytes_sent != $len) {
        !            31:         die($bytes_sent . ' bytes have been sent instead of the ' . $len . ' bytes expected');
        !            32:     }
        !            33: 
        !            34:     $from = "";
        !            35:     $port = 0;
        !            36:     socket_recvfrom($socket, $buf, 12, 0); // cause warning
        !            37:     socket_recvfrom($socket, $buf, 12, 0, $from); // cause warning
        !            38:     $bytes_received = socket_recvfrom($socket, $buf, 12, 0, $from, $port);
        !            39:     if ($bytes_received == -1) {
        !            40:         die('An error occured while receiving from the socket');
        !            41:     } else if ($bytes_received != $len) {
        !            42:         die($bytes_received . ' bytes have been received instead of the ' . $len . ' bytes expected');
        !            43:     }
        !            44:     echo "Received $buf from remote address $from and remote port $port" . PHP_EOL;
        !            45: 
        !            46:     socket_close($socket);
        !            47: --EXPECTF--
        !            48: Warning: socket_recvfrom(): unable to recvfrom [11]: Resource temporarily unavailable in %s on line %d
        !            49: 
        !            50: Warning: Wrong parameter count for socket_sendto() in %s on line %d
        !            51: 
        !            52: Warning: socket_recvfrom() expects at least 5 parameters, 4 given in %s on line %d
        !            53: 
        !            54: Warning: Wrong parameter count for socket_recvfrom() in %s on line %d
        !            55: Received Ping! from remote address ::1 and remote port 1223
        !            56: --CREDITS--
        !            57: Falko Menge <mail at falko-menge dot de>
        !            58: PHP Testfest Berlin 2009-05-09

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>