this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix O_NONBLOCK for `accept`ed sockets

macOS and BSD make sockets created from `accept` inherit the listening socket's O_NONBLOCK flag (and maybe some others, but that requires further testing).

+10
+10
src/kernel/emulation/linux/network/accept.c
··· 5 5 #include "socket.h" 6 6 #include "duct.h" 7 7 #include "../bsdthread/cancelable.h" 8 + #include "../fcntl/fcntl.h" 9 + #include "../fcntl/open.h" 8 10 9 11 long sys_accept(int fd, void* from, int* socklen) 10 12 { ··· 30 32 fixed = (struct sockaddr_fixup*) from; 31 33 fixed->bsd_family = sfamily_linux_to_bsd(fixed->linux_family); 32 34 fixed->bsd_length = *socklen; 35 + 36 + // on macOS (and BSD), accept-ed sockets inherit O_NONBLOCK 37 + int parent_flags = sys_fcntl_nocancel(fd, F_GETFL, 0); 38 + int child_flags = sys_fcntl_nocancel(ret, F_GETFL, 0); 39 + // we silently ignore errors we get from fcntl (it's probably fine; fnctl shouldn't fail here) 40 + if (parent_flags >= 0 && child_flags >= 0 && (parent_flags & BSD_O_NONBLOCK) != 0) { 41 + sys_fcntl_nocancel(ret, F_SETFL, child_flags | BSD_O_NONBLOCK); 42 + } 33 43 } 34 44 35 45 return ret;