This commit is contained in:
jeremygan2021
2026-03-03 22:11:26 +08:00
parent fc92a5feaf
commit 700bc55657
7 changed files with 138 additions and 124 deletions

View File

@@ -147,10 +147,13 @@ class WebSocketClient:
# Read payload
data = bytearray(length)
view = memoryview(data)
# Use smaller chunks for readinto to avoid memory allocation issues in MicroPython
pos = 0
while pos < length:
read_len = self.sock.readinto(view[pos:])
chunk_size = min(length - pos, 512)
chunk_view = memoryview(data)[pos:pos + chunk_size]
read_len = self.sock.readinto(chunk_view)
if read_len == 0:
return None
pos += read_len