From bb86b8b7137f967c9c67144ca7ba5064a9d7f9ed Mon Sep 17 00:00:00 2001 From: john30 Date: Sat, 4 Mar 2017 08:38:27 +0100 Subject: [PATCH] added setTimeout() --- src/lib/utils/tcpsocket.h | 11 +++++++++++ 1 file changed, 11 insertions(+) mode change 100644 => 100755 src/lib/utils/tcpsocket.h diff --git a/src/lib/utils/tcpsocket.h b/src/lib/utils/tcpsocket.h old mode 100644 new mode 100755 index 6b8f3263..1855aaf8 --- a/src/lib/utils/tcpsocket.h +++ b/src/lib/utils/tcpsocket.h @@ -95,6 +95,17 @@ class TCPSocket { */ bool isValid(); + /** + * Set the timeout for @a send and @a recv. + * @param timeout the timeout in seconds. + */ + void setTimeout(int timeout) { + struct timeval t; + t.tv_usec = 0; + t.tv_sec = timeout; + setsockopt(m_sfd, SO_RCVTIMEO, SO_REUSEADDR, &t, sizeof(t)); + setsockopt(m_sfd, SO_SNDTIMEO, SO_REUSEADDR, &t, sizeof(t)); + } private: /** file descriptor from tcp socket */