diff options
Diffstat (limited to 'src/TcpSocket.cpp')
-rw-r--r-- | src/TcpSocket.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/TcpSocket.cpp b/src/TcpSocket.cpp index 13efece..433e5c1 100644 --- a/src/TcpSocket.cpp +++ b/src/TcpSocket.cpp @@ -32,6 +32,7 @@ #include <string.h> #include <signal.h> #include <stdint.h> +#include <poll.h> using namespace std; @@ -166,6 +167,28 @@ TcpSocket TcpSocket::accept() } } +boost::optional<TcpSocket> TcpSocket::accept(int timeout_ms) +{ + struct pollfd fds[1]; + fds[0].fd = m_sock; + fds[0].events = POLLIN | POLLOUT; + + int retval = poll(fds, 1, timeout_ms); + + if (retval == -1) { + stringstream ss; + ss << "TCP Socket accept error: " << strerror(errno); + throw std::runtime_error(ss.str()); + } + else if (retval) { + return accept(); + } + else { + return boost::none; + } +} + + InetAddress TcpSocket::getOwnAddress() const { return m_own_address; |