mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-17560: Too small type for struct.pack/unpack in mutliprocessing.Connection (GH-10305)
Allow sending more than 2 GB at once on a multiprocessing connection on non-Windows systems.
This commit is contained in:
parent
75d9d59ab3
commit
bccacd19fa
2 changed files with 21 additions and 10 deletions
|
@ -389,23 +389,33 @@ class Connection(_ConnectionBase):
|
||||||
|
|
||||||
def _send_bytes(self, buf):
|
def _send_bytes(self, buf):
|
||||||
n = len(buf)
|
n = len(buf)
|
||||||
# For wire compatibility with 3.2 and lower
|
if n > 0x7fffffff:
|
||||||
header = struct.pack("!i", n)
|
pre_header = struct.pack("!i", -1)
|
||||||
if n > 16384:
|
header = struct.pack("!Q", n)
|
||||||
# The payload is large so Nagle's algorithm won't be triggered
|
self._send(pre_header)
|
||||||
# and we'd better avoid the cost of concatenation.
|
|
||||||
self._send(header)
|
self._send(header)
|
||||||
self._send(buf)
|
self._send(buf)
|
||||||
else:
|
else:
|
||||||
# Issue #20540: concatenate before sending, to avoid delays due
|
# For wire compatibility with 3.7 and lower
|
||||||
# to Nagle's algorithm on a TCP socket.
|
header = struct.pack("!i", n)
|
||||||
# Also note we want to avoid sending a 0-length buffer separately,
|
if n > 16384:
|
||||||
# to avoid "broken pipe" errors if the other end closed the pipe.
|
# The payload is large so Nagle's algorithm won't be triggered
|
||||||
self._send(header + buf)
|
# and we'd better avoid the cost of concatenation.
|
||||||
|
self._send(header)
|
||||||
|
self._send(buf)
|
||||||
|
else:
|
||||||
|
# Issue #20540: concatenate before sending, to avoid delays due
|
||||||
|
# to Nagle's algorithm on a TCP socket.
|
||||||
|
# Also note we want to avoid sending a 0-length buffer separately,
|
||||||
|
# to avoid "broken pipe" errors if the other end closed the pipe.
|
||||||
|
self._send(header + buf)
|
||||||
|
|
||||||
def _recv_bytes(self, maxsize=None):
|
def _recv_bytes(self, maxsize=None):
|
||||||
buf = self._recv(4)
|
buf = self._recv(4)
|
||||||
size, = struct.unpack("!i", buf.getvalue())
|
size, = struct.unpack("!i", buf.getvalue())
|
||||||
|
if size == -1:
|
||||||
|
buf = self._recv(8)
|
||||||
|
size, = struct.unpack("!Q", buf.getvalue())
|
||||||
if maxsize is not None and size > maxsize:
|
if maxsize is not None and size > maxsize:
|
||||||
return None
|
return None
|
||||||
return self._recv(size)
|
return self._recv(size)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Allow sending more than 2 GB at once on a multiprocessing connection on non-Windows systems.
|
Loading…
Add table
Add a link
Reference in a new issue