Skip to content

Commit

Permalink
Add 'address' keyword control binded address tornadoweb#2969
Browse files Browse the repository at this point in the history
  • Loading branch information
youguanxinqing committed Jan 11, 2021
1 parent 1fff216 commit 1e7b95c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tornado/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@
_NON_OWNED_IOLOOPS = AsyncIOMainLoop


def bind_unused_port(reuse_port: bool = False) -> Tuple[socket.socket, int]:
def bind_unused_port(reuse_port: bool = False, address: str = "127.0.0.1") -> Tuple[socket.socket, int]:
"""Binds a server socket to an available port on localhost.
Returns a tuple (socket, port).
.. versionchanged:: 4.4
Always binds to ``127.0.0.1`` without resolving the name
Default binds to ``127.0.0.1`` without resolving the name
``localhost``.
"""
sock = netutil.bind_sockets(
0, "127.0.0.1", family=socket.AF_INET, reuse_port=reuse_port
0, address, family=socket.AF_INET, reuse_port=reuse_port
)[0]
port = sock.getsockname()[1]
return sock, port
Expand Down

0 comments on commit 1e7b95c

Please sign in to comment.