mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.14] gh-135444: fix asyncio.DatagramTransport.sendto to account for datagram header size when data cannot be sent (GH-135445) (#137245)
gh-135444: fix `asyncio.DatagramTransport.sendto` to account for datagram header size when data cannot be sent (GH-135445)
(cherry picked from commit e3ea861351)
Co-authored-by: Justin Bronder <jsbronder@cold-front.org>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
This commit is contained in:
parent
bfcd5f25a5
commit
93ac6f3472
5 changed files with 53 additions and 5 deletions
|
|
@ -460,6 +460,8 @@ def _pipe_closed(self, fut):
|
|||
class _ProactorDatagramTransport(_ProactorBasePipeTransport,
|
||||
transports.DatagramTransport):
|
||||
max_size = 256 * 1024
|
||||
_header_size = 8
|
||||
|
||||
def __init__(self, loop, sock, protocol, address=None,
|
||||
waiter=None, extra=None):
|
||||
self._address = address
|
||||
|
|
@ -499,7 +501,7 @@ def sendto(self, data, addr=None):
|
|||
|
||||
# Ensure that what we buffer is immutable.
|
||||
self._buffer.append((bytes(data), addr))
|
||||
self._buffer_size += len(data) + 8 # include header bytes
|
||||
self._buffer_size += len(data) + self._header_size
|
||||
|
||||
if self._write_fut is None:
|
||||
# No current write operations are active, kick one off
|
||||
|
|
@ -526,7 +528,7 @@ def _loop_writing(self, fut=None):
|
|||
return
|
||||
|
||||
data, addr = self._buffer.popleft()
|
||||
self._buffer_size -= len(data)
|
||||
self._buffer_size -= len(data) + self._header_size
|
||||
if self._address is not None:
|
||||
self._write_fut = self._loop._proactor.send(self._sock,
|
||||
data)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue