@@ -126,10 +126,10 @@ def handle_write(self):
126
126
if self .will_close :
127
127
self .handle_close ()
128
128
129
- def _flush_exception (self , flush ):
129
+ def _flush_exception (self , flush , do_close = True ):
130
130
if flush :
131
131
try :
132
- return (flush (), False )
132
+ return (flush (do_close = do_close ), False )
133
133
except OSError :
134
134
if self .adj .log_socket_errors :
135
135
self .logger .exception ("Socket error" )
@@ -240,20 +240,20 @@ def received(self, data):
240
240
241
241
return True
242
242
243
- def _flush_some_if_lockable (self ):
243
+ def _flush_some_if_lockable (self , do_close = True ):
244
244
# Since our task may be appending to the outbuf, we try to acquire
245
245
# the lock, but we don't block if we can't.
246
246
247
247
if self .outbuf_lock .acquire (False ):
248
248
try :
249
- self ._flush_some ()
249
+ self ._flush_some (do_close = do_close )
250
250
251
251
if self .total_outbufs_len < self .adj .outbuf_high_watermark :
252
252
self .outbuf_lock .notify ()
253
253
finally :
254
254
self .outbuf_lock .release ()
255
255
256
- def _flush_some (self ):
256
+ def _flush_some (self , do_close = True ):
257
257
# Send as much data as possible to our client
258
258
259
259
sent = 0
@@ -267,7 +267,7 @@ def _flush_some(self):
267
267
268
268
while outbuflen > 0 :
269
269
chunk = outbuf .get (self .sendbuf_len )
270
- num_sent = self .send (chunk )
270
+ num_sent = self .send (chunk , do_close = do_close )
271
271
272
272
if num_sent :
273
273
outbuf .skip (num_sent , True )
@@ -374,7 +374,9 @@ def write_soon(self, data):
374
374
self .total_outbufs_len += num_bytes
375
375
376
376
if self .total_outbufs_len >= self .adj .send_bytes :
377
- (flushed , exception ) = self ._flush_exception (self ._flush_some )
377
+ (flushed , exception ) = self ._flush_exception (
378
+ self ._flush_some , do_close = False
379
+ )
378
380
379
381
if (
380
382
exception
@@ -392,7 +394,7 @@ def _flush_outbufs_below_high_watermark(self):
392
394
393
395
if self .total_outbufs_len > self .adj .outbuf_high_watermark :
394
396
with self .outbuf_lock :
395
- (_ , exception ) = self ._flush_exception (self ._flush_some )
397
+ (_ , exception ) = self ._flush_exception (self ._flush_some , do_close = False )
396
398
397
399
if exception :
398
400
# An exception happened while flushing, wake up the main
0 commit comments