From f16f9c0634693ce0a53bb269aa2d36402e51f92f Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Mon, 10 Oct 2016 11:19:15 +0200 Subject: Replace select() by poll() for TcpSocket accept --- src/TcpSocket.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/TcpSocket.cpp b/src/TcpSocket.cpp index 6e7c31d..433e5c1 100644 --- a/src/TcpSocket.cpp +++ b/src/TcpSocket.cpp @@ -32,6 +32,7 @@ #include #include #include +#include using namespace std; @@ -168,17 +169,11 @@ TcpSocket TcpSocket::accept() boost::optional TcpSocket::accept(int timeout_ms) { - fd_set rfds; - struct timeval tv; - int retval; + struct pollfd fds[1]; + fds[0].fd = m_sock; + fds[0].events = POLLIN | POLLOUT; - FD_ZERO(&rfds); - FD_SET(m_sock, &rfds); - - tv.tv_sec = 0; - tv.tv_usec = 1000ul * timeout_ms; - - retval = select(1, &rfds, NULL, NULL, &tv); + int retval = poll(fds, 1, timeout_ms); if (retval == -1) { stringstream ss; -- cgit v1.2.3