[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] PATCH: enabling TCP keepalives on VNC connections
From: |
David Ahern |
Subject: |
[Qemu-devel] PATCH: enabling TCP keepalives on VNC connections |
Date: |
Tue, 21 Apr 2009 13:21:48 -0600 |
User-agent: |
Thunderbird 2.0.0.21 (X11/20090320) |
This patch enables TCP keepalives on VNC connections for linux hosts.
After 60-seconds of idle time, probes are sent every 12 seconds with the
connection resetting after 5 failed probes (ie., connection is closed if
no response received in 60-seconds).
Signed-off-by: David Ahern <address@hidden>
david
diff --git a/vnc.c b/vnc.c
index ab1f044..7a8bbd7 100644
--- a/vnc.c
+++ b/vnc.c
@@ -32,6 +32,12 @@
#define VNC_REFRESH_INTERVAL (1000 / 30)
+#ifdef __linux__
+#define VNC_TCP_KEEPIDLE 60
+#define VNC_TCP_KEEPINTVL 12
+#define VNC_TCP_KEEPCNT 5
+#endif
+
#include "vnc_keysym.h"
#include "d3des.h"
@@ -2015,12 +2021,41 @@ static void vnc_listen_read(void *opaque)
VncDisplay *vs = opaque;
struct sockaddr_in addr;
socklen_t addrlen = sizeof(addr);
+ int val;
/* Catch-up */
vga_hw_update();
int csock = accept(vs->lsock, (struct sockaddr *)&addr, &addrlen);
if (csock != -1) {
+#ifdef __linux__
+ /* best effort to enable keep alives */
+ val = 1;
+ if (setsockopt(csock, SOL_SOCKET, SO_KEEPALIVE,
+ &val, sizeof(val)) < 0) {
+ fprintf(stderr, "VNC: failed to enable keepalives\n");
+ }
+
+ /* after N-seconds of idle time, send probes every X seconds
+ * dropping the connection after Y failed probes.
+ */
+ val = VNC_TCP_KEEPIDLE;
+ if (setsockopt(csock, IPPROTO_TCP, TCP_KEEPIDLE,
+ &val, sizeof(val)) < 0) {
+ fprintf(stderr, "VNC: failed to set tcp idle interval\n");
+ }
+ val = VNC_TCP_KEEPINTVL;
+ if (setsockopt(csock, IPPROTO_TCP, TCP_KEEPINTVL,
+ &val, sizeof(val)) < 0) {
+ fprintf(stderr, "VNC: failed to set tcp probe interval\n");
+ }
+ val = VNC_TCP_KEEPCNT;
+ if (setsockopt(csock, IPPROTO_TCP, TCP_KEEPCNT,
+ &val, sizeof(val)) < 0) {
+ fprintf(stderr, "VNC: failed to set tcp missed probe count\n");
+ }
+#endif
+
vnc_connect(vs, csock);
}
}