Commit 5e1306d1 authored by Jason Toffaletti's avatar Jason Toffaletti

fallback when evdns isn't available

--HG--
extra : transplant_source : k%A2%0F%08%E0%13f%93%02%89%DC%E2%CF%0Dc%EE%81%A6%83%8A
parent 23799440
...@@ -639,18 +639,19 @@ def wrap_ssl000(sock, keyfile=None, certfile=None): ...@@ -639,18 +639,19 @@ def wrap_ssl000(sock, keyfile=None, certfile=None):
return ssl_sock return ssl_sock
# TODO: if core.HAS_EVDNS:
# might need to map evdns errors to socket errors # TODO:
# for example, DNS_ERR_NOTEXIST(3) is: # might need to map evdns errors to socket errors
# socket.gaierror: [Errno -2] Name or service not known # for example, DNS_ERR_NOTEXIST(3) is:
# socket.gaierror: [Errno -2] Name or service not known
def _dns_helper(result, type, ttl, addrs, args): def _dns_helper(result, type, ttl, addrs, args):
(waiter,) = args (waiter,) = args
waiter.switch((result, type, ttl, addrs)) waiter.switch((result, type, ttl, addrs))
_ip_re = re.compile('[\d\.]+') _ip_re = re.compile('[\d\.]+')
def gethostbyname(hostname): def gethostbyname(hostname):
# TODO: this is supposed to iterate through all the addresses # TODO: this is supposed to iterate through all the addresses
# could use a global dict(hostname, iter) # could use a global dict(hostname, iter)
# - fix these nasty hacks for localhost, ips, etc. # - fix these nasty hacks for localhost, ips, etc.
...@@ -669,7 +670,7 @@ def gethostbyname(hostname): ...@@ -669,7 +670,7 @@ def gethostbyname(hostname):
raise gaierror(result) raise gaierror(result)
return random.choice(addrs) return random.choice(addrs)
def getaddrinfo(host, port, family=__socket__.AF_INET, socktype=__socket__.SOCK_STREAM, proto=0, flags=0): def getaddrinfo(host, port, family=__socket__.AF_INET, socktype=__socket__.SOCK_STREAM, proto=0, flags=0):
waiter = Waiter() waiter = Waiter()
if family == __socket__.AF_INET: if family == __socket__.AF_INET:
core.dns_resolve_ipv4(host, core.DNS_QUERY_NO_SEARCH, _dns_helper, waiter) core.dns_resolve_ipv4(host, core.DNS_QUERY_NO_SEARCH, _dns_helper, waiter)
...@@ -685,13 +686,13 @@ def getaddrinfo(host, port, family=__socket__.AF_INET, socktype=__socket__.SOCK_ ...@@ -685,13 +686,13 @@ def getaddrinfo(host, port, family=__socket__.AF_INET, socktype=__socket__.SOCK_
r.append((family, socktype, proto, '', (addr, port))) r.append((family, socktype, proto, '', (addr, port)))
return r return r
def getnameinfo(sockaddr, flags): def getnameinfo(sockaddr, flags):
# http://svn.python.org/view/python/trunk/Modules/socketmodule.c?view=markup # http://svn.python.org/view/python/trunk/Modules/socketmodule.c?view=markup
# see socket_getnameinfo # see socket_getnameinfo
try: try:
host, port = sockaddr[:2] host, port = sockaddr[:2]
port = int(port) port = int(port)
except: except ValueError:
# make testRefCountGetNameInfo pass # make testRefCountGetNameInfo pass
del sockaddr del sockaddr
raise SystemError raise SystemError
...@@ -701,7 +702,11 @@ def getnameinfo(sockaddr, flags): ...@@ -701,7 +702,11 @@ def getnameinfo(sockaddr, flags):
if result != core.DNS_ERR_NONE: if result != core.DNS_ERR_NONE:
raise gaierror(result) raise gaierror(result)
return (addrs, port) return (addrs, port)
else:
# fallback to blocking versions
gethostbyname = __socket__.gethostbyname
getaddrinfo = __socket__.getaddrinfo
getnameinfo = __socket__.getnameinfo
def wrap_ssl(sock, keyfile=None, certfile=None): def wrap_ssl(sock, keyfile=None, certfile=None):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment