@@ -389,23 +389,33 @@ def _recv(self, size, read=_read):
389389
390390 def _send_bytes (self , buf ):
391391 n = len (buf )
392- # For wire compatibility with 3.2 and lower
393- header = struct .pack ("!i" , n )
394- if n > 16384 :
395- # The payload is large so Nagle's algorithm won't be triggered
396- # and we'd better avoid the cost of concatenation.
392+ if n > 0x7fffffff :
393+ pre_header = struct .pack ("!i" , - 1 )
394+ header = struct .pack ("!Q" , n )
395+ self ._send (pre_header )
397396 self ._send (header )
398397 self ._send (buf )
399398 else :
400- # Issue #20540: concatenate before sending, to avoid delays due
401- # to Nagle's algorithm on a TCP socket.
402- # Also note we want to avoid sending a 0-length buffer separately,
403- # to avoid "broken pipe" errors if the other end closed the pipe.
404- self ._send (header + buf )
399+ # For wire compatibility with 3.7 and lower
400+ header = struct .pack ("!i" , n )
401+ if n > 16384 :
402+ # The payload is large so Nagle's algorithm won't be triggered
403+ # and we'd better avoid the cost of concatenation.
404+ self ._send (header )
405+ self ._send (buf )
406+ else :
407+ # Issue #20540: concatenate before sending, to avoid delays due
408+ # to Nagle's algorithm on a TCP socket.
409+ # Also note we want to avoid sending a 0-length buffer separately,
410+ # to avoid "broken pipe" errors if the other end closed the pipe.
411+ self ._send (header + buf )
405412
406413 def _recv_bytes (self , maxsize = None ):
407414 buf = self ._recv (4 )
408415 size , = struct .unpack ("!i" , buf .getvalue ())
416+ if size == - 1 :
417+ buf = self ._recv (8 )
418+ size , = struct .unpack ("!Q" , buf .getvalue ())
409419 if maxsize is not None and size > maxsize :
410420 return None
411421 return self ._recv (size )
0 commit comments