MCPcopy Index your code
hub / github.com/python/cpython / _connect_sock

Method _connect_sock

Lib/asyncio/base_events.py:1017–1063  ·  view source on GitHub ↗

Create, bind and connect one socket.

(self, exceptions, addr_info, local_addr_infos=None)

Source from the content-addressed store, hash-verified

1015 offset))
1016
1017 async def _connect_sock(self, exceptions, addr_info, local_addr_infos=None):
1018 """Create, bind and connect one socket."""
1019 my_exceptions = []
1020 exceptions.append(my_exceptions)
1021 family, type_, proto, _, address = addr_info
1022 sock = None
1023 try:
1024 try:
1025 sock = socket.socket(family=family, type=type_, proto=proto)
1026 sock.setblocking(False)
1027 if local_addr_infos is not None:
1028 for lfamily, _, _, _, laddr in local_addr_infos:
1029 # skip local addresses of different family
1030 if lfamily != family:
1031 continue
1032 try:
1033 sock.bind(laddr)
1034 break
1035 except OSError as exc:
1036 msg = (
1037 f'error while attempting to bind on '
1038 f'address {laddr!r}: {str(exc).lower()}'
1039 )
1040 exc = OSError(exc.errno, msg)
1041 my_exceptions.append(exc)
1042 else: # all bind attempts failed
1043 if my_exceptions:
1044 raise my_exceptions.pop()
1045 else:
1046 raise OSError(f"no matching local address with {family=} found")
1047 await self.sock_connect(sock, address)
1048 return sock
1049 except OSError as exc:
1050 my_exceptions.append(exc)
1051 raise
1052 except:
1053 if sock is not None:
1054 try:
1055 sock.close()
1056 except OSError:
1057 # An error when closing a newly created socket is
1058 # not important, but it can overwrite more important
1059 # non-OSError error. So ignore it.
1060 pass
1061 raise
1062 finally:
1063 exceptions = my_exceptions = None
1064
1065 async def create_connection(
1066 self, protocol_factory, host=None, port=None,

Callers 1

create_connectionMethod · 0.95

Calls 9

strFunction · 0.85
socketMethod · 0.80
appendMethod · 0.45
setblockingMethod · 0.45
bindMethod · 0.45
lowerMethod · 0.45
popMethod · 0.45
sock_connectMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected