use poll instead of select in SocketServer
This commit is contained in:
parent
6b8aa43ec0
commit
e646e53dac
@ -213,17 +213,12 @@ namespace ix
|
|||||||
{
|
{
|
||||||
if (_stop) return;
|
if (_stop) return;
|
||||||
|
|
||||||
// Use select to check whether a new connection is in progress
|
// Use poll to check whether a new connection is in progress
|
||||||
fd_set rfds;
|
int timeoutMs = 10;
|
||||||
struct timeval timeout;
|
bool readyToRead = true;
|
||||||
timeout.tv_sec = 0;
|
PollResultType pollResult = Socket::poll(readyToRead, timeoutMs, _serverFd);
|
||||||
timeout.tv_usec = 10 * 1000; // 10ms timeout
|
|
||||||
|
|
||||||
FD_ZERO(&rfds);
|
if (pollResult == PollResultType::Error)
|
||||||
FD_SET(_serverFd, &rfds);
|
|
||||||
|
|
||||||
if (select(_serverFd + 1, &rfds, nullptr, nullptr, &timeout) < 0 &&
|
|
||||||
(errno == EBADF || errno == EINVAL))
|
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "SocketServer::run() error in select: "
|
ss << "SocketServer::run() error in select: "
|
||||||
@ -232,9 +227,8 @@ namespace ix
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FD_ISSET(_serverFd, &rfds))
|
if (pollResult != PollResultType::ReadyForRead)
|
||||||
{
|
{
|
||||||
// We reached the select timeout, and no new connections are pending
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user