Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

devnexen
Copy link
Member

@devnexen devnexen commented May 4, 2024

No description provided.

@devnexen devnexen marked this pull request as ready for review May 6, 2024 17:09
@devnexen devnexen requested a review from bukka as a code owner May 6, 2024 17:09
Copy link
Member

@bukka bukka left a 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.

Comment on lines +4 to +23
<?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)
Copy link
Member

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.

@@ -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) {
Copy link
Member

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.

@@ -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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants