Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry video RTP bind if port is taken. #344

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/sipp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1909,6 +1909,10 @@ int main(int argc, char *argv[])
local_addr->ai_addrlen);
freeaddrinfo(local_addr);

int try_counter = 0;
int max_tries = user_media_port ? 1 : 100;
media_port = user_media_port ? user_media_port : DEFAULT_MEDIA_PORT;
rtp_try_again:
if ((media_socket = socket(media_ip_is_ipv6 ? AF_INET6 : AF_INET,
SOCK_DGRAM, 0)) == -1) {
ERROR_NO("Unable to get the audio RTP socket (IP=%s, port=%d)",
Expand All @@ -1921,10 +1925,7 @@ int main(int argc, char *argv[])
media_ip, media_port + 2);
}

int try_counter;
int max_tries = user_media_port ? 1 : 100;
media_port = user_media_port ? user_media_port : DEFAULT_MEDIA_PORT;
for (try_counter = 0; try_counter < max_tries; try_counter++) {
for (; try_counter < max_tries; try_counter++) {
sockaddr_update_port(&media_sockaddr, media_port);

// Use get_host_and_port to remove square brackets from an
Expand Down Expand Up @@ -1956,8 +1957,15 @@ int main(int argc, char *argv[])

if (::bind(media_socket_video, (sockaddr*)&media_sockaddr,
socklen_from_addr(&media_sockaddr))) {
ERROR_NO("Unable to bind video RTP socket (IP=%s, port=%d)",
media_ip, media_port + 2);
try_counter++;
if (try_counter >= max_tries) {
ERROR_NO("Unable to bind video RTP socket (IP=%s, port=%d)",
media_ip, media_port + 2);
}
::close(media_socket);
::close(media_socket_video);
media_port += 3;
goto rtp_try_again;
}
/* Second socket bound */
}
Expand Down