From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LwMEy-0001Rj-6Y for qemu-devel@nongnu.org; Tue, 21 Apr 2009 16:06:48 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LwMEt-0001PS-HL for qemu-devel@nongnu.org; Tue, 21 Apr 2009 16:06:47 -0400 Received: from [199.232.76.173] (port=60081 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LwMEt-0001PJ-9G for qemu-devel@nongnu.org; Tue, 21 Apr 2009 16:06:43 -0400 Received: from wf-out-1314.google.com ([209.85.200.168]:54769) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LwMEs-0003So-Mn for qemu-devel@nongnu.org; Tue, 21 Apr 2009 16:06:43 -0400 Received: by wf-out-1314.google.com with SMTP id 29so2472399wff.4 for ; Tue, 21 Apr 2009 13:06:41 -0700 (PDT) Message-ID: <49EE274E.4010806@gmail.com> Date: Tue, 21 Apr 2009 14:06:38 -0600 From: David Ahern MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------040800010906040403080007" Subject: [Qemu-devel] PATCH: enabling TCP keepalives on VNC connections List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------040800010906040403080007 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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 david --------------040800010906040403080007 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..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); } } --------------040800010906040403080007--