diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-10-10 11:39:25 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-10-10 11:39:25 +0200 |
commit | 2e71bf974f42cfe9edf9c8289602eec0c7ecadf9 (patch) | |
tree | 574bd00266dacf3dc7b21d6f601131c85340663b /src/TcpSocket.cpp | |
parent | bbafa23de92eb542f4c8266d484aed9faf88d360 (diff) | |
parent | 4576c71f10dc009ce0dd9aedbc2f81a3e1a8be0e (diff) | |
download | dabmux-2e71bf974f42cfe9edf9c8289602eec0c7ecadf9.tar.gz dabmux-2e71bf974f42cfe9edf9c8289602eec0c7ecadf9.tar.bz2 dabmux-2e71bf974f42cfe9edf9c8289602eec0c7ecadf9.zip |
Merge next into servicelinking
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; |