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:
Jamie Phan 2024-02-17 13:38:07 +11:00 committed by GitHub
parent 8db8d7118e
commit 73e8637002
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 50 additions and 16 deletions

View file

@ -1280,11 +1280,10 @@ class SelectorDatagramTransportTests(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)
transport.sendto(b'', ('0.0.0.0', 1234))
self.assertTrue(self.sock.sendto.called)
self.assertEqual(
[(b'data', ('0.0.0.0', 12345))], list(transport._buffer))
self.sock.sendto.call_args[0], (b'', ('0.0.0.0', 1234)))
def test_sendto_buffer(self):
transport = self.datagram_transport()
@ -1320,6 +1319,18 @@ class SelectorDatagramTransportTests(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.sendto(data2, ('0.0.0.0', 12345))
self.assertFalse(self.sock.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)
def test_sendto_tryagain(self):
data = b'data'