From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LwS1s-0003Ir-Ve for qemu-devel@nongnu.org; Tue, 21 Apr 2009 22:17:41 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LwS1o-0003Hx-Tf for qemu-devel@nongnu.org; Tue, 21 Apr 2009 22:17:40 -0400 Received: from [199.232.76.173] (port=57447 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LwS1o-0003Hu-OA for qemu-devel@nongnu.org; Tue, 21 Apr 2009 22:17:36 -0400 Received: from sj-iport-2.cisco.com ([171.71.176.71]:11928) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.60) (envelope-from ) id 1LwS1o-00087b-8j for qemu-devel@nongnu.org; Tue, 21 Apr 2009 22:17:36 -0400 Received: from sj-core-1.cisco.com (sj-core-1.cisco.com [171.71.177.237]) by sj-dkim-4.cisco.com (8.12.11/8.12.11) with ESMTP id n3M2HYQB013235 for ; Tue, 21 Apr 2009 19:17:34 -0700 Received: from xbh-sjc-221.amer.cisco.com (xbh-sjc-221.cisco.com [128.107.191.63]) by sj-core-1.cisco.com (8.13.8/8.13.8) with ESMTP id n3M2HXFW028798 for ; Wed, 22 Apr 2009 02:17:34 GMT Message-ID: <49EE7E35.5050908@cisco.com> Date: Tue, 21 Apr 2009 20:17:25 -0600 From: "David S. Ahern" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------080506040204050509030100" 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. --------------080506040204050509030100 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Something is blocking this message from my gmail account; trying again with this one. 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 --------------080506040204050509030100 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); } } --------------080506040204050509030100--