summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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);