commit: f76452e0760653482afbd4144d60332d4284b67d
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Thu Feb 22 02:58:07 2024 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Thu Feb 22 07:28:38 2024 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=f76452e0
bin/socks5-server.py: Migrate to asyncio.run()
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
bin/socks5-server.py | 34 ++++++++++++++--------------------
1 file changed, 14 insertions(+), 20 deletions(-)
diff --git a/bin/socks5-server.py b/bin/socks5-server.py
index e898835ffa..640c89d5a8 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]))