session CHANGE enable keep-alive on server/client sockets
diff --git a/src/session_client.c b/src/session_client.c
index f79182b..aed5ad2 100644
--- a/src/session_client.c
+++ b/src/session_client.c
@@ -930,6 +930,15 @@
return -1;
}
+ /* enable keep-alive */
+ i = 1;
+ if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &i, sizeof i) == -1) {
+ ERR("Setsockopt failed (%s).", strerror(errno));
+ close(sock);
+ freeaddrinfo(res_list);
+ return -1;
+ }
+
/* we're done, network connection established */
break;
}
diff --git a/src/session_server.c b/src/session_server.c
index 576a9cd..5733581 100644
--- a/src/session_server.c
+++ b/src/session_server.c
@@ -184,7 +184,7 @@
goto fail;
}
- if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&optVal, optLen)) {
+ if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&optVal, optLen) == -1) {
ERR("Could not set socket SO_REUSEADDR socket option (%s).", strerror(errno));
goto fail;
}
@@ -330,6 +330,14 @@
return -1;
}
+ /* enable keep-alive */
+ flags = 1;
+ if (setsockopt(ret, SOL_SOCKET, SO_KEEPALIVE, &flags, sizeof flags) == -1) {
+ ERR("Setsockopt failed (%s).", strerror(errno));
+ close(ret);
+ return -1;
+ }
+
if (idx) {
*idx = i;
}