Added SO_KEEPALIVE to all socket connections by default.
This commit is contained in:
parent
f9a0ec5b78
commit
169830bd15
1 changed files with 8 additions and 0 deletions
|
@ -548,6 +548,9 @@ Socket::Connection::Connection(std::string host, int port, bool nonblock){
|
|||
flags |= O_NONBLOCK;
|
||||
fcntl(sock, F_SETFL, flags);
|
||||
}
|
||||
int optval = 1;
|
||||
int optlen = sizeof(optval);
|
||||
setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen);
|
||||
}
|
||||
}// Socket::Connection TCP Contructor
|
||||
|
||||
|
@ -985,6 +988,11 @@ Socket::Connection Socket::Server::accept(bool nonblock){
|
|||
flags |= O_NONBLOCK;
|
||||
fcntl(r, F_SETFL, flags);
|
||||
}
|
||||
if (r >= 0){
|
||||
int optval = 1;
|
||||
int optlen = sizeof(optval);
|
||||
setsockopt(r, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen);
|
||||
}
|
||||
Socket::Connection tmp(r);
|
||||
tmp.remoteaddr = tmpaddr;
|
||||
if (r < 0){
|
||||
|
|
Loading…
Add table
Reference in a new issue