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
评论列表
文章目录