added setTimeout()
This commit is contained in:
Regular → Executable
+11
@@ -95,6 +95,17 @@ class TCPSocket {
|
|||||||
*/
|
*/
|
||||||
bool isValid();
|
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:
|
private:
|
||||||
/** file descriptor from tcp socket */
|
/** file descriptor from tcp socket */
|
||||||
|
|||||||
Reference in New Issue
Block a user