mirror of
https://github.com/php/php-src.git
synced 2025-01-22 11:44:09 +08:00
MFH:- Fixed bug #44127 (UNIX abstract namespace socket connect does not work)
This commit is contained in:
parent
644b06978a
commit
d91bc9eca2
@ -1328,8 +1328,8 @@ PHP_FUNCTION(socket_connect)
|
||||
memset(&s_un, 0, sizeof(struct sockaddr_un));
|
||||
|
||||
s_un.sun_family = AF_UNIX;
|
||||
snprintf(s_un.sun_path, 108, "%s", addr);
|
||||
retval = connect(php_sock->bsd_socket, (struct sockaddr *) &s_un, SUN_LEN(&s_un));
|
||||
memcpy(&s_un.sun_path, addr, addr_len);
|
||||
retval = connect(php_sock->bsd_socket, (struct sockaddr *) &s_un, (socklen_t) XtOffsetOf(struct sockaddr_un, sun_path) + addr_len);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -3,7 +3,7 @@ IPv4 Loopback test
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded('sockets')) {
|
||||
die('skip sockets extenion not available.');
|
||||
die('skip sockets extension not available.');
|
||||
}
|
||||
?>
|
||||
--FILE--
|
||||
|
@ -3,7 +3,7 @@ IPv6 Loopback test
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded('sockets')) {
|
||||
die('skip sockets extenion not available.');
|
||||
die('skip sockets extension not available.');
|
||||
}
|
||||
if (!defined("AF_INET6")) {
|
||||
die('skip no IPv6 support');
|
||||
|
55
ext/sockets/tests/unixloop.phpt
Normal file
55
ext/sockets/tests/unixloop.phpt
Normal file
@ -0,0 +1,55 @@
|
||||
--TEST--
|
||||
Unix domain socket Loopback test
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded('sockets')) {
|
||||
die('skip sockets extension not available.');
|
||||
}
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
$sock_path = sprintf("/tmp/%s.sock", uniqid());
|
||||
|
||||
if (file_exists($sock_path))
|
||||
die('Temporary socket already exists.');
|
||||
|
||||
/* Setup socket server */
|
||||
$server = socket_create(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (!$server) {
|
||||
die('Unable to create AF_UNIX socket [server]');
|
||||
}
|
||||
if (!socket_bind($server, $sock_path)) {
|
||||
die("Unable to bind to $sock_path");
|
||||
}
|
||||
if (!socket_listen($server, 2)) {
|
||||
die('Unable to listen on socket');
|
||||
}
|
||||
|
||||
/* Connect to it */
|
||||
$client = socket_create(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (!$client) {
|
||||
die('Unable to create AF_UNIX socket [client]');
|
||||
}
|
||||
if (!socket_connect($client, $sock_path)) {
|
||||
die('Unable to connect to server socket');
|
||||
}
|
||||
|
||||
/* Accept that connection */
|
||||
$socket = socket_accept($server);
|
||||
if (!$socket) {
|
||||
die('Unable to accept connection');
|
||||
}
|
||||
|
||||
socket_write($client, "ABCdef123\n");
|
||||
|
||||
$data = socket_read($socket, 10, PHP_BINARY_READ);
|
||||
var_dump($data);
|
||||
|
||||
socket_close($client);
|
||||
socket_close($socket);
|
||||
socket_close($server);
|
||||
@unlink($sock_path);
|
||||
?>
|
||||
--EXPECT--
|
||||
string(10) "ABCdef123
|
||||
"
|
@ -621,7 +621,7 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_
|
||||
parse_unix_address(xparam, &unix_addr TSRMLS_CC);
|
||||
|
||||
ret = php_network_connect_socket(sock->socket,
|
||||
(const struct sockaddr *)&unix_addr, (socklen_t)sizeof(unix_addr),
|
||||
(const struct sockaddr *)&unix_addr, (socklen_t) XtOffsetOf(struct sockaddr_un, sun_path) + xparam->inputs.namelen,
|
||||
xparam->op == STREAM_XPORT_OP_CONNECT_ASYNC, xparam->inputs.timeout,
|
||||
xparam->want_errortext ? &xparam->outputs.error_text : NULL,
|
||||
&err);
|
||||
|
Loading…
Reference in New Issue
Block a user