Closed GravisZro closed 1 month ago
I would rewrite socket initialization as
#ifdef WIN32
dedicated_listen_socket = socket(AF_INET, SOCK_STREAM, 0);
// ...
unsigned long arg = 1;
ioctlsocket(dedicated_listen_socket, FIONBIO, &arg);
#else // WIN32
#ifndef SOCK_NONBLOCK
#include <fcntl.h>
#define SOCK_NONBLOCK O_NONBLOCK
#endif
dedicated_listen_socket = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
#endif
And you don't have to use additional fcntl(..., F_SETFL (fcntl(..., F_GETFL) ))
calls on Linux / macOS platforms. There a plenty code duplication around socket initialization, so would be some helper functions would be useful.
@winterheart Not all of these are socket initializations. As such, I consolidated the code into a single function in networking.h
. Including networking.h
in other headers lead to conflicting duplicate code which is why there are now code deletions.
Would someone please merge this? It's been reviewed by two people already.
PR has regression on Linux, see #398.
These take two different types of arguments but worked in the past due to long being 32-bit.
Pull Request Type
Description
The
ioctl
argument for UNIX systems isint*
while theioctlsocket
argument for Windows isunsigned long*
. On 32-bit systems theses coincided so no problems but not on 64-bit. However, the behavior ofioctl
calls is non-standard which is why code should usefnctl
.See also:
Checklist
Additional Comments