Skip to content

Commit 83ad243

Browse files
committed
address feedback
1 parent 334237c commit 83ad243

3 files changed

Lines changed: 37 additions & 24 deletions

File tree

UPGRADING

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,13 @@ PHP 8.6 UPGRADE NOTES
486486
sockets. A positive value enables lingering for that many seconds, zero
487487
or a negative value disables it. Values above 65535 are clamped as the
488488
linger time is limited to an unsigned short on some platforms.
489+
. Added stream socket context options so_rcvbuf and so_sndbuf that set the
490+
socket receive and send buffer sizes in bytes (SO_RCVBUF and SO_SNDBUF) on
491+
TCP and UDP sockets. The value must be an integer between 1 and 2147483647,
492+
any other value makes the stream creation fail. The operating system may
493+
round, cap or otherwise adjust the requested size, and may stop sizing that
494+
buffer automatically, so the size read back can differ from the one
495+
requested.
489496
. Allowed casting filtered streams as file descriptors for select.
490497
. Added the "write_seek_mode" filter parameter for the bz2, iconv,
491498
zlib, and string stream filters. This parameter must be set via an

ext/standard/tests/network/so_rcvbuf_sndbuf_error.phpt

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,30 @@ SO_RCVBUF and SO_SNDBUF context options reject invalid values
55
foreach (['so_rcvbuf', 'so_sndbuf'] as $option) {
66
foreach ([0, -1, 'abc'] as $value) {
77
$context = stream_context_create(['socket' => [$option => $value]]);
8-
try {
9-
@stream_socket_server("tcp://127.0.0.1:0", $errno, $errstr,
10-
STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $context);
11-
} catch (ValueError $e) {
12-
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
13-
}
8+
var_dump(@stream_socket_server("tcp://127.0.0.1:0", $errno, $errstr,
9+
STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $context));
10+
echo $errstr, PHP_EOL;
1411
}
1512
}
1613

1714
$context = stream_context_create(['socket' => ['so_rcvbuf' => 0]]);
18-
try {
19-
@stream_socket_client("tcp://127.0.0.1:1", $errno, $errstr, 1,
20-
STREAM_CLIENT_CONNECT, $context);
21-
} catch (ValueError $e) {
22-
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
23-
}
15+
var_dump(@stream_socket_client("tcp://127.0.0.1:1", $errno, $errstr, 1,
16+
STREAM_CLIENT_CONNECT, $context));
17+
echo $errstr, PHP_EOL;
2418

2519
?>
2620
--EXPECT--
27-
ValueError: stream context option 'so_rcvbuf' must be between 1 and 2147483647
28-
ValueError: stream context option 'so_rcvbuf' must be between 1 and 2147483647
29-
ValueError: stream context option 'so_rcvbuf' must be between 1 and 2147483647
30-
ValueError: stream context option 'so_sndbuf' must be between 1 and 2147483647
31-
ValueError: stream context option 'so_sndbuf' must be between 1 and 2147483647
32-
ValueError: stream context option 'so_sndbuf' must be between 1 and 2147483647
33-
ValueError: stream context option 'so_rcvbuf' must be between 1 and 2147483647
21+
bool(false)
22+
so_rcvbuf context option must be between 1 and 2147483647
23+
bool(false)
24+
so_rcvbuf context option must be between 1 and 2147483647
25+
bool(false)
26+
so_rcvbuf context option must be between 1 and 2147483647
27+
bool(false)
28+
so_sndbuf context option must be between 1 and 2147483647
29+
bool(false)
30+
so_sndbuf context option must be between 1 and 2147483647
31+
bool(false)
32+
so_sndbuf context option must be between 1 and 2147483647
33+
bool(false)
34+
so_rcvbuf context option must be between 1 and 2147483647

main/streams/xp_socket.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,8 @@ static inline char *parse_ip_address(php_stream_xport_param *xparam, int *portno
677677
return parse_ip_address_ex(xparam->inputs.name, xparam->inputs.namelen, portno, xparam->want_errortext, &xparam->outputs.error_text);
678678
}
679679

680-
static int php_sockop_parse_buffer_sizes(php_stream *stream, php_sockvals *sockvals)
680+
static int php_sockop_parse_buffer_sizes(php_stream *stream, php_stream_xport_param *xparam,
681+
php_sockvals *sockvals)
681682
{
682683
zval *tmpzval;
683684

@@ -690,7 +691,9 @@ static int php_sockop_parse_buffer_sizes(php_stream *stream, php_sockvals *sockv
690691
zend_long bufsize = zval_get_long(tmpzval);
691692

692693
if (bufsize < 1 || bufsize > INT_MAX) {
693-
zend_value_error("stream context option 'so_rcvbuf' must be between 1 and %d", INT_MAX);
694+
if (xparam->want_errortext) {
695+
xparam->outputs.error_text = strpprintf(0, "so_rcvbuf context option must be between 1 and %d", INT_MAX);
696+
}
694697
return -1;
695698
}
696699

@@ -704,7 +707,9 @@ static int php_sockop_parse_buffer_sizes(php_stream *stream, php_sockvals *sockv
704707
zend_long bufsize = zval_get_long(tmpzval);
705708

706709
if (bufsize < 1 || bufsize > INT_MAX) {
707-
zend_value_error("stream context option 'so_sndbuf' must be between 1 and %d", INT_MAX);
710+
if (xparam->want_errortext) {
711+
xparam->outputs.error_text = strpprintf(0, "so_sndbuf context option must be between 1 and %d", INT_MAX);
712+
}
708713
return -1;
709714
}
710715

@@ -759,7 +764,7 @@ static inline int php_tcp_sockop_bind(php_stream *stream, php_netstream_data_t *
759764
return -1;
760765
}
761766

762-
if (php_sockop_parse_buffer_sizes(stream, &sockvals) == -1) {
767+
if (php_sockop_parse_buffer_sizes(stream, xparam, &sockvals) == -1) {
763768
efree(host);
764769
return -1;
765770
}
@@ -912,7 +917,7 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_
912917
return -1;
913918
}
914919

915-
if (php_sockop_parse_buffer_sizes(stream, &sockvals) == -1) {
920+
if (php_sockop_parse_buffer_sizes(stream, xparam, &sockvals) == -1) {
916921
efree(host);
917922
return -1;
918923
}

0 commit comments

Comments
 (0)