Commit c99aebed authored by Denis Bilenko's avatar Denis Bilenko

socket: update create_connection. fixes issue #74

--HG--
extra : transplant_source : %F7%F1%D8%5Ds%A6%0C%95%01%BC%BFS%B5B%0E7%AESu%12
parent 90a43632
...@@ -608,8 +608,8 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=N ...@@ -608,8 +608,8 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=N
An host of '' or port 0 tells the OS to use the default. An host of '' or port 0 tells the OS to use the default.
""" """
msg = "getaddrinfo returns an empty list"
host, port = address host, port = address
err = None
for res in getaddrinfo(host, port, 0, SOCK_STREAM): for res in getaddrinfo(host, port, 0, SOCK_STREAM):
af, socktype, proto, _canonname, sa = res af, socktype, proto, _canonname, sa = res
sock = None sock = None
...@@ -621,11 +621,15 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=N ...@@ -621,11 +621,15 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=N
sock.bind(source_address) sock.bind(source_address)
sock.connect(sa) sock.connect(sa)
return sock return sock
except error, msg: except error, ex:
err = ex
sys.exc_clear() sys.exc_clear()
if sock is not None: if sock is not None:
sock.close() sock.close()
raise msg if err is not None:
raise err
else:
raise error("getaddrinfo returns an empty list")
def gethostbyname(host): def gethostbyname(host):
......
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