From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LwKmX-0001ce-FH for qemu-devel@nongnu.org; Tue, 21 Apr 2009 14:33:21 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LwKmT-0001cD-34 for qemu-devel@nongnu.org; Tue, 21 Apr 2009 14:33:21 -0400 Received: from [199.232.76.173] (port=33006 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LwKmS-0001cA-SP for qemu-devel@nongnu.org; Tue, 21 Apr 2009 14:33:16 -0400 Received: from rv-out-0708.google.com ([209.85.198.247]:34253) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LwKmS-0007fo-Eu for qemu-devel@nongnu.org; Tue, 21 Apr 2009 14:33:16 -0400 Received: by rv-out-0708.google.com with SMTP id c5so867904rvf.22 for ; Tue, 21 Apr 2009 11:33:13 -0700 (PDT) Message-ID: <49EE1166.4040409@gmail.com> Date: Tue, 21 Apr 2009 12:33:10 -0600 From: David Ahern MIME-Version: 1.0 Subject: Re: [Qemu-devel] resetting a stale VNC connection References: <49EDC3B4.7030508@cisco.com> <49EDCC6F.1020703@redhat.com> <49EDE1EF.4070203@cisco.com> <49EDF082.4050900@redhat.com> <49EDF220.2040200@redhat.com> <49EDF434.3000202@cisco.com> <49EDF574.9090506@redhat.com> In-Reply-To: <49EDF574.9090506@redhat.com> Content-Type: multipart/mixed; boundary="------------070803090102010301020907" List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Avi Kivity Cc: Yaniv Kaul , qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------070803090102010301020907 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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 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? > > > --------------070803090102010301020907 Content-Type: text/plain; name="vnc-enable-keepalives.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="vnc-enable-keepalives.patch" 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); } } --------------070803090102010301020907--