Fix error when sending empty write buf

This commit is contained in:
Kovid Goyal 2020-12-01 12:25:09 +05:30
parent df61ee4ac3
commit ed2dae5884
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -324,13 +324,17 @@ class Loop:
self.write_buf[self.iov_limit - 1] = b''.join(self.write_buf[self.iov_limit - 1:])
del self.write_buf[self.iov_limit:]
sizes = tuple(map(len, self.write_buf))
try:
written = os.writev(fd, self.write_buf)
except BlockingIOError:
return
if not written:
raise EOFError('The output stream is closed')
if written >= sum(sizes):
total_size = sum(sizes)
if total_size:
try:
written = os.writev(fd, self.write_buf)
except BlockingIOError:
return
if not written:
raise EOFError('The output stream is closed')
else:
written = 0
if written >= total_size:
self.write_buf: List[bytes] = []
self.asycio_loop.remove_writer(fd)
self.waiting_for_writes = False