about summary refs log tree commit diff
path: root/src/socks.py
blob: 119a62a33e4fdf8af2a6bad203cf0789e6b1a386 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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)