wsaprotocol_info_0.phpt 1.7 KB

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