Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 74193af

Browse files
committed
Finish protocol documentation
1 parent a035e1b commit 74193af

1 file changed

Lines changed: 54 additions & 12 deletions

File tree

Doc/library/asyncio.rst

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ methods. Those methods are callbacks: they will be called by the transport
7272
on certain events (for example when some data is received); you shouldn't
7373
call them yourself, unless you are implementing a transport.
7474

75+
.. note::
76+
All callbacks have default implementations, which are empty. Therefore,
77+
you only need to implement the callbacks for the events in which you
78+
are interested.
79+
7580

7681
Protocol classes
7782
^^^^^^^^^^^^^^^^
@@ -88,17 +93,15 @@ Protocol classes
8893

8994
.. class:: SubprocessProtocol
9095

91-
The base class for implementing protocols representing communication
92-
channels with subprocesses (i.e., the set of pipes allowing bidirectional
93-
data exchange between this process and the child process).
96+
The base class for implementing protocols communicating with child
97+
processes (through a set of unidirectional pipes).
9498

9599

96100
Connection callbacks
97101
^^^^^^^^^^^^^^^^^^^^
98102

99103
These callbacks may be called on :class:`Protocol` and
100-
:class:`SubprocessProtocol` instances. The default implementations are
101-
empty.
104+
:class:`SubprocessProtocol` instances:
102105

103106
.. method:: connection_made(transport)
104107

@@ -121,12 +124,32 @@ per successful connection. All other callbacks will be called between those
121124
two methods, which allows for easier resource management in your protocol
122125
implementation.
123126

127+
The following callbacks may be called only on :class:`SubprocessProtocol`
128+
instances:
129+
130+
.. method:: pipe_data_received(fd, data)
131+
132+
Called when the child process writes data into its stdout or stderr pipe.
133+
*fd* is the integer file descriptor of the pipe. *data* is a non-empty
134+
bytes object containing the data.
135+
136+
.. method:: pipe_connection_lost(fd, exc)
137+
138+
Called when one of the pipes communicating with the child process
139+
is closed. *fd* is the integer file descriptor that was closed.
140+
141+
.. method:: process_exited()
142+
143+
Called when the child process has exited.
144+
124145

125146
Data reception callbacks
126147
^^^^^^^^^^^^^^^^^^^^^^^^
127148

128-
The following callbacks are called on :class:`Protocol` instances.
129-
The default implementations are empty.
149+
Streaming protocols
150+
"""""""""""""""""""
151+
152+
The following callbacks are called on :class:`Protocol` instances:
130153

131154
.. method:: data_received(data)
132155

@@ -136,9 +159,8 @@ The default implementations are empty.
136159
.. note::
137160
Whether the data is buffered, chunked or reassembled depends on
138161
the transport. In general, you shouldn't rely on specific semantics
139-
and instead make your parsing generic and flexible enough.
140-
141-
However, data always comes in the correct order.
162+
and instead make your parsing generic and flexible enough. However,
163+
data is always received in the correct order.
142164

143165
.. method:: eof_received()
144166

@@ -156,17 +178,37 @@ The default implementations are empty.
156178
in which case returning true from this method will not prevent closing
157179
the connection.
158180

159-
160181
:meth:`data_received` can be called an arbitrary number of times during
161182
a connection. However, :meth:`eof_received` is called at most once
162183
and, if called, :meth:`data_received` won't be called after it.
163184

185+
Datagram protocols
186+
""""""""""""""""""
187+
188+
The following callbacks are called on :class:`DatagramProtocol` instances.
189+
190+
.. method:: datagram_received(data, addr)
191+
192+
Called when a datagram is received. *data* is a bytes object containing
193+
the incoming data. *addr* is the address of the peer sending the data;
194+
the exact format depends on the transport.
195+
196+
.. method:: error_received(exc)
197+
198+
Called when a previous send or receive operation raises an
199+
:class:`OSError`. *exc* is the :class:`OSError` instance.
200+
201+
This method is called in rare conditions, when the transport (e.g. UDP)
202+
detects that a datagram couldn't be delivered to its recipient.
203+
In many conditions though, undeliverable datagrams will be silently
204+
dropped.
205+
164206

165207
Flow control callbacks
166208
^^^^^^^^^^^^^^^^^^^^^^
167209

168210
These callbacks may be called on :class:`Protocol` and
169-
:class:`SubprocessProtocol`. The default implementations are empty.
211+
:class:`SubprocessProtocol` instances:
170212

171213
.. method:: pause_writing()
172214

0 commit comments

Comments
 (0)