Enable SO_KEEPALIVE

This hopefully prevents unnecessary TCP timeouts.
This commit is contained in:
Markus Mäkelä
2019-11-02 13:26:51 +02:00
parent ca52d1cdce
commit 03e8e85a22

View File

@ -950,12 +950,16 @@ bool configure_network_socket(int so, int type)
{ {
int one = 1; int one = 1;
if (type != AF_UNIX && setsockopt(so, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)) != 0) if (type != AF_UNIX)
{
if (setsockopt(so, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)) != 0
|| setsockopt(so, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof(one)) != 0)
{ {
MXS_ERROR("Failed to set socket option: %d, %s.", errno, mxs_strerror(errno)); MXS_ERROR("Failed to set socket option: %d, %s.", errno, mxs_strerror(errno));
mxb_assert(!true); mxb_assert(!true);
return false; return false;
} }
}
return setnonblocking(so) == 0; return setnonblocking(so) == 0;
} }