Skip to content

Commit 9e19f40

Browse files
committed
Add proto to sock_connect
Allow the selection of the protocol used by getaddrinfo by adding an additional, optional parameter proto_addr_info. If not specified, use the protocol used by the socket (= previous behaviour) This change is needed to allow custom protocols to be used with the sock_connect, because these protocols may raise an error when calling getaddrinfo (result in a "ai_proto not supported" error) An example of such protocol is MPTCP (https://mptcp.dev)
1 parent bffed80 commit 9e19f40

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Lib/asyncio/selector_events.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,19 +618,24 @@ def _sock_sendto(self, fut, sock, data, address):
618618
else:
619619
fut.set_result(n)
620620

621-
async def sock_connect(self, sock, address):
621+
async def sock_connect(self, sock, address, proto_addr_info = None):
622622
"""Connect to a remote socket at address.
623623
624624
This method is a coroutine.
625+
626+
The proto_addr info parameter allows to specify a protocol to use for the
627+
resolution of the address. If not specified, default to the protocol used
628+
by sock
625629
"""
626630
base_events._check_ssl_socket(sock)
627631
if self._debug and sock.gettimeout() != 0:
628632
raise ValueError("the socket must be non-blocking")
629633

630634
if sock.family == socket.AF_INET or (
631635
base_events._HAS_IPv6 and sock.family == socket.AF_INET6):
636+
proto = proto_addr_info if proto_addr_info is not None else sock.proto
632637
resolved = await self._ensure_resolved(
633-
address, family=sock.family, type=sock.type, proto=sock.proto,
638+
address, family=sock.family, type=sock.type, proto=proto,
634639
loop=self,
635640
)
636641
_, _, _, _, address = resolved[0]

0 commit comments

Comments
 (0)