From b493af6bf262ab0694f4065e59d7f15036e33d5d Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Fri, 16 Oct 2020 16:19:08 +0000 Subject: [PATCH] #2420 add more specific keepalive options (per OS) git-svn-id: https://xpra.org/svn/Xpra/trunk@27682 3bb7dfac-3a0b-4e04-842a-767bc560f471 --- src/xpra/net/bytestreams.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/xpra/net/bytestreams.py b/src/xpra/net/bytestreams.py index e1154a5be1..94a55a7738 100644 --- a/src/xpra/net/bytestreams.py +++ b/src/xpra/net/bytestreams.py @@ -1,5 +1,5 @@ # This file is part of Xpra. -# Copyright (C) 2011-2019 Antoine Martin +# Copyright (C) 2011-2020 Antoine Martin # Copyright (C) 2008, 2009, 2010 Nathaniel Smith # Xpra is released under the terms of the GNU GPL v2, or, at your option, any # later version. See the file COPYING for details. @@ -11,7 +11,7 @@ from xpra.net.common import ConnectionClosedException from xpra.util import envint, envbool, csv -from xpra.os_util import POSIX, LINUX +from xpra.os_util import POSIX, LINUX, WIN32, OSX from xpra.platform.features import TCP_OPTIONS, IP_OPTIONS, SOCKET_OPTIONS from xpra.log import Logger @@ -266,6 +266,19 @@ def boolget(k, default_value): keepalive = boolget("keepalive", SOCKET_KEEPALIVE) try: self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, int(keepalive)) + if keepalive: + idletime = 10 + interval = 3 + kmax = 5 + if WIN32: + sock.ioctl(socket.SIO_KEEPALIVE_VALS, (1, idletime*1000, interval*1000)) #@UndefinedVariable pylint: disable=no-member + elif OSX: + TCP_KEEPALIVE = 0x10 + sock.setsockopt(socket.IPPROTO_TCP, TCP_KEEPALIVE, interval) + elif LINUX: + sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, idletime) + sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, interval) + sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, kmax) except OSError: log("cannot set KEEPALIVE", exc_info=True) else: