-
Notifications
You must be signed in to change notification settings - Fork 8k
ext/sockets: adding Linux's TCP_USER_TIMEOUT constant. #20708
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
base: master
Are you sure you want to change the base?
Changes from 6 commits
d87015f
67ee0ad
1117658
1cd17b1
a804258
840e546
efb6560
66a4ea4
dab9d20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2329,6 +2329,22 @@ PHP_FUNCTION(socket_set_option) | |
| } | ||
| #endif | ||
|
|
||
| #if defined(TCP_USER_TIMEOUT) | ||
| case TCP_USER_TIMEOUT: { | ||
| ov = zval_get_long(arg4); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not mean this. more like case TCP_USER_TIMEOUT: {
zend_long timeout timeout = zval_get_long(arg4);
// TCP_USER_TIMEOUT unsigned int
if (timeout < 0 || timeout > UINT_MAX) {
zend_argument_value_error(4, "must be of between 0 and %u", UINT_MAX);
RETURN_THROWS();
}
unsigned int val = (unsigned int)timeout;
optlen = sizeof(val);
opt_ptr = &val;
break;Your test passes because you test -1, but ov can never be greater than UINT_MAX.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bear with me :) we re almost there. |
||
|
|
||
| // TCP_USER_TIMEOUT unsigned int | ||
| if (ZEND_LONG_UINT_OVFL(ov)) { | ||
| zend_argument_value_error(4, "must be of between 0 and %u", UINT_MAX); | ||
| RETURN_THROWS(); | ||
| } | ||
|
|
||
| optlen = sizeof(ov); | ||
| opt_ptr = &ov; | ||
| break; | ||
| } | ||
| #endif | ||
|
|
||
| #if defined(UDP_SEGMENT) | ||
| case UDP_SEGMENT: { | ||
| ov = zval_get_long(arg4); | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| --TEST-- | ||
| Test if socket_set_option() works, option:TCP_USER_TIMEOUT | ||
| --EXTENSIONS-- | ||
| sockets | ||
| --SKIPIF-- | ||
| <?php | ||
| if (!defined('TCP_USER_TIMEOUT')) { die('skip TCP_USER_TIMEOUT is not defined'); } | ||
| ?> | ||
| --FILE-- | ||
| <?php | ||
| $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); | ||
| if (!$socket) { | ||
| die('Unable to create AF_INET socket [socket]'); | ||
| } | ||
| socket_set_block($socket); | ||
|
|
||
| try { | ||
| socket_setopt($socket, SOL_TCP, TCP_USER_TIMEOUT, -1); | ||
| } catch (\ValueError $e) { | ||
| echo $e->getMessage(), PHP_EOL; | ||
| } | ||
|
|
||
| $timeout = 200; | ||
| $retval_2 = socket_set_option($socket, SOL_TCP, TCP_USER_TIMEOUT, $timeout); | ||
| $retval_3 = socket_get_option($socket, SOL_TCP, TCP_USER_TIMEOUT); | ||
| var_dump($retval_2); | ||
| var_dump($retval_3 === $timeout); | ||
| socket_close($socket); | ||
| ?> | ||
| --EXPECTF-- | ||
| socket_setopt(): Argument #4 ($value) must be of between 0 and %d | ||
| bool(true) | ||
| bool(true) |
Uh oh!
There was an error while loading. Please reload this page.
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.
my bad, I realise ov is an int.
you would need the following change