@@ -203,12 +203,12 @@ def __repr__(self):
203
203
def open_connection (host , port , ssl = False ):
204
204
if DEBUG and __debug__ :
205
205
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 ])
207
209
s .setblocking (False )
208
- ai = _socket .getaddrinfo (host , port )
209
- addr = ai [0 ][4 ]
210
210
try :
211
- s .connect (addr )
211
+ s .connect (ai [ - 1 ] )
212
212
except OSError as e :
213
213
if e .args [0 ] != uerrno .EINPROGRESS :
214
214
raise
@@ -232,13 +232,13 @@ def open_connection(host, port, ssl=False):
232
232
def start_server (client_coro , host , port , backlog = 10 ):
233
233
if DEBUG and __debug__ :
234
234
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 ])
236
238
s .setblocking (False )
237
239
238
- ai = _socket .getaddrinfo (host , port )
239
- addr = ai [0 ][4 ]
240
240
s .setsockopt (_socket .SOL_SOCKET , _socket .SO_REUSEADDR , 1 )
241
- s .bind (addr )
241
+ s .bind (ai [ - 1 ] )
242
242
s .listen (backlog )
243
243
while True :
244
244
if DEBUG and __debug__ :
0 commit comments