* [Qemu-devel] PATCH: enabling TCP keepalives on VNC connections
@ 2009-04-21 19:21 David Ahern
0 siblings, 0 replies; 7+ messages in thread
From: David Ahern @ 2009-04-21 19:21 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 310 bytes --]
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 <dsahern@gmail.com>
david
[-- Attachment #2: vnc-enable-keepalives.patch --]
[-- Type: text/plain, Size: 1778 bytes --]
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);
}
}
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] PATCH: enabling TCP keepalives on VNC connections
@ 2009-04-21 20:06 David Ahern
0 siblings, 0 replies; 7+ messages in thread
From: David Ahern @ 2009-04-21 20:06 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 312 bytes --]
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 <dsahern@gmail.com>
david
[-- Attachment #2: vnc-enable-keepalives.patch --]
[-- Type: text/plain, Size: 1778 bytes --]
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);
}
}
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] PATCH: enabling TCP keepalives on VNC connections
@ 2009-04-22 1:46 David Ahern
0 siblings, 0 replies; 7+ messages in thread
From: David Ahern @ 2009-04-22 1:46 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 309 bytes --]
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 <dsahern@gmail.com>
david
[-- Attachment #2: vnc-enable-keepalives.patch --]
[-- Type: text/plain, Size: 1778 bytes --]
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);
}
}
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] PATCH: enabling TCP keepalives on VNC connections
@ 2009-04-22 1:48 David Ahern
0 siblings, 0 replies; 7+ messages in thread
From: David Ahern @ 2009-04-22 1:48 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 311 bytes --]
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 <dsahern@gmail.com>
david
[-- Attachment #2: vnc-enable-keepalives.patch --]
[-- Type: text/plain, Size: 1778 bytes --]
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);
}
}
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] PATCH: enabling TCP keepalives on VNC connections
@ 2009-04-22 2:17 David S. Ahern
2009-04-22 18:26 ` Anthony Liguori
0 siblings, 1 reply; 7+ messages in thread
From: David S. Ahern @ 2009-04-22 2:17 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 396 bytes --]
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 <dsahern@gmail.com>
david
[-- Attachment #2: vnc-enable-keepalives.patch --]
[-- Type: text/plain, Size: 1778 bytes --]
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);
}
}
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] PATCH: enabling TCP keepalives on VNC connections
2009-04-22 2:17 David S. Ahern
@ 2009-04-22 18:26 ` Anthony Liguori
2009-04-22 21:22 ` David S. Ahern
0 siblings, 1 reply; 7+ messages in thread
From: Anthony Liguori @ 2009-04-22 18:26 UTC (permalink / raw)
To: David S. Ahern; +Cc: qemu-devel
David S. Ahern wrote:
> 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 <dsahern@gmail.com>
>
>
> 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
>
Should probe in configure and make an appropriate CONFIG_. This is not
necessarily a linux specific feature.
> #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");
> + }
>
If we want to enable keep alive universally, wouldn't we also want it on
the tcp: character devices?
--
Regards,
Anthony Liguori
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] PATCH: enabling TCP keepalives on VNC connections
2009-04-22 18:26 ` Anthony Liguori
@ 2009-04-22 21:22 ` David S. Ahern
0 siblings, 0 replies; 7+ messages in thread
From: David S. Ahern @ 2009-04-22 21:22 UTC (permalink / raw)
To: Anthony Liguori; +Cc: qemu-devel
Anthony Liguori wrote:
> David S. Ahern wrote:
>> 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 <dsahern@gmail.com>
>>
>>
>> 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
>>
>
> Should probe in configure and make an appropriate CONFIG_. This is not
> necessarily a linux specific feature.
ok. I can only test on linux and mac os x; I do not have a means for
building on windows.
>
>> #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");
>> + }
>>
>
> If we want to enable keep alive universally, wouldn't we also want it on
> the tcp: character devices?
>
Ok. I can make a generic library call that takes the timers as input
options. If the timer is 0 means leave at OS default. What about other
accept() callers - e.g.,gdbstub?
I'll take a look at this end of next week after my vacation around this
weekend.
david
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-04-22 21:22 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-21 19:21 [Qemu-devel] PATCH: enabling TCP keepalives on VNC connections David Ahern
2009-04-21 20:06 David Ahern
2009-04-22 1:46 David Ahern
2009-04-22 1:48 David Ahern
2009-04-22 2:17 David S. Ahern
2009-04-22 18:26 ` Anthony Liguori
2009-04-22 21:22 ` David S. Ahern
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.