◐ Shell
clean mode source ↗

bpo-41279: Add StreamReaderBufferedProtocol by tontinton · Pull Request #21446 · python/cpython

@tontinton tontinton changed the title Fix issue 41279 bpo-41273: Convert StreamReaderProtocol to a BufferedProtocol

Jul 11, 2020

@tontinton tontinton changed the title bpo-41273: Convert StreamReaderProtocol to a BufferedProtocol bpo-41279: Convert StreamReaderProtocol to a BufferedProtocol

Jul 11, 2020

@tontinton tontinton changed the title bpo-41279: Convert StreamReaderProtocol to a BufferedProtocol bpo-41279: Convert StreamReaderProtocol to a BufferedProtocol for increased performance

Jul 11, 2020

1st1

mpaolini

mpaolini

1st1

1st1

1st1

1st1

1st1 approved these changes Jul 29, 2020

tzickel

asvetlov

gst

This class gets better performance as BufferedProtocol uses read_into
into a buffer allocated before, instead of allocating a new buffer
each time read is called.
…pythonGH-21446)

The transport did not know how to use the proper api exported by
BufferedProtocol.

Added a new callback function that calls getbuffer() and
buffer_updated() instead of data_received() when the protocol given to
it is of type BufferedProtocol.

This is exactly the same way _SelectorSocketTransport handles a
BufferedProtocol.
…port (pythonGH-21446)

In the __init__ function if the protocol is of instance BufferedProtocol
instead of creating a buffer object, we call get_buffer on the protocol
to get its buffer.

In addition _loop_reading now calls _data_received as soon as there is
actual data instead of calling only after adding a recv_into event.

The reason for this change is because read_into could call it's callback
immediatly meaning overriding the data on the buffer before we actually
call _data_received on it, which fixes the potential issue of missed data.
…pythonGH-21446)

When calling set_protocol to change the protocol you can now change the
type of the protocol from BufferedProtocol to Protocol or vice versa.

start_tls needed this feature as it could read into a buffered protocol
at first and then change the protocol to SSLProto which is a regular
protocol.