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, the original 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)
51object(Socket)#%d (0) {
52}
53object(Socket)#%d (0) {
54}
55object(Socket)#%d (0) {
56}
57object(Socket)#%d (0) {
58}
59
60Warning: socket_wsaprotocol_info_export(): Unable to export WSA protocol info [0x00002726]: %s in %s on line %d
61
62Warning: socket_wsaprotocol_info_import(): Unable to open file mapping [0x00000002] in %s on line %d
63