MCPcopy
hub / github.com/tornadoweb/tornado / _handle_write

Method _handle_write

tornado/iostream.py:947–983  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

945 )
946
947 def _handle_write(self) -> None:
948 while True:
949 size = len(self._write_buffer)
950 if not size:
951 break
952 assert size > 0
953 try:
954 if _WINDOWS:
955 # On windows, socket.send blows up if given a
956 # write buffer that's too large, instead of just
957 # returning the number of bytes it was able to
958 # process. Therefore we must not call socket.send
959 # with more than 128KB at a time.
960 size = 128 * 1024
961
962 num_bytes = self.write_to_fd(self._write_buffer.peek(size))
963 if num_bytes == 0:
964 break
965 self._write_buffer.advance(num_bytes)
966 self._total_write_done_index += num_bytes
967 except BlockingIOError:
968 break
969 except OSError as e:
970 if not self._is_connreset(e):
971 # Broken pipe errors are usually caused by connection
972 # reset, and its better to not log EPIPE errors to
973 # minimize log spam
974 gen_log.warning("Write error on %s: %s", self.fileno(), e)
975 self.close(exc_info=e)
976 return
977
978 while self._write_futures:
979 index, future = self._write_futures[0]
980 if index > self._total_write_done_index:
981 break
982 self._write_futures.popleft()
983 future_set_result_unless_cancelled(future, None)
984
985 def _consume(self, loc: int) -> bytes:
986 # Consume loc bytes from the read buffer and return them

Callers 2

writeMethod · 0.95
_handle_eventsMethod · 0.95

Calls 7

write_to_fdMethod · 0.95
_is_connresetMethod · 0.95
filenoMethod · 0.95
closeMethod · 0.95
peekMethod · 0.80
advanceMethod · 0.80

Tested by

no test coverage detected