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

Method _read_to_buffer_loop

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

Source from the content-addressed store, hash-verified

728 raise
729
730 def _read_to_buffer_loop(self) -> Optional[int]:
731 # This method is called from _handle_read and _try_inline_read.
732 if self._read_bytes is not None:
733 target_bytes = self._read_bytes # type: Optional[int]
734 elif self._read_max_bytes is not None:
735 target_bytes = self._read_max_bytes
736 elif self.reading():
737 # For read_until without max_bytes, or
738 # read_until_close, read as much as we can before
739 # scanning for the delimiter.
740 target_bytes = None
741 else:
742 target_bytes = 0
743 next_find_pos = 0
744 while not self.closed():
745 # Read from the socket until we get EWOULDBLOCK or equivalent.
746 # SSL sockets do some internal buffering, and if the data is
747 # sitting in the SSL object's buffer select() and friends
748 # can't see it; the only way to find out if it's there is to
749 # try to read it.
750 if self._read_to_buffer() == 0:
751 break
752
753 # If we've read all the bytes we can use, break out of
754 # this loop.
755
756 # If we've reached target_bytes, we know we're done.
757 if target_bytes is not None and self._read_buffer_size >= target_bytes:
758 break
759
760 # Otherwise, we need to call the more expensive find_read_pos.
761 # It's inefficient to do this on every read, so instead
762 # do it on the first read and whenever the read buffer
763 # size has doubled.
764 if self._read_buffer_size >= next_find_pos:
765 pos = self._find_read_pos()
766 if pos is not None:
767 return pos
768 next_find_pos = self._read_buffer_size * 2
769 return self._find_read_pos()
770
771 def _handle_read(self) -> None:
772 try:

Callers 2

_handle_readMethod · 0.95
_try_inline_readMethod · 0.95

Calls 4

readingMethod · 0.95
closedMethod · 0.95
_read_to_bufferMethod · 0.95
_find_read_posMethod · 0.95

Tested by

no test coverage detected