Skip to content

Commit

Permalink
#2420 add more specific keepalive options (per OS)
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@27682 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Oct 16, 2020
1 parent c206a42 commit b493af6
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/xpra/net/bytestreams.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file is part of Xpra.
# Copyright (C) 2011-2019 Antoine Martin <[email protected]>
# Copyright (C) 2011-2020 Antoine Martin <[email protected]>
# Copyright (C) 2008, 2009, 2010 Nathaniel Smith <[email protected]>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.
Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b493af6

Please sign in to comment.