Complete dumb_socketpair() implementation
Original int socketpair(int domain, int type, int protocol, int sv[2]); manpage states that "Since Linux 2.6.27, socketpair() supports the SOCK_NONBLOCK and SOCK_CLOEXEC flags in the type argument":
SOCK_NONBLOCK support is already present in openconnect through int set_sock_nonblock(int fd) both for Linux and Windows (via FIONBIO flag).
SOCK_CLOEXEC (or its equivalents) support for Windows is missing in openconnect, so this merge request completes socketpair() implementation for Windows through the support of WSA_FLAG_NO_HANDLE_INHERIT flag specified as a WSASocket() parameter (https://etherealwake.com/2021/01/portable-sockets-basics/).
Why do I suggest to replace listener = socket(domain, SOCK_STREAM,...
with
listener = WSASocket(domain, SOCK_STREAM, domain == AF_INET ? IPPROTO_TCP : 0, NULL, 0, (WSA_FLAG_OVERLAPPED | (no_inherit_flag ? WSA_FLAG_NO_HANDLE_INHERIT : 0)));
but not with
listener = WSASocket(domain, SOCK_STREAM, domain == AF_INET ? IPPROTO_TCP : 0, NULL, 0, no_inherit_flag ? WSA_FLAG_NO_HANDLE_INHERIT : 0)?
Because according to https://stackoverflow.com/questions/65238091/why-would-a-call-to-wsasocket-vs-socket-cause-sends-to-block and MSDN:
sock = WSASocketW(AF_INET, SOCK_STREAM, IPOROTO_TCP, nullptr, 0, WSA_FLAG_OVERLAPPED);
Is the same as doing:
sock = socket(AF_INET, SOCK_STREAM, IPOROTO_TCP);
the current MSDN documentation for the socket() call states that "The socket that is created will have the overlapped attribute as a default." so it's expected that to create a functionally equivalent socket with WSASocket you would need the WSA_FLAG_OVERLAPPED flag.