[Spice-devel] [spice-server 1/3] Always enable TCP keepalive
Christophe Fergeau
cfergeau at redhat.com
Thu Mar 10 15:57:36 UTC 2016
Always enabled, hardcoded interval
as per https://bugzilla.redhat.com/show_bug.cgi?id=1298590
---
server/reds.c | 40 ++++++++++++++++++++++++++--------------
1 file changed, 26 insertions(+), 14 deletions(-)
diff --git a/server/reds.c b/server/reds.c
index 72282a6..8f03239 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -2287,6 +2287,31 @@ static void reds_handle_ssl_accept(int fd, int event, void *data)
}
}
+#define KEEPALIVE_TIMEOUT (10*60)
+
+static bool reds_init_keepalive(int socket)
+{
+ int keepalive = 1;
+ int keepalive_timeout = KEEPALIVE_TIMEOUT;
+
+ if (setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE, &keepalive, sizeof(keepalive)) == -1) {
+ if (errno != ENOTSUP) {
+ spice_printerr("setsockopt for keepalive failed, %s", strerror(errno));
+ return false;
+ }
+ }
+
+ if (setsockopt(socket, SOL_TCP, TCP_KEEPIDLE,
+ &keepalive_timeout, sizeof(keepalive_timeout)) == -1) {
+ if (errno != ENOTSUP) {
+ spice_printerr("setsockopt for keepalive timeout failed, %s", strerror(errno));
+ return false;
+ }
+ }
+
+ return true;
+}
+
static RedLinkInfo *reds_init_client_connection(RedsState *reds, int socket)
{
RedLinkInfo *link;
@@ -2309,20 +2334,7 @@ static RedLinkInfo *reds_init_client_connection(RedsState *reds, int socket)
}
}
- if (reds->keepalive_timeout > 0) {
- int keepalive = 1;
- if (setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE, &keepalive, sizeof(keepalive)) == -1) {
- if (errno != ENOTSUP) {
- spice_printerr("setsockopt for keepalive failed, %s", strerror(errno));
- }
- }
- if (setsockopt(socket, SOL_TCP, TCP_KEEPIDLE,
- &reds->keepalive_timeout, sizeof(reds->keepalive_timeout)) == -1) {
- if (errno != ENOTSUP) {
- spice_printerr("setsockopt for keepalive timeout failed, %s", strerror(errno));
- }
- }
- }
+ reds_init_keepalive(socket);
link = spice_new0(RedLinkInfo, 1);
link->reds = reds;
--
2.5.0
More information about the Spice-devel
mailing list