1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Propagate bind error for stream_socket_server()

When stream_socket_server() fails during bind(), we're currently only showing
"Unknown error" in the error message. Properly propagate this error for better
diagnostics.

Closes GH-21328
This commit is contained in:
Ilija Tovilo
2026-03-03 13:37:04 +01:00
parent f44609c84d
commit 0039af028c
3 changed files with 26 additions and 1 deletions

1
NEWS
View File

@@ -145,6 +145,7 @@ PHP NEWS
. Allowed filtered streams to be casted as fd for select. (Jakub Zelenka)
. Fixed bug GH-21221 (Prevent closing of innerstream of php://temp stream).
(ilutov)
. Improved stream_socket_server() bind failure error reporting. (ilutov)
- Zip:
. Fixed ZipArchive callback being called after executor has shut down.

View File

@@ -0,0 +1,19 @@
--TEST--
stream_socket_server() bind error
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN' ) {
die('skip not for Windows');
}
?>
--FILE--
<?php
$server1 = stream_socket_server("tcp://0.0.0.0:0");
$name = stream_socket_get_name($server1, false);
$server2 = stream_socket_server("tcp://$name");
fclose($server1);
?>
--EXPECTF--
Warning: stream_socket_server(): Unable to connect to tcp://0.0.0.0:%d (Address %r(already )?%rin use) in %s on line %d

View File

@@ -699,8 +699,13 @@ static inline int php_tcp_sockop_bind(php_stream *stream, php_netstream_data_t *
parse_unix_address(xparam, &unix_addr);
return bind(sock->socket, (const struct sockaddr *)&unix_addr,
int result = bind(sock->socket, (const struct sockaddr *)&unix_addr,
(socklen_t) XtOffsetOf(struct sockaddr_un, sun_path) + xparam->inputs.namelen);
if (result == -1 && xparam->want_errortext) {
char errstr[256];
xparam->outputs.error_text = strpprintf(0, "%s", php_socket_strerror_s(errno, errstr, sizeof(errstr)));
}
return result;
}
#endif