Make a socket. This function uses the module's ``socket_factory`` to make a socket of the specified address family and type. *af*, a ``socket.AddressFamily`` or ``int`` is the address family, either ``socket.AF_INET`` or ``socket.AF_INET6``. *type*, a ``socket.SocketKind`` is
(
af: socket.AddressFamily | int,
type: socket.SocketKind,
source: Any | None = None,
)
| 322 | |
| 323 | |
| 324 | def make_socket( |
| 325 | af: socket.AddressFamily | int, |
| 326 | type: socket.SocketKind, |
| 327 | source: Any | None = None, |
| 328 | ) -> socket.socket: |
| 329 | """Make a socket. |
| 330 | |
| 331 | This function uses the module's ``socket_factory`` to make a socket of the |
| 332 | specified address family and type. |
| 333 | |
| 334 | *af*, a ``socket.AddressFamily`` or ``int`` is the address family, either |
| 335 | ``socket.AF_INET`` or ``socket.AF_INET6``. |
| 336 | |
| 337 | *type*, a ``socket.SocketKind`` is the type of socket, e.g. ``socket.SOCK_DGRAM``, |
| 338 | a datagram socket, or ``socket.SOCK_STREAM``, a stream socket. Note that the |
| 339 | ``proto`` attribute of a socket is always zero with this API, so a datagram socket |
| 340 | will always be a UDP socket, and a stream socket will always be a TCP socket. |
| 341 | |
| 342 | *source* is the source address and port to bind to, if any. The default is |
| 343 | ``None`` which will bind to the wildcard address and a randomly chosen port. |
| 344 | If not ``None``, it should be a (low-level) address tuple appropriate for *af*. |
| 345 | """ |
| 346 | s = socket_factory(af, type, 0) |
| 347 | try: |
| 348 | s.setblocking(False) |
| 349 | if source is not None: |
| 350 | s.bind(source) |
| 351 | return s |
| 352 | except Exception: |
| 353 | s.close() |
| 354 | raise |
| 355 | |
| 356 | |
| 357 | def make_ssl_socket( |
no test coverage detected
searching dependent graphs…