Enable TCP keepalive on sockets

This commit is contained in:
Florent Le Coz
2014-02-08 08:14:24 +01:00
parent eb2a2e75c2
commit d46e7ee8c9
+3
View File
@@ -21,6 +21,9 @@ SocketHandler::SocketHandler():
{
if ((this->socket = ::socket(AF_INET, SOCK_STREAM, 0)) == -1)
throw std::runtime_error("Could not create socket");
int optval = 1;
if (::setsockopt(this->socket, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval)) == -1)
log_warning("Failed to enable TCP keepalive on socket: " << strerror(errno));
}
std::pair<bool, std::string> SocketHandler::connect(const std::string& address, const std::string& port)