@@ -166,6 +166,7 @@ async def _basetest_sock_send_racing(self, listener, sock):
166
166
listener .listen (1 )
167
167
168
168
# make connection
169
+ sock .setsockopt (socket .SOL_SOCKET , socket .SO_SNDBUF , 1024 )
169
170
sock .setblocking (False )
170
171
task = asyncio .create_task (
171
172
self .loop .sock_connect (sock , listener .getsockname ()))
@@ -176,30 +177,35 @@ async def _basetest_sock_send_racing(self, listener, sock):
176
177
with server :
177
178
await task
178
179
179
- # fill the buffer
180
- with self .assertRaises (BlockingIOError ):
181
- while True :
182
- sock .send (b' ' * 5 )
180
+ # fill the buffer until sending 5 chars would block
181
+ size = 8192
182
+ while size >= 4 :
183
+ with self .assertRaises (BlockingIOError ):
184
+ while True :
185
+ sock .send (b' ' * size )
186
+ size = int (size / 2 )
183
187
184
188
# cancel a blocked sock_sendall
185
189
task = asyncio .create_task (
186
190
self .loop .sock_sendall (sock , b'hello' ))
187
191
await asyncio .sleep (0 )
188
192
task .cancel ()
189
193
190
- # clear the buffer
191
- async def recv_until ():
192
- data = b''
193
- while not data :
194
- data = await self .loop .sock_recv (server , 1024 )
195
- data = data .strip ()
196
- return data
197
- task = asyncio .create_task (recv_until ())
194
+ # receive everything that is not a space
195
+ async def recv_all ():
196
+ rv = b''
197
+ while True :
198
+ buf = await self .loop .sock_recv (server , 8192 )
199
+ if not buf :
200
+ return rv
201
+ rv += buf .strip ()
202
+ task = asyncio .create_task (recv_all ())
198
203
199
- # immediately register another sock_sendall
204
+ # immediately make another sock_sendall call
200
205
await self .loop .sock_sendall (sock , b'world' )
206
+ sock .shutdown (socket .SHUT_WR )
201
207
data = await task
202
- # ProactorEventLoop could deliver hello
208
+ # ProactorEventLoop could deliver hello, so endswith is necessary
203
209
self .assertTrue (data .endswith (b'world' ))
204
210
205
211
# After the first connect attempt before the listener is ready,
0 commit comments