Skip to content

Commit 3ff5822

Browse files
authored
Docs: don't rely on implicit 'above' directions in socket docs (#146426)
1 parent 1efe441 commit 3ff5822

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

Doc/library/socket.rst

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ is implicit on send operations.
3939
A TLS/SSL wrapper for socket objects.
4040

4141

42+
.. _socket-addresses:
43+
4244
Socket families
4345
---------------
4446

@@ -903,7 +905,7 @@ The following functions all create :ref:`socket objects <socket-objects>`.
903905

904906
Build a pair of connected socket objects using the given address family, socket
905907
type, and protocol number. Address family, socket type, and protocol number are
906-
as for the :func:`~socket.socket` function above. The default family is :const:`AF_UNIX`
908+
as for the :func:`~socket.socket` function. The default family is :const:`AF_UNIX`
907909
if defined on the platform; otherwise, the default is :const:`AF_INET`.
908910

909911
The newly created sockets are :ref:`non-inheritable <fd_inheritance>`.
@@ -999,8 +1001,8 @@ The following functions all create :ref:`socket objects <socket-objects>`.
9991001

10001002
Duplicate the file descriptor *fd* (an integer as returned by a file object's
10011003
:meth:`~io.IOBase.fileno` method) and build a socket object from the result. Address
1002-
family, socket type and protocol number are as for the :func:`~socket.socket` function
1003-
above. The file descriptor should refer to a socket, but this is not checked ---
1004+
family, socket type and protocol number are as for the :func:`~socket.socket` function.
1005+
The file descriptor should refer to a socket, but this is not checked ---
10041006
subsequent operations on the object may fail if the file descriptor is invalid.
10051007
This function is rarely needed, but can be used to get or set socket options on
10061008
a socket passed to a program as standard input or output (such as a server
@@ -1564,8 +1566,8 @@ to sockets.
15641566

15651567
.. method:: socket.bind(address)
15661568

1567-
Bind the socket to *address*. The socket must not already be bound. (The format
1568-
of *address* depends on the address family --- see above.)
1569+
Bind the socket to *address*. The socket must not already be bound. The format
1570+
of *address* depends on the address family --- see :ref:`socket-addresses`.
15691571

15701572
.. audit-event:: socket.bind self,address socket.socket.bind
15711573

@@ -1598,8 +1600,8 @@ to sockets.
15981600

15991601
.. method:: socket.connect(address)
16001602

1601-
Connect to a remote socket at *address*. (The format of *address* depends on the
1602-
address family --- see above.)
1603+
Connect to a remote socket at *address*. The format of *address* depends on the
1604+
address family --- see :ref:`socket-addresses`.
16031605

16041606
If the connection is interrupted by a signal, the method waits until the
16051607
connection completes, or raises a :exc:`TimeoutError` on timeout, if the
@@ -1674,16 +1676,16 @@ to sockets.
16741676
.. method:: socket.getpeername()
16751677

16761678
Return the remote address to which the socket is connected. This is useful to
1677-
find out the port number of a remote IPv4/v6 socket, for instance. (The format
1678-
of the address returned depends on the address family --- see above.) On some
1679-
systems this function is not supported.
1679+
find out the port number of a remote IPv4/v6 socket, for instance. The format
1680+
of the address returned depends on the address family --- see :ref:`socket-addresses`.
1681+
On some systems this function is not supported.
16801682

16811683

16821684
.. method:: socket.getsockname()
16831685

16841686
Return the socket's own address. This is useful to find out the port number of
1685-
an IPv4/v6 socket, for instance. (The format of the address returned depends on
1686-
the address family --- see above.)
1687+
an IPv4/v6 socket, for instance. The format of the address returned depends on
1688+
the address family --- see :ref:`socket-addresses`.
16871689

16881690

16891691
.. method:: socket.getsockopt(level, optname[, buflen])
@@ -1795,7 +1797,8 @@ to sockets.
17951797
where *bytes* is a bytes object representing the data received and *address* is the
17961798
address of the socket sending the data. See the Unix manual page
17971799
:manpage:`recv(2)` for the meaning of the optional argument *flags*; it defaults
1798-
to zero. (The format of *address* depends on the address family --- see above.)
1800+
to zero. The format of *address* depends on the address family --- see
1801+
:ref:`socket-addresses`.
17991802

18001803
.. versionchanged:: 3.5
18011804
If the system call is interrupted and the signal handler does not raise
@@ -1925,8 +1928,8 @@ to sockets.
19251928
new bytestring. The return value is a pair ``(nbytes, address)`` where *nbytes* is
19261929
the number of bytes received and *address* is the address of the socket sending
19271930
the data. See the Unix manual page :manpage:`recv(2)` for the meaning of the
1928-
optional argument *flags*; it defaults to zero. (The format of *address*
1929-
depends on the address family --- see above.)
1931+
optional argument *flags*; it defaults to zero. The format of *address*
1932+
depends on the address family --- see :ref:`socket-addresses`.
19301933

19311934

19321935
.. method:: socket.recv_into(buffer[, nbytes[, flags]])
@@ -1941,7 +1944,7 @@ to sockets.
19411944
.. method:: socket.send(bytes[, flags])
19421945

19431946
Send data to the socket. The socket must be connected to a remote socket. The
1944-
optional *flags* argument has the same meaning as for :meth:`recv` above.
1947+
optional *flags* argument has the same meaning as for :meth:`recv`.
19451948
Returns the number of bytes sent. Applications are responsible for checking that
19461949
all data has been sent; if only some of the data was transmitted, the
19471950
application needs to attempt delivery of the remaining data. For further
@@ -1956,7 +1959,7 @@ to sockets.
19561959
.. method:: socket.sendall(bytes[, flags])
19571960

19581961
Send data to the socket. The socket must be connected to a remote socket. The
1959-
optional *flags* argument has the same meaning as for :meth:`recv` above.
1962+
optional *flags* argument has the same meaning as for :meth:`recv`.
19601963
Unlike :meth:`send`, this method continues to send data from *bytes* until
19611964
either all data has been sent or an error occurs. ``None`` is returned on
19621965
success. On error, an exception is raised, and there is no way to determine how
@@ -1977,9 +1980,9 @@ to sockets.
19771980

19781981
Send data to the socket. The socket should not be connected to a remote socket,
19791982
since the destination socket is specified by *address*. The optional *flags*
1980-
argument has the same meaning as for :meth:`recv` above. Return the number of
1981-
bytes sent. (The format of *address* depends on the address family --- see
1982-
above.)
1983+
argument has the same meaning as for :meth:`recv`. Return the number of
1984+
bytes sent. The format of *address* depends on the address family --- see
1985+
:ref:`socket-addresses`.
19831986

19841987
.. audit-event:: socket.sendto self,address socket.socket.sendto
19851988

0 commit comments

Comments
 (0)