Browse Source
socket: support unix paths in the abstract namespace
socket: support unix paths in the abstract namespace
Those starting with '\0'.pull/387/head
4 changed files with 119 additions and 11 deletions
-
25ext/sockets/conversions.c
-
21ext/sockets/sockets.c
-
44ext/sockets/tests/socket_abstract_path.phpt
-
40ext/sockets/tests/socket_abstract_path_sendmsg.phpt
@ -0,0 +1,44 @@ |
|||
--TEST-- |
|||
Support for paths in the abstract namespace (bind, connect) |
|||
--SKIPIF-- |
|||
<?php |
|||
if (!extension_loaded('sockets')) |
|||
die('skip sockets extension not available.'); |
|||
|
|||
if (PHP_OS != 'Linux') { |
|||
die('skip For Linux only'); |
|||
} |
|||
?> |
|||
--FILE-- |
|||
<?php |
|||
include __DIR__."/mcast_helpers.php.inc"; |
|||
|
|||
$path = "\x00/foo_bar"; |
|||
|
|||
echo "creating server socket\n"; |
|||
$servers = socket_create(AF_UNIX, SOCK_STREAM, 0) or die("err"); |
|||
socket_bind($servers, $path) or die("Could not bind"); |
|||
socket_listen($servers) or die("Could not listen"); |
|||
socket_set_nonblock($servers) or die("Could not put in non-blocking mode"); |
|||
|
|||
echo "creating client socket\n"; |
|||
$clients = socket_create(AF_UNIX, SOCK_STREAM, 0) or die("err"); |
|||
socket_connect($clients, $path) or die("Error connecting"); |
|||
|
|||
$conns = socket_accept($servers) or die("Could not accept connection"); |
|||
|
|||
$r = socket_sendmsg($clients, [ |
|||
//"name" => [ "addr" => $path, ], |
|||
"iov" => ["test ", "thing", "\n"], |
|||
], 0); |
|||
var_dump($r); |
|||
checktimeout($conns, 500); |
|||
|
|||
if (!socket_recv($conns, $buf, 20, 0)) die("recv"); |
|||
print_r($buf); |
|||
?> |
|||
--EXPECTF-- |
|||
creating server socket |
|||
creating client socket |
|||
int(11) |
|||
test thing |
|||
@ -0,0 +1,40 @@ |
|||
--TEST-- |
|||
Support for paths in the abstract namespace (bind, sendmsg, recvmsg) |
|||
--SKIPIF-- |
|||
<?php |
|||
if (!extension_loaded('sockets')) |
|||
die('skip sockets extension not available.'); |
|||
|
|||
if (PHP_OS != 'Linux') { |
|||
die('skip For Linux only'); |
|||
} |
|||
?> |
|||
--FILE-- |
|||
<?php |
|||
include __DIR__."/mcast_helpers.php.inc"; |
|||
|
|||
$path = "\x00/bar_foo"; |
|||
|
|||
echo "creating send socket\n"; |
|||
$sends1 = socket_create(AF_UNIX, SOCK_DGRAM, 0) or die("err"); |
|||
socket_set_nonblock($sends1) or die("Could not put in non-blocking mode"); |
|||
|
|||
echo "creating receive socket\n"; |
|||
$s = socket_create(AF_UNIX, SOCK_DGRAM, 0) or die("err"); |
|||
socket_bind($s, $path) or die("err"); |
|||
|
|||
$r = socket_sendmsg($sends1, [ |
|||
"name" => [ "path" => $path], |
|||
"iov" => ["test ", "thing", "\n"], |
|||
], 0); |
|||
var_dump($r); |
|||
checktimeout($s, 500); |
|||
|
|||
if (!socket_recv($s, $buf, 20, 0)) die("recv"); |
|||
print_r($buf); |
|||
?> |
|||
--EXPECTF-- |
|||
creating send socket |
|||
creating receive socket |
|||
int(11) |
|||
test thing |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue