@@ -203,12 +203,12 @@ def __repr__(self):
203203def open_connection (host , port , ssl = False ):
204204 if DEBUG and __debug__ :
205205 log .debug ("open_connection(%s, %s)" , host , port )
206- s = _socket .socket ()
206+ ai = _socket .getaddrinfo (host , port , 0 , _socket .SOCK_STREAM )
207+ ai = ai [0 ]
208+ s = _socket .socket (ai [0 ], ai [1 ], ai [2 ])
207209 s .setblocking (False )
208- ai = _socket .getaddrinfo (host , port )
209- addr = ai [0 ][4 ]
210210 try :
211- s .connect (addr )
211+ s .connect (ai [ - 1 ] )
212212 except OSError as e :
213213 if e .args [0 ] != uerrno .EINPROGRESS :
214214 raise
@@ -232,13 +232,13 @@ def open_connection(host, port, ssl=False):
232232def start_server (client_coro , host , port , backlog = 10 ):
233233 if DEBUG and __debug__ :
234234 log .debug ("start_server(%s, %s)" , host , port )
235- s = _socket .socket ()
235+ ai = _socket .getaddrinfo (host , port , 0 , _socket .SOCK_STREAM )
236+ ai = ai [0 ]
237+ s = _socket .socket (ai [0 ], ai [1 ], ai [2 ])
236238 s .setblocking (False )
237239
238- ai = _socket .getaddrinfo (host , port )
239- addr = ai [0 ][4 ]
240240 s .setsockopt (_socket .SOL_SOCKET , _socket .SO_REUSEADDR , 1 )
241- s .bind (addr )
241+ s .bind (ai [ - 1 ] )
242242 s .listen (backlog )
243243 while True :
244244 if DEBUG and __debug__ :
0 commit comments