Skip to content

Commit 0c387bf

Browse files
GH-88968: Add notes about socket ownership transfers (GH-97936)
(cherry picked from commit 74ea204) Co-authored-by: Guido van Rossum <[email protected]>
1 parent c9480d5 commit 0c387bf

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

Doc/library/asyncio-eventloop.rst

+24
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,12 @@ Opening network connections
458458
*happy_eyeballs_delay*, *interleave*
459459
and *local_addr* should be specified.
460460

461+
.. note::
462+
463+
The *sock* argument transfers ownership of the socket to the
464+
transport created. To close the socket, call the transport's
465+
:meth:`~asyncio.BaseTransport.close` method.
466+
461467
* *local_addr*, if given, is a ``(local_host, local_port)`` tuple used
462468
to bind the socket locally. The *local_host* and *local_port*
463469
are looked up using ``getaddrinfo()``, similarly to *host* and *port*.
@@ -556,6 +562,12 @@ Opening network connections
556562
transport. If specified, *local_addr* and *remote_addr* should be omitted
557563
(must be :const:`None`).
558564

565+
.. note::
566+
567+
The *sock* argument transfers ownership of the socket to the
568+
transport created. To close the socket, call the transport's
569+
:meth:`~asyncio.BaseTransport.close` method.
570+
559571
See :ref:`UDP echo client protocol <asyncio-udp-echo-client-protocol>` and
560572
:ref:`UDP echo server protocol <asyncio-udp-echo-server-protocol>` examples.
561573

@@ -667,6 +679,12 @@ Creating network servers
667679
* *sock* can optionally be specified in order to use a preexisting
668680
socket object. If specified, *host* and *port* must not be specified.
669681

682+
.. note::
683+
684+
The *sock* argument transfers ownership of the socket to the
685+
server created. To close the socket, call the server's
686+
:meth:`~asyncio.Server.close` method.
687+
670688
* *backlog* is the maximum number of queued connections passed to
671689
:meth:`~socket.socket.listen` (defaults to 100).
672690

@@ -768,6 +786,12 @@ Creating network servers
768786
* *sock* is a preexisting socket object returned from
769787
:meth:`socket.accept <socket.socket.accept>`.
770788

789+
.. note::
790+
791+
The *sock* argument transfers ownership of the socket to the
792+
transport created. To close the socket, call the transport's
793+
:meth:`~asyncio.BaseTransport.close` method.
794+
771795
* *ssl* can be set to an :class:`~ssl.SSLContext` to enable SSL over
772796
the accepted connections.
773797

Doc/library/asyncio-stream.rst

+24
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ and work with streams:
6767
The rest of the arguments are passed directly to
6868
:meth:`loop.create_connection`.
6969

70+
.. note::
71+
72+
The *sock* argument transfers ownership of the socket to the
73+
:class:`StreamWriter` created. To close the socket, call its
74+
:meth:`~asyncio.StreamWriter.close` method.
75+
7076
.. versionchanged:: 3.7
7177
Added the *ssl_handshake_timeout* parameter.
7278

@@ -103,6 +109,12 @@ and work with streams:
103109
The rest of the arguments are passed directly to
104110
:meth:`loop.create_server`.
105111

112+
.. note::
113+
114+
The *sock* argument transfers ownership of the socket to the
115+
server created. To close the socket, call the server's
116+
:meth:`~asyncio.Server.close` method.
117+
106118
.. versionchanged:: 3.7
107119
Added the *ssl_handshake_timeout* and *start_serving* parameters.
108120

@@ -123,6 +135,12 @@ and work with streams:
123135

124136
See also the documentation of :meth:`loop.create_unix_connection`.
125137

138+
.. note::
139+
140+
The *sock* argument transfers ownership of the socket to the
141+
:class:`StreamWriter` created. To close the socket, call its
142+
:meth:`~asyncio.StreamWriter.close` method.
143+
126144
.. availability:: Unix.
127145

128146
.. versionchanged:: 3.7
@@ -143,6 +161,12 @@ and work with streams:
143161

144162
See also the documentation of :meth:`loop.create_unix_server`.
145163

164+
.. note::
165+
166+
The *sock* argument transfers ownership of the socket to the
167+
server created. To close the socket, call the server's
168+
:meth:`~asyncio.Server.close` method.
169+
146170
.. availability:: Unix.
147171

148172
.. versionchanged:: 3.7

0 commit comments

Comments
 (0)