mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-113812: Allow DatagramTransport.sendto to send empty data (#115199)
Also include the UDP packet header sizes (8 bytes per packet) in the buffer size reported to the flow control subsystem.
This commit is contained in:
parent
8db8d7118e
commit
73e8637002
8 changed files with 50 additions and 16 deletions
|
@ -487,9 +487,6 @@ class _ProactorDatagramTransport(_ProactorBasePipeTransport,
|
|||
raise TypeError('data argument must be bytes-like object (%r)',
|
||||
type(data))
|
||||
|
||||
if not data:
|
||||
return
|
||||
|
||||
if self._address is not None and addr not in (None, self._address):
|
||||
raise ValueError(
|
||||
f'Invalid address: must be None or {self._address}')
|
||||
|
@ -502,7 +499,7 @@ class _ProactorDatagramTransport(_ProactorBasePipeTransport,
|
|||
|
||||
# Ensure that what we buffer is immutable.
|
||||
self._buffer.append((bytes(data), addr))
|
||||
self._buffer_size += len(data)
|
||||
self._buffer_size += len(data) + 8 # include header bytes
|
||||
|
||||
if self._write_fut is None:
|
||||
# No current write operations are active, kick one off
|
||||
|
|
|
@ -1241,8 +1241,6 @@ class _SelectorDatagramTransport(_SelectorTransport, transports.DatagramTranspor
|
|||
if not isinstance(data, (bytes, bytearray, memoryview)):
|
||||
raise TypeError(f'data argument must be a bytes-like object, '
|
||||
f'not {type(data).__name__!r}')
|
||||
if not data:
|
||||
return
|
||||
|
||||
if self._address:
|
||||
if addr not in (None, self._address):
|
||||
|
@ -1278,7 +1276,7 @@ class _SelectorDatagramTransport(_SelectorTransport, transports.DatagramTranspor
|
|||
|
||||
# Ensure that what we buffer is immutable.
|
||||
self._buffer.append((bytes(data), addr))
|
||||
self._buffer_size += len(data)
|
||||
self._buffer_size += len(data) + 8 # include header bytes
|
||||
self._maybe_pause_protocol()
|
||||
|
||||
def _sendto_ready(self):
|
||||
|
|
|
@ -181,6 +181,8 @@ class DatagramTransport(BaseTransport):
|
|||
to be sent out asynchronously.
|
||||
addr is target socket address.
|
||||
If addr is None use target address pointed on transport creation.
|
||||
If data is an empty bytes object a zero-length datagram will be
|
||||
sent.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue