about summary refs log tree commit diff
path: root/src/socks.py
diff options
context:
space:
mode:
authorUltraQbik <no1skill@yandex.ru>2024-08-22 04:45:39 +0300
committerUltraQbik <no1skill@yandex.ru>2024-08-22 04:45:39 +0300
commit9a539001f3f1e77a6ea8332f659695d7ddcedb2f (patch)
treeb26ba03bda05a5584f384e18317d380cffcbf178 /src/socks.py
parent4f741ce90cd857aba53de06047b9221fa27b0c61 (diff)
downloadhttpy-9a539001f3f1e77a6ea8332f659695d7ddcedb2f.tar.gz
httpy-9a539001f3f1e77a6ea8332f659695d7ddcedb2f.zip
Massive refactoring addition of API
Diffstat (limited to 'src/socks.py')
-rw-r--r--src/socks.py20
1 files changed, 20 insertions, 0 deletions
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)