@@ -1020,8 +1020,12 @@ def _check_sendfile_params(self, sock, file, offset, count):
10201020 "offset must be a non-negative integer (got {!r})" .format (
10211021 offset ))
10221022
1023- async def _connect_sock (self , exceptions , addr_info , local_addr_infos = None ):
1024- """Create, bind and connect one socket."""
1023+ async def _connect_sock (self , exceptions , addr_info , local_addr_infos = None ,
1024+ connected_sockets = None ):
1025+ """Create, bind and connect one socket.
1026+
1027+ If *connected_sockets* is a list, the connected socket is appended to it.
1028+ """
10251029 my_exceptions = []
10261030 exceptions .append (my_exceptions )
10271031 family , type_ , proto , _ , address = addr_info
@@ -1051,6 +1055,8 @@ async def _connect_sock(self, exceptions, addr_info, local_addr_infos=None):
10511055 else :
10521056 raise OSError (f"no matching local address with { family = } found" )
10531057 await self .sock_connect (sock , address )
1058+ if connected_sockets is not None :
1059+ connected_sockets .append (sock )
10541060 return sock
10551061 except OSError as exc :
10561062 my_exceptions .append (exc )
@@ -1160,19 +1166,14 @@ async def create_connection(
11601166 # Sockets connected by the attempts, so that the winner is
11611167 # closed if the race is cancelled before it returns.
11621168 connected = []
1163-
1164- async def connect_sock (addrinfo ):
1165- sock = await self ._connect_sock (
1166- exceptions , addrinfo , laddr_infos )
1167- connected .append (sock )
1168- return sock
1169-
11701169 try :
11711170 sock = (await staggered .staggered_race (
11721171 (
11731172 # can't use functools.partial as it keeps a
11741173 # reference to exceptions
1175- lambda addrinfo = addrinfo : connect_sock (addrinfo )
1174+ lambda addrinfo = addrinfo : self ._connect_sock (
1175+ exceptions , addrinfo , laddr_infos , connected
1176+ )
11761177 for addrinfo in infos
11771178 ),
11781179 happy_eyeballs_delay ,
0 commit comments