1--TEST--
2Winsock export/import socket, basic test
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) != 'WIN') {
6	die('skip.. Windows only test');
7}
8if (!extension_loaded('sockets')) {
9	die('skip sockets extension not available.');
10}
11?>
12--FILE--
13<?php
14	$address = 'localhost';
15	$port = 10000;
16
17	if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) {
18		fprintf(STDERR, "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n");
19	}
20
21	if (socket_bind($sock, $address, $port) === false) {
22		fprintf(STDERR, "socket_bind() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n");
23	}
24
25	if (socket_listen($sock, 5) === false) {
26		fprintf(STDERR, "socket_listen() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n");
27	}
28
29	/* Duplicate socket in the same process. */
30	$pid = getmypid();
31	$info = socket_wsaprotocol_info_export($sock, $pid);
32	$sock2 = socket_wsaprotocol_info_import($info);
33	var_dump(socket_wsaprotocol_info_release($info));
34
35	var_dump($sock, $sock2);
36
37	/* Close duplicated socket, teh orig is still valid. */
38	socket_close($sock2);
39	var_dump($sock, $sock2);
40
41	/* Using invalid PID. */
42	$info = socket_wsaprotocol_info_export($sock, 123412341);
43
44	socket_close($sock);
45
46	/* Importing with invalid identifier. */
47	$sock2 = socket_wsaprotocol_info_import("garbage");
48?>
49--EXPECTF--
50bool(true)
51resource(%d) of type (Socket)
52resource(%d) of type (Socket)
53resource(%d) of type (Socket)
54resource(%d) of type (Unknown)
55
56Warning: socket_wsaprotocol_info_export(): Unable to export WSA protocol info [0x00002726]: %s
57 in %s on line %d
58
59Warning: socket_wsaprotocol_info_import(): Unable to open file mapping [0x00000002] in %s on line %d
60