diff options
Diffstat (limited to 'bin/socks5-server.py')
-rw-r--r-- | bin/socks5-server.py | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/bin/socks5-server.py b/bin/socks5-server.py index e898835ff..640c89d5a 100644 --- a/bin/socks5-server.py +++ b/bin/socks5-server.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # SOCKSv5 proxy server for network-sandbox -# Copyright 2015-2022 Gentoo Authors +# Copyright 2015-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 import asyncio @@ -218,27 +218,21 @@ class Socks5Server: return -if __name__ == "__main__": - if len(sys.argv) != 2: - print(f"Usage: {sys.argv[0]} <socket-path>") - sys.exit(1) - - loop = asyncio.new_event_loop() +async def run_socks5_server(socket_path): s = Socks5Server() - server = loop.run_until_complete( - asyncio.start_unix_server(s.handle_proxy_conn, sys.argv[1]) - ) + server = await asyncio.start_unix_server(s.handle_proxy_conn, socket_path) - ret = 0 try: - try: - loop.run_forever() - except KeyboardInterrupt: - pass - except: - ret = 1 + await asyncio.get_running_loop().create_future() finally: server.close() - loop.run_until_complete(server.wait_closed()) - loop.close() - os.unlink(sys.argv[1]) + await server.wait_closed() + os.unlink(socket_path) + + +if __name__ == "__main__": + if len(sys.argv) != 2: + print(f"Usage: {sys.argv[0]} <socket-path>") + sys.exit(1) + + asyncio.run(run_socks5_server(sys.argv[1])) |