-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-14111 main/streams: adding SO_LINGER to stream options. #14129
base: master
Are you sure you want to change the base?
Conversation
adb3644
to
bdd35ea
Compare
16c185c
to
19e8ddc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to support SO_LINGER. Added some comments. We need a good test for this though.
<?php | ||
if (getenv("SKIP_ONLINE_TESTS")) die('skip online test'); | ||
if (!in_array('https', stream_get_wrappers())) die('skip: https wrapper is required'); | ||
?> | ||
--FILE-- | ||
<?php | ||
$context = stream_context_create(['socket' => ['so_linger' => false]]); | ||
var_dump(file_get_contents('https://httpbin.org/get', false, $context) !== false); | ||
$context = stream_context_create(['socket' => ['so_linger' => PHP_INT_MAX + 1]]); | ||
var_dump(file_get_contents('https://httpbin.org/get', false, $context) !== false); | ||
$context = stream_context_create(['socket' => ['so_linger' => 3]]); | ||
var_dump(file_get_contents('https://httpbin.org/get', false, $context) !== false); | ||
?> | ||
--EXPECTF-- | ||
Warning: file_get_contents(https://httpbin.org/get): Failed to open stream: Invalid `so_linger` value in %s on line %d | ||
bool(false) | ||
|
||
Warning: file_get_contents(https://httpbin.org/get): Failed to open stream: Invalid `so_linger` value in %s on line %d | ||
bool(false) | ||
bool(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please don't add any online tests - they are useless and should be used as last resort. This should be done using a proper test that will will properly delay the data reading on server side so the lingering can be properly tested.
main/streams/xp_socket.c
Outdated
@@ -719,9 +748,27 @@ static inline int php_tcp_sockop_bind(php_stream *stream, php_netstream_data_t * | |||
} | |||
#endif | |||
|
|||
#ifdef SO_LINGER | |||
if (PHP_STREAM_CONTEXT(stream) | |||
&& (tmpzval = php_stream_context_get_option(PHP_STREAM_CONTEXT(stream), "socket", "so_linger")) != NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's already part of socket option so there is no point for so_ prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well I added it to have consistency but I do not mind removing it
main/php_network.h
Outdated
@@ -280,7 +282,7 @@ PHPAPI int php_network_connect_socket(php_socket_t sockfd, | |||
php_network_connect_socket((sock), (addr), (addrlen), 0, (timeout), NULL, NULL) | |||
|
|||
PHPAPI php_socket_t php_network_bind_socket_to_local_addr(const char *host, unsigned port, | |||
int socktype, long sockopts, zend_string **error_string, int *error_code | |||
int socktype, long sockopts, long linger, zend_string **error_string, int *error_code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be better to introduce something more generic that can be used for not just linger so we don't have to change this function if there are other values needed. It could be either completely opaque or just some pointer to union that can hold multiple types.
a8f1613
to
ea791a3
Compare
ea791a3
to
95d107e
Compare
No description provided.