Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions curl_cffi/requests/websockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,29 +718,30 @@ async def send(
"Invalid active socket", CurlECode.NO_CONNECTION_AVAILABLE
)

# Loop checks for CurlECode.Again
# https://curl.se/libcurl/c/curl_ws_send.html
offset = 0
while offset < len(payload):
current_buffer = payload[offset:]
# TODO: Why does concurrently sending fail
async with self._send_lock:
offset = 0

try:
# TODO: Why does concurrently sending fail
async with self._send_lock:
# Loop checks for CurlECode.Again
# https://curl.se/libcurl/c/curl_ws_send.html
while offset < len(payload):
current_buffer = payload[offset:]

try:
n_sent = await self.loop.run_in_executor(
None, self.curl.ws_send, current_buffer, flags
)
except CurlError as e:
if e.code == CurlECode.AGAIN:
writeable = await aselect(
sock_fd, mode="write", loop=self.loop, timeout=0.5
)
if not writeable:
raise WebSocketError("Socket write timeout") from e
continue
raise
except CurlError as e:
if e.code == CurlECode.AGAIN:
writeable = await aselect(
sock_fd, mode="write", loop=self.loop, timeout=0.5
)
if not writeable:
raise WebSocketError("Socket write timeout") from e
continue
raise

offset += n_sent
offset += n_sent

return offset

Expand Down
Loading