utils.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:pytestlab 作者: sangoma 项目源码 文件源码
def new_rtp_socket(host, version=4):
    '''
    Get and return free socket address from the system in the rtp
    range 16382 <= port < 32767.

    Parameters
    ----------
    host : string
        hostname or ip for which a socket addr is needed

    Returns
    -------
    ip, port : string, int

    Notes
    -----
    Due to common usage with SIPp (which uses every rtp port
    and that port + 2) we have the rule that we skip forward
    by two on evey second call since N+2, (N+1)+2, will be
    already taken up and the next available will be (N+1)+2+1
    '''
    err = None
    for _ in range(5):
        try:
            return get_new_sock(
                host, port=next(_rtp_port_gen), version=version)
        except socket.error as e:
            # If we failed to bind, lets try again. Otherwise reraise
            # the error immediately as its something much more serious.
            if e.errno != errno.EADDRINUSE:
                raise
            err = e
    raise err
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号