Emulate Linux socket timeout signaling on Windows

This commit is contained in:
Justine Tunney 2024-09-17 00:24:08 -07:00
parent 65e425fbca
commit b14dddcc18
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
8 changed files with 246 additions and 29 deletions

View file

@ -36,14 +36,17 @@ textwindows int sys_setsockopt_nt(struct Fd *fd, int level, int optname,
const void *optval, uint32_t optlen) {
// socket read/write timeouts
// timeout of zero means wait forever (default)
if (level == SOL_SOCKET &&
(optname == SO_RCVTIMEO || optname == SO_SNDTIMEO)) {
if (!(optval && optlen == sizeof(struct timeval)))
if (!optval)
return einval();
if (optlen < sizeof(struct timeval))
return einval();
const struct timeval *tv = optval;
int64_t ms = timeval_tomillis(*tv);
if (ms > -1u)
ms = 0; // wait forever (default) yes zero actually means this
ms = -1u;
if (optname == SO_RCVTIMEO)
fd->rcvtimeo = ms;
if (optname == SO_SNDTIMEO)
@ -51,7 +54,7 @@ textwindows int sys_setsockopt_nt(struct Fd *fd, int level, int optname,
return 0; // we want to handle this on our own
}
// how to make close() a blocking i/o call
// how to make close() a blocking i/o call lool
union {
uint32_t millis;
struct linger_nt linger;