summaryrefslogtreecommitdiff
path: root/kvmd/apps/vnc/server.py
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-03-20 04:47:21 +0300
committerDevaev Maxim <[email protected]>2020-03-20 11:39:22 +0300
commit8164594b920c6b0c5bc7554621c20165298e3d57 (patch)
treef24b19fad5eddb682a1ba3dc8fe3847d58deda06 /kvmd/apps/vnc/server.py
parent0ac8b0c3e478b24b689025bd52de93bf20357c9f (diff)
minor vnc fixes
Diffstat (limited to 'kvmd/apps/vnc/server.py')
-rw-r--r--kvmd/apps/vnc/server.py47
1 files changed, 24 insertions, 23 deletions
diff --git a/kvmd/apps/vnc/server.py b/kvmd/apps/vnc/server.py
index d9225f3b..adf6f32d 100644
--- a/kvmd/apps/vnc/server.py
+++ b/kvmd/apps/vnc/server.py
@@ -24,6 +24,7 @@ import asyncio
import asyncio.queues
import socket
import dataclasses
+import contextlib
import json
from typing import Dict
@@ -281,31 +282,31 @@ class VncServer:
logger = get_logger(0)
logger.info("Listening VNC on TCP [%s]:%d ...", self.__host, self.__port)
- sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
- sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, False)
- sock.bind((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.bind((self.__host, self.__port))
- loop = asyncio.get_event_loop()
- server = loop.run_until_complete(asyncio.start_server(
- client_connected_cb=self.__handle_client,
- sock=sock,
- backlog=self.__max_clients,
- loop=loop,
- ))
+ loop = asyncio.get_event_loop()
+ server = loop.run_until_complete(asyncio.start_server(
+ client_connected_cb=self.__handle_client,
+ sock=sock,
+ backlog=self.__max_clients,
+ loop=loop,
+ ))
- try:
- loop.run_forever()
- except (SystemExit, KeyboardInterrupt):
- pass
- finally:
- server.close()
- loop.run_until_complete(server.wait_closed())
- tasks = asyncio.Task.all_tasks()
- for task in tasks:
- task.cancel()
- loop.run_until_complete(asyncio.gather(*tasks, return_exceptions=True))
- loop.close()
- logger.info("Bye-bye")
+ try:
+ loop.run_forever()
+ except (SystemExit, KeyboardInterrupt):
+ pass
+ finally:
+ server.close()
+ loop.run_until_complete(server.wait_closed())
+ tasks = asyncio.Task.all_tasks()
+ for task in tasks:
+ task.cancel()
+ loop.run_until_complete(asyncio.gather(*tasks, return_exceptions=True))
+ loop.close()
+ logger.info("Bye-bye")
async def __handle_client(self, reader: asyncio.StreamReader, writer: asyncio.StreamWriter) -> None:
await _Client(reader, writer, self.__kvmd, self.__streamer, self.__symmap, self.__shared_params).run()