Commit 31cfb782 authored by Denis Bilenko's avatar Denis Bilenko

socket: update create_connection. fixes issue #74

parent a2387f8a
...@@ -627,8 +627,8 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=N ...@@ -627,8 +627,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
...@@ -640,11 +640,15 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=N ...@@ -640,11 +640,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")
try: try:
......
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