@@ -842,66 +842,8 @@ Creating sockets
842842The following functions all create :ref: `socket objects <socket-objects >`.
843843
844844
845- .. class :: socket(family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None)
846- :noindex:
847-
848- Create a new socket using the given address family, socket type and protocol
849- number. The address family should be :const: `AF_INET ` (the default),
850- :const: `AF_INET6 `, :const: `AF_UNIX `, :const: `AF_CAN `, :const: `AF_PACKET `,
851- or :const: `AF_RDS `. The socket type should be :const: `SOCK_STREAM ` (the
852- default), :const: `SOCK_DGRAM `, :const: `SOCK_RAW ` or perhaps one of the other
853- ``SOCK_ `` constants. The protocol number is usually zero and may be omitted
854- or in the case where the address family is :const: `AF_CAN ` the protocol
855- should be one of :const: `CAN_RAW `, :const: `CAN_BCM `, :const: `CAN_ISOTP ` or
856- :const: `CAN_J1939 `.
857-
858- If *fileno * is specified, the values for *family *, *type *, and *proto * are
859- auto-detected from the specified file descriptor. Auto-detection can be
860- overruled by calling the function with explicit *family *, *type *, or *proto *
861- arguments. This only affects how Python represents e.g. the return value
862- of :meth: `socket.getpeername ` but not the actual OS resource. Unlike
863- :func: `socket.fromfd `, *fileno * will return the same socket and not a
864- duplicate. This may help close a detached socket using
865- :meth: `socket.close `.
866-
867- The newly created socket is :ref: `non-inheritable <fd_inheritance >`.
868-
869- .. audit-event :: socket.__new__ self,family,type,protocol socket.socket
870-
871- .. versionchanged :: 3.3
872- The AF_CAN family was added.
873- The AF_RDS family was added.
874-
875- .. versionchanged :: 3.4
876- The CAN_BCM protocol was added.
877-
878- .. versionchanged :: 3.4
879- The returned socket is now non-inheritable.
880-
881- .. versionchanged :: 3.7
882- The CAN_ISOTP protocol was added.
883-
884- .. versionchanged :: 3.7
885- When :const: `SOCK_NONBLOCK ` or :const: `SOCK_CLOEXEC `
886- bit flags are applied to *type * they are cleared, and
887- :attr: `socket.type ` will not reflect them. They are still passed
888- to the underlying system ``socket() `` call. Therefore,
889-
890- ::
891-
892- sock = socket.socket(
893- socket.AF_INET,
894- socket.SOCK_STREAM | socket.SOCK_NONBLOCK)
895-
896- will still create a non-blocking socket on OSes that support
897- ``SOCK_NONBLOCK ``, but ``sock.type `` will be set to
898- ``socket.SOCK_STREAM ``.
899-
900- .. versionchanged :: 3.9
901- The CAN_J1939 protocol was added.
902-
903- .. versionchanged :: 3.10
904- The IPPROTO_MPTCP protocol was added.
845+ The :class: `socket <socket.socket> ` class constructor creates a new socket
846+ directly; see :ref: `socket-objects ` for its parameters and full description.
905847
906848.. function :: socketpair([family[, type[, proto]]])
907849
@@ -1533,7 +1475,65 @@ The :mod:`!socket` module also offers various network-related services:
15331475Socket Objects
15341476--------------
15351477
1536- .. class :: socket
1478+ .. class :: socket(family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None)
1479+
1480+ Create a new socket using the given address family, socket type and protocol
1481+ number. The address family should be :const: `AF_INET ` (the default),
1482+ :const: `AF_INET6 `, :const: `AF_UNIX `, :const: `AF_CAN `, :const: `AF_PACKET `,
1483+ or :const: `AF_RDS `. The socket type should be :const: `SOCK_STREAM ` (the
1484+ default), :const: `SOCK_DGRAM `, :const: `SOCK_RAW ` or perhaps one of the other
1485+ ``SOCK_ `` constants. The protocol number is usually zero and may be omitted
1486+ or in the case where the address family is :const: `AF_CAN ` the protocol
1487+ should be one of :const: `CAN_RAW `, :const: `CAN_BCM `, :const: `CAN_ISOTP ` or
1488+ :const: `CAN_J1939 `.
1489+
1490+ If *fileno * is specified, the values for *family *, *type *, and *proto * are
1491+ auto-detected from the specified file descriptor. Auto-detection can be
1492+ overruled by calling the function with explicit *family *, *type *, or *proto *
1493+ arguments. This only affects how Python represents e.g. the return value
1494+ of :meth: `socket.getpeername ` but not the actual OS resource. Unlike
1495+ :func: `socket.fromfd `, *fileno * will return the same socket and not a
1496+ duplicate. This may help close a detached socket using
1497+ :meth: `socket.close `.
1498+
1499+ The newly created socket is :ref: `non-inheritable <fd_inheritance >`.
1500+
1501+ .. audit-event :: socket.__new__ self,family,type,protocol socket.socket
1502+
1503+ .. versionchanged :: 3.3
1504+ The AF_CAN family was added.
1505+ The AF_RDS family was added.
1506+
1507+ .. versionchanged :: 3.4
1508+ The CAN_BCM protocol was added.
1509+
1510+ .. versionchanged :: 3.4
1511+ The returned socket is now non-inheritable.
1512+
1513+ .. versionchanged :: 3.7
1514+ The CAN_ISOTP protocol was added.
1515+
1516+ .. versionchanged :: 3.7
1517+ When :const: `SOCK_NONBLOCK ` or :const: `SOCK_CLOEXEC `
1518+ bit flags are applied to *type * they are cleared, and
1519+ :attr: `socket.type ` will not reflect them. They are still passed
1520+ to the underlying system ``socket() `` call. Therefore,
1521+
1522+ ::
1523+
1524+ sock = socket.socket(
1525+ socket.AF_INET,
1526+ socket.SOCK_STREAM | socket.SOCK_NONBLOCK)
1527+
1528+ will still create a non-blocking socket on OSes that support
1529+ ``SOCK_NONBLOCK ``, but ``sock.type `` will be set to
1530+ ``socket.SOCK_STREAM ``.
1531+
1532+ .. versionchanged :: 3.9
1533+ The CAN_J1939 protocol was added.
1534+
1535+ .. versionchanged :: 3.10
1536+ The IPPROTO_MPTCP protocol was added.
15371537
15381538 Socket objects have the following methods. Except for
15391539 :meth: `~socket.makefile `, these correspond to Unix system calls applicable
0 commit comments