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

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

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