summaryrefslogtreecommitdiff
path: root/kvmd/apps/vnc
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-07-23 10:38:45 +0300
committerDevaev Maxim <[email protected]>2020-07-23 10:38:45 +0300
commitd338bf219c22020e6791a30e210299138d45926c (patch)
tree312818c6162095890200a35aef4a4a43e3a4a4e3 /kvmd/apps/vnc
parent37c2f9391c4129114702f653270049d0ad67bc90 (diff)
tune vnc socket
Diffstat (limited to 'kvmd/apps/vnc')
-rw-r--r--kvmd/apps/vnc/__init__.py4
-rw-r--r--kvmd/apps/vnc/server.py25
2 files changed, 26 insertions, 3 deletions
diff --git a/kvmd/apps/vnc/__init__.py b/kvmd/apps/vnc/__init__.py
index aaf67740..923ac39a 100644
--- a/kvmd/apps/vnc/__init__.py
+++ b/kvmd/apps/vnc/__init__.py
@@ -50,6 +50,8 @@ def main(argv: Optional[List[str]]=None) -> None:
port=config.server.port,
max_clients=config.server.max_clients,
+ no_delay=config.server.no_delay,
+
tls_ciphers=config.server.tls.ciphers,
tls_timeout=config.server.tls.timeout,
@@ -65,4 +67,6 @@ def main(argv: Optional[List[str]]=None) -> None:
**config.streamer._unpack(),
),
vnc_auth_manager=VncAuthManager(**config.auth.vncauth._unpack()),
+
+ **config.server.keepalive._unpack(),
).run()
diff --git a/kvmd/apps/vnc/server.py b/kvmd/apps/vnc/server.py
index 73c9c148..55ff4e7c 100644
--- a/kvmd/apps/vnc/server.py
+++ b/kvmd/apps/vnc/server.py
@@ -285,12 +285,18 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes
# =====
class VncServer: # pylint: disable=too-many-instance-attributes
- def __init__( # pylint: disable=too-many-arguments
+ def __init__( # pylint: disable=too-many-arguments,too-many-locals
self,
host: str,
port: int,
max_clients: int,
+ no_delay: bool,
+ keepalive_enabled: bool,
+ keepalive_idle: int,
+ keepalive_interval: int,
+ keepalive_count: int,
+
tls_ciphers: str,
tls_timeout: float,
@@ -318,6 +324,19 @@ class VncServer: # pylint: disable=too-many-instance-attributes
remote = rfb_format_remote(writer)
logger.info("[entry] [%s]: Connected client", remote)
try:
+ sock = writer.get_extra_info("socket")
+ if no_delay:
+ sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
+ if keepalive_enabled:
+ # https://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/#setsockopt
+ # https://blog.cloudflare.com/when-tcp-sockets-refuse-to-die
+ sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
+ sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, keepalive_idle)
+ sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, keepalive_interval)
+ sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, keepalive_count)
+ timeout = (keepalive_idle + keepalive_interval * keepalive_count) * 1000 # Milliseconds
+ sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_USER_TIMEOUT, timeout)
+
try:
async with kvmd.make_session("", "") as kvmd_session:
none_auth_only = await kvmd_session.auth.check()
@@ -357,8 +376,8 @@ class VncServer: # pylint: disable=too-many-instance-attributes
logger.info("Listening VNC on TCP [%s]:%d ...", self.__host, self.__port)
with contextlib.closing(socket.socket(socket.AF_INET6, socket.SOCK_STREAM)) as sock:
- sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, False)
- sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
+ sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
+ sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind((self.__host, self.__port))
server = loop.run_until_complete(asyncio.start_server(