@@ -208,6 +208,8 @@ def sock_recv(self, sock, n):
208208 return fut
209209
210210 def _sock_recv (self , fut , registered , sock , n ):
211+ # _sock_recv() can add itself as an I/O callback if the operation can't
212+ # be done immediatly. Don't use it directly, call sock_recv().
211213 fd = sock .fileno ()
212214 if registered :
213215 # Remove the callback early. It should be rare that the
@@ -260,22 +262,16 @@ def _sock_sendall(self, fut, registered, sock, data):
260262
261263 def sock_connect (self , sock , address ):
262264 """XXX"""
263- # That address better not require a lookup! We're not calling
264- # self.getaddrinfo() for you here. But verifying this is
265- # complicated; the socket module doesn't have a pattern for
266- # IPv6 addresses (there are too many forms, apparently).
267265 fut = futures .Future (loop = self )
268- self ._sock_connect (fut , False , sock , address )
266+ try :
267+ base_events ._check_resolved_address (sock , address )
268+ except ValueError as err :
269+ fut .set_exception (err )
270+ else :
271+ self ._sock_connect (fut , False , sock , address )
269272 return fut
270273
271274 def _sock_connect (self , fut , registered , sock , address ):
272- # TODO: Use getaddrinfo() to look up the address, to avoid the
273- # trap of hanging the entire event loop when the address
274- # requires doing a DNS lookup. (OTOH, the caller should
275- # already have done this, so it would be nice if we could
276- # easily tell whether the address needs looking up or not. I
277- # know how to do this for IPv4, but IPv6 addresses have many
278- # syntaxes.)
279275 fd = sock .fileno ()
280276 if registered :
281277 self .remove_writer (fd )
0 commit comments