Fix NT accept/connect not initializing with SO_UPDATE_*_CONTEXT (#1164)

This commit is contained in:
Gavin Hayes 2024-05-17 05:45:30 -04:00 committed by GitHub
parent 2f3c6e7cc3
commit 624119ea38
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 173 additions and 8 deletions

View file

@ -87,10 +87,6 @@ static int sys_accept_nt_start(int64_t handle, struct NtOverlapped *overlap,
if (g_acceptex.lpAcceptEx(args->listensock, handle, args->buffer, 0,
sizeof(args->buffer->local),
sizeof(args->buffer->remote), 0, overlap)) {
// inherit properties of listening socket
unassert(!__imp_setsockopt(args->listensock, SOL_SOCKET,
kNtSoUpdateAcceptContext, &handle,
sizeof(handle)));
return 0;
} else {
return -1;
@ -123,6 +119,13 @@ textwindows int sys_accept_nt(struct Fd *f, struct sockaddr_storage *addr,
goto Finish;
}
// inherit properties of listening socket
// errors ignored as if f->handle was created before forking
// this fails with WSAENOTSOCK, see
// https://github.com/jart/cosmopolitan/issues/1174
__imp_setsockopt(resources.handle, SOL_SOCKET, kNtSoUpdateAcceptContext,
&f->handle, sizeof(f->handle));
// create file descriptor for new socket
// don't inherit the file open mode bits
int oflags = 0;