@@ -126,10 +126,10 @@ def handle_write(self):
126126 if self .will_close :
127127 self .handle_close ()
128128
129- def _flush_exception (self , flush ):
129+ def _flush_exception (self , flush , do_close = True ):
130130 if flush :
131131 try :
132- return (flush (), False )
132+ return (flush (do_close = do_close ), False )
133133 except OSError :
134134 if self .adj .log_socket_errors :
135135 self .logger .exception ("Socket error" )
@@ -240,20 +240,20 @@ def received(self, data):
240240
241241 return True
242242
243- def _flush_some_if_lockable (self ):
243+ def _flush_some_if_lockable (self , do_close = True ):
244244 # Since our task may be appending to the outbuf, we try to acquire
245245 # the lock, but we don't block if we can't.
246246
247247 if self .outbuf_lock .acquire (False ):
248248 try :
249- self ._flush_some ()
249+ self ._flush_some (do_close = do_close )
250250
251251 if self .total_outbufs_len < self .adj .outbuf_high_watermark :
252252 self .outbuf_lock .notify ()
253253 finally :
254254 self .outbuf_lock .release ()
255255
256- def _flush_some (self ):
256+ def _flush_some (self , do_close = True ):
257257 # Send as much data as possible to our client
258258
259259 sent = 0
@@ -267,7 +267,7 @@ def _flush_some(self):
267267
268268 while outbuflen > 0 :
269269 chunk = outbuf .get (self .sendbuf_len )
270- num_sent = self .send (chunk )
270+ num_sent = self .send (chunk , do_close = do_close )
271271
272272 if num_sent :
273273 outbuf .skip (num_sent , True )
@@ -374,7 +374,9 @@ def write_soon(self, data):
374374 self .total_outbufs_len += num_bytes
375375
376376 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+ )
378380
379381 if (
380382 exception
@@ -392,7 +394,7 @@ def _flush_outbufs_below_high_watermark(self):
392394
393395 if self .total_outbufs_len > self .adj .outbuf_high_watermark :
394396 with self .outbuf_lock :
395- (_ , exception ) = self ._flush_exception (self ._flush_some )
397+ (_ , exception ) = self ._flush_exception (self ._flush_some , do_close = False )
396398
397399 if exception :
398400 # An exception happened while flushing, wake up the main
0 commit comments