|
|
e2c81d |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
e2c81d |
From: Christophe Fergeau <cfergeau@redhat.com>
|
|
|
e2c81d |
Date: Wed, 2 Mar 2016 12:24:11 +0100
|
|
|
e2c81d |
Subject: [PATCH] Always enable TCP keepalive
|
|
|
e2c81d |
|
|
|
e2c81d |
Always enabled, hardcoded interval
|
|
|
e2c81d |
as per https://bugzilla.redhat.com/show_bug.cgi?id=1298590
|
|
|
e2c81d |
---
|
|
|
e2c81d |
server/reds.c | 40 ++++++++++++++++++++++++++--------------
|
|
|
e2c81d |
1 file changed, 26 insertions(+), 14 deletions(-)
|
|
|
e2c81d |
|
|
|
e2c81d |
diff --git a/server/reds.c b/server/reds.c
|
|
|
e2c81d |
index a28027e..a848828 100644
|
|
|
e2c81d |
--- a/server/reds.c
|
|
|
e2c81d |
+++ b/server/reds.c
|
|
|
e2c81d |
@@ -2876,6 +2876,31 @@ static void reds_handle_ssl_accept(int fd, int event, void *data)
|
|
|
e2c81d |
reds_handle_new_link(link);
|
|
|
e2c81d |
}
|
|
|
e2c81d |
|
|
|
e2c81d |
+#define KEEPALIVE_TIMEOUT (10*60)
|
|
|
e2c81d |
+
|
|
|
e2c81d |
+static bool reds_init_keepalive(int socket)
|
|
|
e2c81d |
+{
|
|
|
e2c81d |
+ int keepalive = 1;
|
|
|
e2c81d |
+ int keepalive_timeout = KEEPALIVE_TIMEOUT;
|
|
|
e2c81d |
+
|
|
|
e2c81d |
+ if (setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE, &keepalive, sizeof(keepalive)) == -1) {
|
|
|
e2c81d |
+ if (errno != ENOTSUP) {
|
|
|
e2c81d |
+ spice_printerr("setsockopt for keepalive failed, %s", strerror(errno));
|
|
|
e2c81d |
+ return false;
|
|
|
e2c81d |
+ }
|
|
|
e2c81d |
+ }
|
|
|
e2c81d |
+
|
|
|
e2c81d |
+ if (setsockopt(socket, SOL_TCP, TCP_KEEPIDLE,
|
|
|
e2c81d |
+ &keepalive_timeout, sizeof(keepalive_timeout)) == -1) {
|
|
|
e2c81d |
+ if (errno != ENOTSUP) {
|
|
|
e2c81d |
+ spice_printerr("setsockopt for keepalive timeout failed, %s", strerror(errno));
|
|
|
e2c81d |
+ return false;
|
|
|
e2c81d |
+ }
|
|
|
e2c81d |
+ }
|
|
|
e2c81d |
+
|
|
|
e2c81d |
+ return true;
|
|
|
e2c81d |
+}
|
|
|
e2c81d |
+
|
|
|
e2c81d |
static RedLinkInfo *reds_init_client_connection(int socket)
|
|
|
e2c81d |
{
|
|
|
e2c81d |
RedLinkInfo *link;
|
|
|
e2c81d |
@@ -2899,20 +2924,7 @@ static RedLinkInfo *reds_init_client_connection(int socket)
|
|
|
e2c81d |
}
|
|
|
e2c81d |
}
|
|
|
e2c81d |
|
|
|
e2c81d |
- if (reds->keepalive_timeout > 0) {
|
|
|
e2c81d |
- int keepalive = 1;
|
|
|
e2c81d |
- if (setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE, &keepalive, sizeof(keepalive)) == -1) {
|
|
|
e2c81d |
- if (errno != ENOTSUP) {
|
|
|
e2c81d |
- spice_printerr("setsockopt for keepalive failed, %s", strerror(errno));
|
|
|
e2c81d |
- }
|
|
|
e2c81d |
- }
|
|
|
e2c81d |
- if (setsockopt(socket, SOL_TCP, TCP_KEEPIDLE,
|
|
|
e2c81d |
- &reds->keepalive_timeout, sizeof(reds->keepalive_timeout)) == -1) {
|
|
|
e2c81d |
- if (errno != ENOTSUP) {
|
|
|
e2c81d |
- spice_printerr("setsockopt for keepalive timeout failed, %s", strerror(errno));
|
|
|
e2c81d |
- }
|
|
|
e2c81d |
- }
|
|
|
e2c81d |
- }
|
|
|
e2c81d |
+ reds_init_keepalive(socket);
|
|
|
e2c81d |
|
|
|
e2c81d |
link = spice_new0(RedLinkInfo, 1);
|
|
|
e2c81d |
stream = spice_new0(RedsStream, 1);
|