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:
1
NEWS
1
NEWS
@@ -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.
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user