Switch to poll() to be safe against stack corruption from exceeding FD_SETSIZE

Fortunately, the fd_set definition is not prone to stack corruption on Windows,
because FD_SETSIZE is the maximum number of sockets in a fd_set, not
the maximum value socket file descriptor that can be stored in a fd_set.

https://beesbuzz.biz/code/5739-The-problem-with-select-vs-poll
This commit is contained in:
Cameron Gutman
2020-07-26 19:53:52 -07:00
parent 84f2421fbf
commit 117a7c637f
4 changed files with 136 additions and 82 deletions

View File

@@ -29,6 +29,7 @@ typedef int SOCKADDR_LEN;
#include <netdb.h>
#include <errno.h>
#include <signal.h>
#include <poll.h>
#define ioctlsocket ioctl
#define LastSocketError() errno
@@ -59,6 +60,7 @@ int setNonFatalRecvTimeoutMs(SOCKET s, int timeoutMs);
void setRecvTimeout(SOCKET s, int timeoutSec);
void closeSocket(SOCKET s);
int isPrivateNetworkAddress(struct sockaddr_storage* address);
int pollSockets(struct pollfd* pollFds, int pollFdsCount, int timeoutMs);
int initializePlatformSockets(void);
void cleanupPlatformSockets(void);