@@ -370,34 +370,38 @@ def _proxy(self):
370
370
r , w , _ = select .select (rlist , wlist , [])
371
371
for sock in r :
372
372
if sock == self .websocket :
373
- opcode , frame = self .websocket .recv_data_frame (True )
374
- if opcode == ABNF .OPCODE_BINARY :
375
- if not frame .data :
376
- raise RuntimeError ("Unexpected frame data size" )
377
- channel = six .byte2int (frame .data )
378
- if channel >= len (channel_ports ):
379
- raise RuntimeError ("Unexpected channel number: %s" % channel )
380
- port = channel_ports [channel ]
381
- if channel_initialized [channel ]:
382
- if channel % 2 :
383
- if port .error is None :
384
- port .error = ''
385
- port .error += frame .data [1 :].decode ()
373
+ pending = True
374
+ while pending :
375
+ opcode , frame = self .websocket .recv_data_frame (True )
376
+ if opcode == ABNF .OPCODE_BINARY :
377
+ if not frame .data :
378
+ raise RuntimeError ("Unexpected frame data size" )
379
+ channel = six .byte2int (frame .data )
380
+ if channel >= len (channel_ports ):
381
+ raise RuntimeError ("Unexpected channel number: %s" % channel )
382
+ port = channel_ports [channel ]
383
+ if channel_initialized [channel ]:
384
+ if channel % 2 :
385
+ if port .error is None :
386
+ port .error = ''
387
+ port .error += frame .data [1 :].decode ()
388
+ else :
389
+ port .data += frame .data [1 :]
386
390
else :
387
- port .data += frame . data [ 1 :]
388
- else :
389
- if len ( frame . data ) != 3 :
390
- raise RuntimeError (
391
- "Unexpected initial channel frame data size"
392
- )
393
- port_number = six . byte2int ( frame . data [ 1 : 2 ]) + ( six . byte2int ( frame . data [ 2 : 3 ]) * 256 )
394
- if port_number != port . port_number :
395
- raise RuntimeError (
396
- "Unexpected port number in initial channel frame: %s" % port_number
397
- )
398
- channel_initialized [ channel ] = True
399
- elif opcode not in ( ABNF . OPCODE_PING , ABNF . OPCODE_PONG , ABNF . OPCODE_CLOSE ):
400
- raise RuntimeError ( "Unexpected websocket opcode: %s" % opcode )
391
+ if len ( frame .data ) != 3 :
392
+ raise RuntimeError (
393
+ "Unexpected initial channel frame data size"
394
+ )
395
+ port_number = six . byte2int ( frame . data [ 1 : 2 ]) + ( six . byte2int ( frame . data [ 2 : 3 ]) * 256 )
396
+ if port_number != port . port_number :
397
+ raise RuntimeError (
398
+ "Unexpected port number in initial channel frame: %s" % port_number
399
+ )
400
+ channel_initialized [ channel ] = True
401
+ elif opcode not in ( ABNF . OPCODE_PING , ABNF . OPCODE_PONG , ABNF . OPCODE_CLOSE ):
402
+ raise RuntimeError ( "Unexpected websocket opcode: %s" % opcode )
403
+ if not isinstance ( self . websocket . sock , ssl . SSLSocket ) or not self . websocket . sock . pending ( ):
404
+ pending = False
401
405
else :
402
406
port = local_ports [sock ]
403
407
data = port .python .recv (1024 * 1024 )
0 commit comments