summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2016-09-21 19:37:38 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2016-09-21 19:37:38 +0200
commit7a66d48f815b475d98e56a99a5125ba3b8592e8d (patch)
tree6555c5e3ab2cf0664e2174b89c146edaff7b8257
parent0b36f44c7bf0d8fc0a230c9acdc480cbd3965e5e (diff)
downloaddabmod-7a66d48f815b475d98e56a99a5125ba3b8592e8d.tar.gz
dabmod-7a66d48f815b475d98e56a99a5125ba3b8592e8d.tar.bz2
dabmod-7a66d48f815b475d98e56a99a5125ba3b8592e8d.zip
Add TCP input recv timeout of 30s
-rw-r--r--src/InputTcpReader.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/InputTcpReader.cpp b/src/InputTcpReader.cpp
index 34ccb2e..94ec0ad 100644
--- a/src/InputTcpReader.cpp
+++ b/src/InputTcpReader.cpp
@@ -32,6 +32,9 @@
#include "InputReader.h"
#include "PcDebug.h"
#include "Utils.h"
+#include <sys/socket.h>
+#include <unistd.h>
+#include <errno.h>
InputTcpReader::InputTcpReader()
{
@@ -88,6 +91,15 @@ void InputTcpReader::Open(const std::string& endpoint)
throw std::runtime_error(ss.str());
}
+ /* Set recv timeout of 30s, see socket(7) for details */
+ struct timeval tv = {0};
+ tv.tv_sec = 30;
+ if (setsockopt(m_sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(struct timeval)) == -1) {
+ std::stringstream ss;
+ ss << "Could not set socket recv timeout: " << strerror(errno);
+ throw std::runtime_error(ss.str());
+ }
+
if (connect(m_sock, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
std::stringstream ss;
ss << "Could not connect to " << hostname << ":" << port << " :" << strerror(errno);