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
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19

View File

@ -950,11 +950,15 @@ bool configure_network_socket(int so, int type)
{
int one = 1;
if (type != AF_UNIX && setsockopt(so, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)) != 0)
if (type != AF_UNIX)
{
MXS_ERROR("Failed to set socket option: %d, %s.", errno, mxs_strerror(errno));
mxb_assert(!true);
return false;
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));
mxb_assert(!true);
return false;
}
}
return setnonblocking(so) == 0;