added setTimeout()

This commit is contained in:
john30
2017-03-04 08:38:27 +01:00
parent cc59b32f0d
commit bb86b8b713
Regular → Executable
+11
View File
@@ -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 */