diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-10-10 10:10:24 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-10-10 10:10:24 +0200 |
commit | e2e1a0f374aeffc933d0e5d295607197d6b74a4a (patch) | |
tree | 1878bc61a66d221d3e4395e10e1d72aa487fb36e /src/TcpSocket.cpp | |
parent | eccfa8ad3774205a929ff70090540d24674618a1 (diff) | |
download | dabmux-e2e1a0f374aeffc933d0e5d295607197d6b74a4a.tar.gz dabmux-e2e1a0f374aeffc933d0e5d295607197d6b74a4a.tar.bz2 dabmux-e2e1a0f374aeffc933d0e5d295607197d6b74a4a.zip |
Fix dabOutputTCP shutdown using accept() with timeout
Diffstat (limited to 'src/TcpSocket.cpp')
-rw-r--r-- | src/TcpSocket.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/TcpSocket.cpp b/src/TcpSocket.cpp index 13efece..6e7c31d 100644 --- a/src/TcpSocket.cpp +++ b/src/TcpSocket.cpp @@ -166,6 +166,34 @@ TcpSocket TcpSocket::accept() } } +boost::optional<TcpSocket> TcpSocket::accept(int timeout_ms) +{ + fd_set rfds; + struct timeval tv; + int retval; + + 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); + + 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; |