Add stream socket so_linger context option - #20808
Conversation
This adds so_linger stream socket context options that is used to set the lingering time in seconds. If the value is lower or equal to 0, then the lingering is disabled.
I just double checked, but FreeBSD set l_onoff field by masking with SO_LINGER (which is 0x0080) l.l_onoff = so->so_options & SO_LINGER; |
| if (sockvals->mask & PHP_SOCKVAL_SO_LINGER) { | ||
| struct linger linger_val = { | ||
| .l_onoff = (sockvals->linger > 0), | ||
| .l_linger = (unsigned short)sockvals->linger |
There was a problem hiding this comment.
the only subtlety is setting l_onoff with 1 but with l_linger with 0 is a valid use case (closing connection w/o handshake aka RST on close) but you can only carry one value per socket option right ?
There was a problem hiding this comment.
saying that, even rust expresses this in a similar way I just recalled having pushing a PR in there :)
| if (sockvals != NULL) { | ||
| #ifdef SO_LINGER | ||
| if (sockvals->mask & PHP_SOCKVAL_SO_LINGER) { | ||
| struct linger linger_val = { |
There was a problem hiding this comment.
what can be done eventualy here, is something like this:
unsigned short secs = sockvals->linger > USHRT_MAX ? USHRT_MAX : (unsigned short)sockvals->linger;
struct linger linger_val = {
.l_onoff = (sockvals->linger > 0),
.l_linger = sockvals->linger > 0 ? secs : 0,
};| die('Unable to accept connection'); | ||
| } | ||
|
|
||
| $so_linger = PHP_OS_FAMILY === 'Darwin' ? SO_LINGER_SEC : SO_LINGER; |
There was a problem hiding this comment.
could be instead
$so_linger = defined('SO_LINGER_SEC') : SO_LINGER_SEC : SO_LINGER;
65536 became l_onoff=1, l_linger=0, an abortive close. Also fix the test's SO_LINGER_SEC detection and drop its unreachable SKIPIF.
This adds so_linger stream socket context options that is used to set the lingering time in seconds. If the value is lower or equal to 0, then the lingering is disabled.