added KEEPALIVE option to the TCP socket so that at least we are notified if the peer turns out to be non-connected
This commit is contained in:
parent
e1e83dfba6
commit
0f596d7a6e
|
|
@ -120,6 +120,12 @@ private:
|
||||||
|
|
||||||
// turn socket into a non-blocking socket and set the close-on-exec bit
|
// turn socket into a non-blocking socket and set the close-on-exec bit
|
||||||
fcntl(_socket, F_SETFL, O_NONBLOCK | O_CLOEXEC);
|
fcntl(_socket, F_SETFL, O_NONBLOCK | O_CLOEXEC);
|
||||||
|
|
||||||
|
// we set the 'keepalive' option so that we automatically detect if the peer is dead
|
||||||
|
int keepalive = 1;
|
||||||
|
|
||||||
|
// set the keepalive option
|
||||||
|
setsockopt(_socket, SOL_SOCKET, SO_KEEPALIVE, &keepalive, sizeof(keepalive));
|
||||||
|
|
||||||
// try to connect non-blocking
|
// try to connect non-blocking
|
||||||
if (connect(_socket, addresses[i]->ai_addr, addresses[i]->ai_addrlen) == 0) break;
|
if (connect(_socket, addresses[i]->ai_addr, addresses[i]->ai_addrlen) == 0) break;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue