提交 9744dbb4 编写于 作者: C Cleber Rosa

avocado.utils.network: introduce default port values for find_free_port()

On many situations, users just need a port, there's no need to pick
from a defined range.  Let's introduce defaults, so it can be used
without any arguments for that use case.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 04329b15
......@@ -48,14 +48,15 @@ def is_port_free(port, address):
return free
def find_free_port(start_port, end_port, address="localhost", sequent=True):
def find_free_port(start_port=1024, end_port=65535, address="localhost", sequent=True):
"""
Return a host free port in the range [start_port, end_port].
:param start_port: header of candidate port range
:param end_port: ender of candidate port range
:param start_port: header of candidate port range, defaults to 1024
:param end_port: ender of candidate port range, defaults to 65535
:param sequent: Find port sequentially, random order if it's False
:param address: Socket address to bind or connect
:rtype: int or None if no free port found
"""
port_range = range(start_port, end_port)
if not sequent:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册