@@ -227,9 +227,11 @@ async def serve(rd, wr):
227
227
(c_rd , c_wr ) = await asyncio .open_connection (addr [0 ], addr [1 ], limit = 4096 )
228
228
self .addCleanup (c_wr .close )
229
229
230
- # Limit the send buffer so we can reliably overfill it
230
+ # Limit the socket buffers so we can reliably overfill them
231
231
s_sock = s_wr .get_extra_info ('socket' )
232
232
s_sock .setsockopt (socket .SOL_SOCKET , socket .SO_SNDBUF , 65536 )
233
+ c_sock = c_wr .get_extra_info ('socket' )
234
+ c_sock .setsockopt (socket .SOL_SOCKET , socket .SO_RCVBUF , 65536 )
233
235
234
236
# Get the reader in to a paused state by sending more than twice
235
237
# the configured limit
@@ -240,10 +242,11 @@ async def serve(rd, wr):
240
242
await asyncio .sleep (0 )
241
243
242
244
# Get the writer in a waiting state by sending data until the
243
- # kernel stops accepting more in to the send buffer
244
- while s_wr .transport .get_write_buffer_size () == 0 :
245
- s_wr .write (b'a' * 4096 )
246
- await asyncio .sleep (0 )
245
+ # socket buffers are full on both server and client sockets and
246
+ # the kernel stops accepting more data
247
+ s_wr .write (b'a' * c_sock .getsockopt (socket .SOL_SOCKET , socket .SO_RCVBUF ))
248
+ s_wr .write (b'a' * s_sock .getsockopt (socket .SOL_SOCKET , socket .SO_SNDBUF ))
249
+ self .assertNotEqual (s_wr .transport .get_write_buffer_size (), 0 )
247
250
248
251
task = asyncio .create_task (srv .wait_closed ())
249
252
await asyncio .sleep (0 )
0 commit comments