@@ -424,11 +424,13 @@ cdef class UVStream(UVBaseTransport):
424424 self ._buffer_size += dlen
425425 self ._buffer.append(data)
426426
427- cdef inline _initiate_write(self ):
428- if (not self ._protocol_paused and
429- (< uv.uv_stream_t* > self ._handle).write_queue_size == 0 and
430- self ._buffer_size > self ._high_water):
427+ cdef inline _initiate_write(self , bint skip_fast_path):
428+ if (not skip_fast_path and
429+ not self ._protocol_paused and
430+ (< uv.uv_stream_t* > self ._handle).write_queue_size == 0 and
431+ self ._buffer_size > self ._high_water):
431432 # Fast-path. If:
433+ # - the caller hasn't tried fast path itself
432434 # - the protocol isn't yet paused,
433435 # - there is no data in libuv buffers for this stream,
434436 # - the protocol will be paused if we continue to buffer data
@@ -687,9 +689,7 @@ cdef class UVStream(UVBaseTransport):
687689
688690 cdef ssize_t bytes_written
689691
690- if (not self ._protocol_paused and self ._buffer_size == 0 and
691- (< uv.uv_stream_t* > self ._handle).write_queue_size == 0 ):
692-
692+ if self ._get_write_buffer_size() == 0 :
693693 bytes_written_ = self ._try_write(buf)
694694
695695 if bytes_written_ is None :
@@ -726,7 +726,7 @@ cdef class UVStream(UVBaseTransport):
726726 # buffer remaining data and send it later
727727
728728 self ._buffer_write(buf)
729- self ._initiate_write()
729+ self ._initiate_write(True ) # skip fast path in _initiate_write
730730
731731 def writelines (self , bufs ):
732732 self ._ensure_alive()
@@ -738,7 +738,7 @@ cdef class UVStream(UVBaseTransport):
738738 return
739739 for buf in bufs:
740740 self ._buffer_write(buf)
741- self ._initiate_write()
741+ self ._initiate_write(False ) # try fast path in _initiate_write
742742
743743 def write_eof (self ):
744744 self ._ensure_alive()
0 commit comments