fix: 修复代理问题

This commit is contained in:
丹尼尔
2026-03-15 17:16:05 +08:00
parent 8b62c445fc
commit 15c9e1772a
100 changed files with 6157 additions and 69 deletions

View File

@@ -0,0 +1,32 @@
import socket
from .._errors import ProxyError
from .. import _abc as abc
DEFAULT_RECEIVE_SIZE = 65536
class SyncSocketStream(abc.SyncSocketStream):
_socket: socket.socket
def __init__(self, sock: socket.socket):
self._socket = sock
def write_all(self, data):
self._socket.sendall(data)
def read(self, max_bytes=DEFAULT_RECEIVE_SIZE):
return self._socket.recv(max_bytes)
def read_exact(self, n):
data = bytearray()
while len(data) < n:
packet = self._socket.recv(n - len(data))
if not packet: # pragma: no cover
raise ProxyError('Connection closed unexpectedly')
data += packet
return data
def close(self):
if self._socket is not None:
self._socket.close()