@@ -162,7 +162,7 @@ cdef class _StreamWriteContext:
162
162
PyObject_GetBuffer(
163
163
buf, & p_pybufs[py_bufs_len], PyBUF_SIMPLE)
164
164
except Exception :
165
- # This shouldn't ever happen, as `UVStream._write `
165
+ # This shouldn't ever happen, as `UVStream._buffer_write `
166
166
# casts non-bytes objects to `memoryviews`.
167
167
ctx.py_bufs_len = py_bufs_len
168
168
ctx.free_bufs()
@@ -407,7 +407,7 @@ cdef class UVStream(UVBaseTransport):
407
407
408
408
return written
409
409
410
- cdef inline _write (self , object data):
410
+ cdef inline _buffer_write (self , object data):
411
411
cdef int dlen
412
412
413
413
if not PyBytes_CheckExact(data):
@@ -420,6 +420,7 @@ cdef class UVStream(UVBaseTransport):
420
420
self ._buffer_size += dlen
421
421
self ._buffer.append(data)
422
422
423
+ cdef inline _start_write(self ):
423
424
if (not self ._protocol_paused and
424
425
(< uv.uv_stream_t* > self ._handle).write_queue_size == 0 and
425
426
self ._buffer_size > self ._high_water):
@@ -443,10 +444,10 @@ cdef class UVStream(UVBaseTransport):
443
444
# If not all of the data was sent successfully,
444
445
# we might need to pause the protocol.
445
446
self ._maybe_pause_protocol()
446
- return
447
447
448
- self ._maybe_pause_protocol()
449
- self ._loop._queue_write(self )
448
+ elif self ._buffer_size > 0 :
449
+ self ._maybe_pause_protocol()
450
+ self ._loop._queue_write(self )
450
451
451
452
cdef inline _exec_write(self ):
452
453
cdef:
@@ -679,7 +680,8 @@ cdef class UVStream(UVBaseTransport):
679
680
if self ._conn_lost:
680
681
self ._conn_lost += 1
681
682
return
682
- self ._write(buf)
683
+ self ._buffer_write(buf)
684
+ self ._start_write()
683
685
684
686
def writelines (self , bufs ):
685
687
self ._ensure_alive()
@@ -690,7 +692,8 @@ cdef class UVStream(UVBaseTransport):
690
692
self ._conn_lost += 1
691
693
return
692
694
for buf in bufs:
693
- self ._write(buf)
695
+ self ._buffer_write(buf)
696
+ self ._start_write()
694
697
695
698
def write_eof (self ):
696
699
self ._ensure_alive()
0 commit comments