@@ -375,6 +375,7 @@ cdef class UVStream(UVBaseTransport):
375375 # uv_try_write -- less layers of code. The error
376376 # checking logic is copied from libuv.
377377 written = system.write(fd, buf, blen)
378+
378379 while written == - 1 and (
379380 errno.errno == errno.EINTR or
380381 (system.PLATFORM_IS_APPLE and
@@ -464,7 +465,7 @@ cdef class UVStream(UVBaseTransport):
464465 if not buf_len:
465466 return
466467
467- if (< uv.uv_stream_t* > self ._handle).write_queue_size == 0 :
468+ if not self ._protocol_paused and (< uv.uv_stream_t* > self ._handle).write_queue_size == 0 :
468469 # libuv internal write buffers for this stream are empty.
469470 if buf_len == 1 :
470471 # If we only have one piece of data to send, let's
@@ -681,14 +682,14 @@ cdef class UVStream(UVBaseTransport):
681682 self ._conn_lost += 1
682683 return
683684
684- cdef int sent
685+ cdef ssize_t written
685686
686- if (self ._buffer_size == 0 and
687+ if (not self ._protocol_paused and self ._buffer_size == 0 and
687688 (< uv.uv_stream_t* > self ._handle).write_queue_size == 0 ):
688689
689- sent_ = self ._try_write(buf)
690+ written_ = self ._try_write(buf)
690691
691- if sent_ is None :
692+ if written_ is None :
692693 # A `self._fatal_error` was called.
693694 # It might not raise an exception under some
694695 # conditions.
@@ -698,25 +699,24 @@ cdef class UVStream(UVBaseTransport):
698699
699700 return
700701
701- sent = sent_
702+ written = written_
702703
703- if sent == 0 :
704+ if written == 0 :
704705 # All data was successfully written.
705706 # on_write will call "maybe_resume_protocol".
706- self ._on_write()
707707 return
708708
709- if sent > 0 :
709+ if written > 0 :
710710 if UVLOOP_DEBUG:
711- if sent == len (buf):
711+ if written == len (buf):
712712 raise RuntimeError (' _try_write sent all data and '
713713 ' returned non-zero' )
714714
715715 if PyBytes_CheckExact(buf):
716716 # Cast bytes to memoryview to avoid copying
717717 # data that wasn't sent.
718718 buf = memoryview(buf)
719- buf = buf[sent :]
719+ buf = buf[written_ :]
720720
721721 # At this point it's either data was sent partially,
722722 # or an EAGAIN has happened.
@@ -940,7 +940,6 @@ cdef void __uv_stream_on_write(
940940 uv.uv_write_t* req,
941941 int status,
942942) noexcept with gil:
943-
944943 if UVLOOP_DEBUG:
945944 if req.data is NULL :
946945 aio_logger.error(
0 commit comments