GH-88968: Add notes about socket ownership transfers (GH-97936)

(cherry picked from commit 74ea204634)

Co-authored-by: Guido van Rossum <guido@python.org>
This commit is contained in:
Miss Islington (bot) 2022-10-05 16:54:21 -07:00 committed by GitHub
parent c9480d5ad5
commit 0c387bf978
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 0 deletions

View file

@ -458,6 +458,12 @@ Opening network connections
*happy_eyeballs_delay*, *interleave* *happy_eyeballs_delay*, *interleave*
and *local_addr* should be specified. and *local_addr* should be specified.
.. note::
The *sock* argument transfers ownership of the socket to the
transport created. To close the socket, call the transport's
:meth:`~asyncio.BaseTransport.close` method.
* *local_addr*, if given, is a ``(local_host, local_port)`` tuple used * *local_addr*, if given, is a ``(local_host, local_port)`` tuple used
to bind the socket locally. The *local_host* and *local_port* to bind the socket locally. The *local_host* and *local_port*
are looked up using ``getaddrinfo()``, similarly to *host* and *port*. are looked up using ``getaddrinfo()``, similarly to *host* and *port*.
@ -556,6 +562,12 @@ Opening network connections
transport. If specified, *local_addr* and *remote_addr* should be omitted transport. If specified, *local_addr* and *remote_addr* should be omitted
(must be :const:`None`). (must be :const:`None`).
.. note::
The *sock* argument transfers ownership of the socket to the
transport created. To close the socket, call the transport's
:meth:`~asyncio.BaseTransport.close` method.
See :ref:`UDP echo client protocol <asyncio-udp-echo-client-protocol>` and See :ref:`UDP echo client protocol <asyncio-udp-echo-client-protocol>` and
:ref:`UDP echo server protocol <asyncio-udp-echo-server-protocol>` examples. :ref:`UDP echo server protocol <asyncio-udp-echo-server-protocol>` examples.
@ -667,6 +679,12 @@ Creating network servers
* *sock* can optionally be specified in order to use a preexisting * *sock* can optionally be specified in order to use a preexisting
socket object. If specified, *host* and *port* must not be specified. socket object. If specified, *host* and *port* must not be specified.
.. note::
The *sock* argument transfers ownership of the socket to the
server created. To close the socket, call the server's
:meth:`~asyncio.Server.close` method.
* *backlog* is the maximum number of queued connections passed to * *backlog* is the maximum number of queued connections passed to
:meth:`~socket.socket.listen` (defaults to 100). :meth:`~socket.socket.listen` (defaults to 100).
@ -768,6 +786,12 @@ Creating network servers
* *sock* is a preexisting socket object returned from * *sock* is a preexisting socket object returned from
:meth:`socket.accept <socket.socket.accept>`. :meth:`socket.accept <socket.socket.accept>`.
.. note::
The *sock* argument transfers ownership of the socket to the
transport created. To close the socket, call the transport's
:meth:`~asyncio.BaseTransport.close` method.
* *ssl* can be set to an :class:`~ssl.SSLContext` to enable SSL over * *ssl* can be set to an :class:`~ssl.SSLContext` to enable SSL over
the accepted connections. the accepted connections.

View file

@ -67,6 +67,12 @@ and work with streams:
The rest of the arguments are passed directly to The rest of the arguments are passed directly to
:meth:`loop.create_connection`. :meth:`loop.create_connection`.
.. note::
The *sock* argument transfers ownership of the socket to the
:class:`StreamWriter` created. To close the socket, call its
:meth:`~asyncio.StreamWriter.close` method.
.. versionchanged:: 3.7 .. versionchanged:: 3.7
Added the *ssl_handshake_timeout* parameter. Added the *ssl_handshake_timeout* parameter.
@ -103,6 +109,12 @@ and work with streams:
The rest of the arguments are passed directly to The rest of the arguments are passed directly to
:meth:`loop.create_server`. :meth:`loop.create_server`.
.. note::
The *sock* argument transfers ownership of the socket to the
server created. To close the socket, call the server's
:meth:`~asyncio.Server.close` method.
.. versionchanged:: 3.7 .. versionchanged:: 3.7
Added the *ssl_handshake_timeout* and *start_serving* parameters. Added the *ssl_handshake_timeout* and *start_serving* parameters.
@ -123,6 +135,12 @@ and work with streams:
See also the documentation of :meth:`loop.create_unix_connection`. See also the documentation of :meth:`loop.create_unix_connection`.
.. note::
The *sock* argument transfers ownership of the socket to the
:class:`StreamWriter` created. To close the socket, call its
:meth:`~asyncio.StreamWriter.close` method.
.. availability:: Unix. .. availability:: Unix.
.. versionchanged:: 3.7 .. versionchanged:: 3.7
@ -143,6 +161,12 @@ and work with streams:
See also the documentation of :meth:`loop.create_unix_server`. See also the documentation of :meth:`loop.create_unix_server`.
.. note::
The *sock* argument transfers ownership of the socket to the
server created. To close the socket, call the server's
:meth:`~asyncio.Server.close` method.
.. availability:: Unix. .. availability:: Unix.
.. versionchanged:: 3.7 .. versionchanged:: 3.7