Skip to content

Commit fc010ee

Browse files
committed
Support reading more than 64KB
1 parent 4601fbf commit fc010ee

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

pymongo/network_layer.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,17 @@ async def async_receive_data_socket(
297297

298298

299299
async def _async_receive_stream(reader: asyncio.StreamReader, length: int) -> memoryview:
300-
bytes = await reader.read(length)
301-
if len(bytes) == 0:
302-
raise OSError("connection closed")
303-
return memoryview(bytes)
300+
mv = bytearray(length)
301+
total_read = 0
302+
303+
while total_read < length:
304+
bytes = await reader.read(length)
305+
chunk_length = len(bytes)
306+
if chunk_length == 0:
307+
raise OSError("connection closed")
308+
mv[total_read:] = bytes
309+
total_read += chunk_length
310+
return memoryview(mv)
304311

305312
def receive_data(conn: Connection, length: int, deadline: Optional[float]) -> memoryview:
306313
buf = bytearray(length)

0 commit comments

Comments
 (0)