Annotation of embedaddon/php/ext/sockets/tests/unixloop.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Unix domain socket Loopback test
! 3: --SKIPIF--
! 4: <?php
! 5: if (!extension_loaded('sockets')) {
! 6: die('skip sockets extension not available.');
! 7: }
! 8: ?>
! 9: --FILE--
! 10: <?php
! 11: $sock_path = sprintf("/tmp/%s.sock", uniqid());
! 12:
! 13: if (file_exists($sock_path))
! 14: die('Temporary socket already exists.');
! 15:
! 16: /* Setup socket server */
! 17: $server = socket_create(AF_UNIX, SOCK_STREAM, 0);
! 18: if (!$server) {
! 19: die('Unable to create AF_UNIX socket [server]');
! 20: }
! 21: if (!socket_bind($server, $sock_path)) {
! 22: die("Unable to bind to $sock_path");
! 23: }
! 24: if (!socket_listen($server, 2)) {
! 25: die('Unable to listen on socket');
! 26: }
! 27:
! 28: /* Connect to it */
! 29: $client = socket_create(AF_UNIX, SOCK_STREAM, 0);
! 30: if (!$client) {
! 31: die('Unable to create AF_UNIX socket [client]');
! 32: }
! 33: if (!socket_connect($client, $sock_path)) {
! 34: die('Unable to connect to server socket');
! 35: }
! 36:
! 37: /* Accept that connection */
! 38: $socket = socket_accept($server);
! 39: if (!$socket) {
! 40: die('Unable to accept connection');
! 41: }
! 42:
! 43: socket_write($client, "ABCdef123\n");
! 44:
! 45: $data = socket_read($socket, 10, PHP_BINARY_READ);
! 46: var_dump($data);
! 47:
! 48: socket_close($client);
! 49: socket_close($socket);
! 50: socket_close($server);
! 51: @unlink($sock_path);
! 52: ?>
! 53: --EXPECT--
! 54: string(10) "ABCdef123
! 55: "
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>