mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +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
|
@ -585,11 +585,10 @@ class ProactorDatagramTransportTests(test_utils.TestCase):
|
|||
|
||||
def test_sendto_no_data(self):
|
||||
transport = self.datagram_transport()
|
||||
transport._buffer.append((b'data', ('0.0.0.0', 12345)))
|
||||
transport.sendto(b'', ())
|
||||
self.assertFalse(self.sock.sendto.called)
|
||||
self.assertEqual(
|
||||
[(b'data', ('0.0.0.0', 12345))], list(transport._buffer))
|
||||
transport.sendto(b'', ('0.0.0.0', 1234))
|
||||
self.assertTrue(self.proactor.sendto.called)
|
||||
self.proactor.sendto.assert_called_with(
|
||||
self.sock, b'', addr=('0.0.0.0', 1234))
|
||||
|
||||
def test_sendto_buffer(self):
|
||||
transport = self.datagram_transport()
|
||||
|
@ -628,6 +627,19 @@ class ProactorDatagramTransportTests(test_utils.TestCase):
|
|||
list(transport._buffer))
|
||||
self.assertIsInstance(transport._buffer[1][0], bytes)
|
||||
|
||||
def test_sendto_buffer_nodata(self):
|
||||
data2 = b''
|
||||
transport = self.datagram_transport()
|
||||
transport._buffer.append((b'data1', ('0.0.0.0', 12345)))
|
||||
transport._write_fut = object()
|
||||
transport.sendto(data2, ('0.0.0.0', 12345))
|
||||
self.assertFalse(self.proactor.sendto.called)
|
||||
self.assertEqual(
|
||||
[(b'data1', ('0.0.0.0', 12345)),
|
||||
(b'', ('0.0.0.0', 12345))],
|
||||
list(transport._buffer))
|
||||
self.assertIsInstance(transport._buffer[1][0], bytes)
|
||||
|
||||
@mock.patch('asyncio.proactor_events.logger')
|
||||
def test_sendto_exception(self, m_log):
|
||||
data = b'data'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue