diff options
author | Zac Medico <zmedico@gentoo.org> | 2024-02-21 18:58:07 -0800 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2024-02-21 23:28:38 -0800 |
commit | f76452e0760653482afbd4144d60332d4284b67d (patch) | |
tree | 556dd17a00fd7b866a59741f3279166dc127e8e7 /bin | |
parent | NEWS, meson.build: prepare for portage-3.0.62 (diff) | |
download | portage-f76452e0760653482afbd4144d60332d4284b67d.tar.gz portage-f76452e0760653482afbd4144d60332d4284b67d.tar.bz2 portage-f76452e0760653482afbd4144d60332d4284b67d.zip |
bin/socks5-server.py: Migrate to asyncio.run()
Signed-off-by: Zac Medico <zmedico@gentoo.org>
Diffstat (limited to 'bin')
-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])) |