Skip to content

Commit 91fcf48

Browse files
author
denis.kashitsyn
committed
Allow server to receive files more than initial receive buffer size
1 parent f1fafb8 commit 91fcf48

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

python/mujinasync/asynctcp.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -364,19 +364,30 @@ def SpinOnce(self, timeout=0):
364364
continue
365365

366366
serverClient, connection = socketConnections[rsocket]
367-
try:
368-
received = rsocket.recv_into(connection.receiveBuffer.writeView)
369-
except Exception as e:
370-
connection.closeType = 'Immediate'
371-
log.exception('error while trying to receive from connection %s: %s', connection, e)
367+
totalReceived = 0
368+
while True:
369+
try:
370+
received = rsocket.recv_into(connection.receiveBuffer.writeView)
371+
if received == 0:
372+
break
373+
connection.receiveBuffer.size += received
374+
totalReceived += received
375+
if connection.receiveBuffer.capacity - connection.receiveBuffer.size < connection.receiveBuffer.capacity:
376+
connection.receiveBuffer.capacity *= 2
377+
except socket.error as e:
378+
if e.errno not in (errno.EAGAIN, errno.EWOULDBLOCK):
379+
connection.closeType = 'Immediate'
380+
log.exception('error while trying to receive from connection %s: %s', connection, e)
381+
break
382+
383+
if connection.closeType == 'Immediate':
372384
continue
373385

374-
if received == 0:
386+
if totalReceived == 0:
375387
connection.closeType = 'AfterSend'
376388
log.debug('received nothing from connection, maybe closed: %s', connection)
377389
continue
378390

379-
connection.receiveBuffer.size += received
380391
receivedConnections.append((serverClient, connection))
381392

382393
# handle sockets that can write

0 commit comments

Comments
 (0)