Skip to content

Commit 147085d

Browse files
committed
uasyncio: Be sure to create socket with params returned by getaddrinfo().
1 parent 63b3d75 commit 147085d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

uasyncio/uasyncio/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,12 @@ def __repr__(self):
203203
def open_connection(host, port, ssl=False):
204204
if DEBUG and __debug__:
205205
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])
207209
s.setblocking(False)
208-
ai = _socket.getaddrinfo(host, port)
209-
addr = ai[0][4]
210210
try:
211-
s.connect(addr)
211+
s.connect(ai[-1])
212212
except OSError as e:
213213
if e.args[0] != uerrno.EINPROGRESS:
214214
raise
@@ -232,13 +232,13 @@ def open_connection(host, port, ssl=False):
232232
def start_server(client_coro, host, port, backlog=10):
233233
if DEBUG and __debug__:
234234
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])
236238
s.setblocking(False)
237239

238-
ai = _socket.getaddrinfo(host, port)
239-
addr = ai[0][4]
240240
s.setsockopt(_socket.SOL_SOCKET, _socket.SO_REUSEADDR, 1)
241-
s.bind(addr)
241+
s.bind(ai[-1])
242242
s.listen(backlog)
243243
while True:
244244
if DEBUG and __debug__:

0 commit comments

Comments
 (0)