1--TEST--
2Streams Based IPv6 TCP Loopback test
3--SKIPIF--
4<?php
5	/* If IPv6 is supported on the platform this will error out with code 111 - Connection refused.
6	   If IPv6 is NOT supported, $errno will be set to something else (indicating parse/getaddrinfo error)
7	   Note: Might be a good idea to export an IPv6 support indicator (such as AF_INET6 exported by ext/sockets) */
8	@stream_socket_client('tcp://[::1]:0', $errno);
9	if ($errno != 111) die('skip IPv6 not supported.');
10?>
11--FILE--
12<?php
13
14  for ($i=0; $i<100; $i++) {
15    $port = rand(10000, 65000);
16    /* Setup socket server */
17    $server = @stream_socket_server("tcp://[::1]:$port");
18    if ($server) {
19      break;
20    }
21  }
22
23	if (!$server) {
24		die('Unable to create AF_INET6 socket [server]');
25	}
26
27	/* Connect to it */
28	$client = stream_socket_client("tcp://[::1]:$port");
29	if (!$client) {
30		die('Unable to create AF_INET6 socket [client]');
31	}
32
33	/* Accept that connection */
34	$socket = stream_socket_accept($server);
35	if (!$socket) {
36		die('Unable to accept connection');
37	}
38
39	fwrite($client, "ABCdef123\n");
40
41	$data = fread($socket, 10);
42	var_dump($data);
43
44	fclose($client);
45	fclose($socket);
46	fclose($server);
47?>
48--EXPECT--
49string(10) "ABCdef123
50"
51