qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] resetting a stale VNC connection


From: David Ahern
Subject: Re: [Qemu-devel] resetting a stale VNC connection
Date: Tue, 21 Apr 2009 12:33:10 -0600
User-agent: Thunderbird 2.0.0.21 (X11/20090320)

This patch enables TCP keepalives on VNC connections. After 60-seconds
of idle time, probes are sent every 2 seconds with the connection
resetting after 4 failed probes. This might be a rather aggressive
setting -- 8 seconds until connection is reset.

Also, I believe this is a linux-specific way of doing this; not sure
what the posix/windows method is. Open to suggestions.

Yaniv: I do not believe this interferes with the 'shared desktop'.

Signed-off-by: David Ahern <address@hidden>


Avi Kivity wrote:
> David S. Ahern wrote:
>>>> I don't think so.  But enabling keepalives for vnc should be a one
>>>> liner (or rather two, since we want to change the default interval).
>>>>       
>>
>> What default interval would you prefer over the global values?
>>   
> 
> The global one is two hours.
> 
> Say sending a probe every two seconds, failing if four probes don't come
> back?
> 
> 
> 
diff --git a/vnc.c b/vnc.c
index ab1f044..7884a55 100644
--- a/vnc.c
+++ b/vnc.c
@@ -32,6 +32,10 @@
 
 #define VNC_REFRESH_INTERVAL (1000 / 30)
 
+#define VNC_TCP_KEEPIDLE  60
+#define VNC_TCP_KEEPINTVL  2
+#define VNC_TCP_KEEPCNT    4
+
 #include "vnc_keysym.h"
 #include "d3des.h"
 
@@ -2015,12 +2019,40 @@ 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) {
+
+        /* 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 60-seconds of idle time, send probes every 2 seconds
+         * dropping the connection after 4 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 prove interval\n");
+        }
+        val = VNC_TCP_KEEPCNT;
+        if (setsockopt(csock, IPPROTO_TCP, TCP_KEEPCNT,
+                       &val, sizeof(val)) < 0) {
+            fprintf(stderr, "VNC: failed to set tcp prove interval\n");
+        }
+
         vnc_connect(vs, csock);
     }
 }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]