Skip to content

Commit b2239f4

Browse files
MirochillKriechi
authored andcommitted
Document connection state transition timing
1 parent d9452d8 commit b2239f4

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

docs/source/api.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ Connection
2323
:special-members: __init__
2424
:members:
2525

26+
Incoming bytes are parsed by ``receive_data()``, but state changes caused by
27+
received events are applied while ``events()`` is consumed. For example, when
28+
the remote peer sends a close frame, the connection enters
29+
``REMOTE_CLOSING`` when the corresponding ``CloseConnection`` event is yielded,
30+
not when the bytes are first passed to ``receive_data()``.
31+
2632
.. autoclass:: wsproto.ConnectionType
2733
:members:
2834

src/wsproto/connection.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ def receive_data(self, data: bytes | None) -> None:
126126
127127
A list of events that the remote peer triggered by sending this data can
128128
be retrieved with :meth:`~wsproto.connection.Connection.events`.
129+
Passing bytes here does not itself apply every state transition caused
130+
by those events. For example, a remote close frame changes the
131+
connection state when its corresponding
132+
:class:`~wsproto.events.CloseConnection` event is yielded from
133+
:meth:`~wsproto.connection.Connection.events`.
129134
130135
:param data: The data received from the remote peer on the network.
131136
:type data: ``bytes``
@@ -152,6 +157,12 @@ def events(self) -> Generator[Event, None, None]:
152157
Return a generator that provides any events that have been generated
153158
by protocol activity.
154159
160+
Iterating this generator can advance the connection state while
161+
received frames are converted into events. For example, yielding a
162+
remote :class:`~wsproto.events.CloseConnection` event moves the
163+
connection into
164+
:attr:`~wsproto.connection.ConnectionState.REMOTE_CLOSING`.
165+
155166
:returns: generator of :class:`Event <wsproto.events.Event>` subclasses
156167
"""
157168
while self._events:

0 commit comments

Comments
 (0)