-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add stream socket so_linger context option #20808
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6c89842
Add stream socket so_linger context option
bukka 6c67b5f
Use SO_LINGER_SEC if available (MacOS)
bukka eefbf0e
Do not relay on exact l_onoff value (FreeBSD uses 128 instead of 1)
bukka 890cf30
Clamp so_linger context option instead of truncating it
devnexen 5a293b5
Add NEWS/UPGRADING entries for so_linger
devnexen bffb84c
Merge branch 'master' into stream_so_linger
bukka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| --TEST-- | ||
| stream_socket_server() and stream_socket_client() SO_LINGER context option test | ||
| --EXTENSIONS-- | ||
| sockets | ||
| --FILE-- | ||
| <?php | ||
| // Test server with SO_LINGER enabled | ||
| $server_context = stream_context_create([ | ||
| 'socket' => [ | ||
| 'so_linger' => 10, | ||
| ] | ||
| ]); | ||
|
|
||
| $server = stream_socket_server("tcp://127.0.0.1:0", $errno, $errstr, | ||
| STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $server_context); | ||
|
|
||
| if (!$server) { | ||
| die('Unable to create server'); | ||
| } | ||
|
|
||
| $addr = stream_socket_get_name($server, false); | ||
| $port = (int)substr(strrchr($addr, ':'), 1); | ||
|
|
||
| // Test client with SO_LINGER enabled | ||
| $client_context = stream_context_create([ | ||
| 'socket' => [ | ||
| 'so_linger' => 8, | ||
| ] | ||
| ]); | ||
|
|
||
| $client = stream_socket_client("tcp://127.0.0.1:$port", $errno, $errstr, 30, | ||
| STREAM_CLIENT_CONNECT, $client_context); | ||
|
|
||
| if (!$client) { | ||
| die('Unable to create client'); | ||
| } | ||
|
|
||
| $accepted = stream_socket_accept($server, 1); | ||
|
|
||
| if (!$accepted) { | ||
| die('Unable to accept connection'); | ||
| } | ||
|
|
||
| // macOS expresses SO_LINGER in ticks, SO_LINGER_SEC in seconds. | ||
| $so_linger = defined('SO_LINGER_SEC') ? SO_LINGER_SEC : SO_LINGER; | ||
|
|
||
| // Verify the listening socket | ||
| $listen_sock = socket_import_stream($server); | ||
| $listen_linger = socket_get_option($listen_sock, SOL_SOCKET, $so_linger); | ||
| echo "Listen SO_LINGER\n"; | ||
| var_dump($listen_linger['l_onoff'] > 0); | ||
| var_dump($listen_linger['l_linger']); | ||
|
|
||
| // Verify server side (accepted connection, inherits from the listening socket) | ||
| $server_sock = socket_import_stream($accepted); | ||
| $server_linger = socket_get_option($server_sock, SOL_SOCKET, $so_linger); | ||
| echo "Server SO_LINGER\n"; | ||
| var_dump($server_linger['l_onoff'] > 0); | ||
| var_dump($server_linger['l_linger']); | ||
|
|
||
| // Verify client side | ||
| $client_sock = socket_import_stream($client); | ||
| $client_linger = socket_get_option($client_sock, SOL_SOCKET, $so_linger); | ||
| echo "Client SO_LINGER\n"; | ||
| var_dump($client_linger['l_onoff'] > 0); | ||
| var_dump($client_linger['l_linger']); | ||
|
|
||
| fclose($accepted); | ||
| fclose($client); | ||
| fclose($server); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| Listen SO_LINGER | ||
| bool(true) | ||
| int(10) | ||
| Server SO_LINGER | ||
| bool(true) | ||
| int(10) | ||
| Client SO_LINGER | ||
| bool(true) | ||
| int(8) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.