From 9a539001f3f1e77a6ea8332f659695d7ddcedb2f Mon Sep 17 00:00:00 2001 From: UltraQbik Date: Thu, 22 Aug 2024 04:45:39 +0300 Subject: Massive refactoring addition of API --- src/socks.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/socks.py (limited to 'src/socks.py') diff --git a/src/socks.py b/src/socks.py new file mode 100644 index 0000000..119a62a --- /dev/null +++ b/src/socks.py @@ -0,0 +1,20 @@ +import time +from ssl import SSLSocket + + +async def ssl_sock_accept(sock: SSLSocket) -> tuple[SSLSocket, str]: + while True: + try: + return sock.accept() + except BlockingIOError: + time.sleep(1.e-3) + + +async def ssl_sock_recv(sock: SSLSocket, buflen: int = 1024): + while (msg := sock.recv(buflen)) == b'': + time.sleep(1.e-3) + return msg + + +async def ssl_sock_sendall(sock: SSLSocket, data: bytes): + sock.sendall(data) -- cgit 1.4.1