From e646e53dac90e68280289ae3789cf016228b14ad Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Tue, 25 Jun 2019 17:18:24 -0700 Subject: [PATCH] use poll instead of select in SocketServer --- ixwebsocket/IXSocketServer.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/ixwebsocket/IXSocketServer.cpp b/ixwebsocket/IXSocketServer.cpp index 4fb103cd..1bb62d55 100644 --- a/ixwebsocket/IXSocketServer.cpp +++ b/ixwebsocket/IXSocketServer.cpp @@ -213,17 +213,12 @@ namespace ix { if (_stop) return; - // Use select to check whether a new connection is in progress - fd_set rfds; - struct timeval timeout; - timeout.tv_sec = 0; - timeout.tv_usec = 10 * 1000; // 10ms timeout + // Use poll to check whether a new connection is in progress + int timeoutMs = 10; + bool readyToRead = true; + PollResultType pollResult = Socket::poll(readyToRead, timeoutMs, _serverFd); - FD_ZERO(&rfds); - FD_SET(_serverFd, &rfds); - - if (select(_serverFd + 1, &rfds, nullptr, nullptr, &timeout) < 0 && - (errno == EBADF || errno == EINVAL)) + if (pollResult == PollResultType::Error) { std::stringstream ss; ss << "SocketServer::run() error in select: " @@ -232,9 +227,8 @@ namespace ix continue; } - if (!FD_ISSET(_serverFd, &rfds)) + if (pollResult != PollResultType::ReadyForRead) { - // We reached the select timeout, and no new connections are pending continue; }