-
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?
Conversation
|
|
||
| #if defined(TCP_USER_TIMEOUT) | ||
| case TCP_USER_TIMEOUT: { | ||
| ov = zval_get_long(arg4); |
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
zend_long timeout = zval_get_long(arg4);
<overflow check on timeout>
unsigned int val = (unsigned int)timeout;
optlen = sizeof(val);
opt_ptr = &val;
ext/sockets/sockets.c
Outdated
| zend_long timeout = zval_get_long(arg4); | ||
|
|
||
| // TCP_USER_TIMEOUT unsigned int | ||
| if (ZEND_LONG_UINT_OVFL(timeout)) { |
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.
can you reestablish the former version, i.e. if (timeout < 0 || timeout > UINT_MAX) ?
that might solve the 32 bits version issue.
|
|
||
| #if defined(TCP_USER_TIMEOUT) | ||
| case TCP_USER_TIMEOUT: { | ||
| ov = zval_get_long(arg4); |
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 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.
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.
Bear with me :) we re almost there.
Useful to ensure PHP sockets are notified of socket failure when Sockets may be closed incorrectly and data can no longer be transmitted. eg Firewall dropping connection or peer device failure (commonly seen with Cloud load balancers).
From tcp(7) :It specifies the maximum amount of time in milliseconds that transmitted data may remain unacknowledged, or buffered data may remain untransmitted (due to zero window size) before TCP will forcibly close the corresponding connection and return ETIMEDOUT to the application.
Following #13816 for PR format for socket constants/