Skip to content

Commit 3335bbe

Browse files
gvanrossummpage
authored andcommitted
pythonGH-88968: Add notes about socket ownership transfers (python#97936)
1 parent adc2815 commit 3335bbe

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
@@ -468,6 +468,12 @@ Opening network connections
468468
*happy_eyeballs_delay*, *interleave*
469469
and *local_addr* should be specified.
470470

471+
.. note::
472+
473+
The *sock* argument transfers ownership of the socket to the
474+
transport created. To close the socket, call the transport's
475+
:meth:`~asyncio.BaseTransport.close` method.
476+
471477
* *local_addr*, if given, is a ``(local_host, local_port)`` tuple used
472478
to bind the socket locally. The *local_host* and *local_port*
473479
are looked up using ``getaddrinfo()``, similarly to *host* and *port*.
@@ -577,6 +583,12 @@ Opening network connections
577583
transport. If specified, *local_addr* and *remote_addr* should be omitted
578584
(must be :const:`None`).
579585

586+
.. note::
587+
588+
The *sock* argument transfers ownership of the socket to the
589+
transport created. To close the socket, call the transport's
590+
:meth:`~asyncio.BaseTransport.close` method.
591+
580592
See :ref:`UDP echo client protocol <asyncio-udp-echo-client-protocol>` and
581593
:ref:`UDP echo server protocol <asyncio-udp-echo-server-protocol>` examples.
582594

@@ -688,6 +700,12 @@ Creating network servers
688700
* *sock* can optionally be specified in order to use a preexisting
689701
socket object. If specified, *host* and *port* must not be specified.
690702

703+
.. note::
704+
705+
The *sock* argument transfers ownership of the socket to the
706+
server created. To close the socket, call the server's
707+
:meth:`~asyncio.Server.close` method.
708+
691709
* *backlog* is the maximum number of queued connections passed to
692710
:meth:`~socket.socket.listen` (defaults to 100).
693711

@@ -789,6 +807,12 @@ Creating network servers
789807
* *sock* is a preexisting socket object returned from
790808
:meth:`socket.accept <socket.socket.accept>`.
791809

810+
.. note::
811+
812+
The *sock* argument transfers ownership of the socket to the
813+
transport created. To close the socket, call the transport's
814+
:meth:`~asyncio.BaseTransport.close` method.
815+
792816
* *ssl* can be set to an :class:`~ssl.SSLContext` to enable SSL over
793817
the accepted connections.
794818

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)