From: Mike Brady Date: Tue, 20 Nov 2018 23:49:22 +0000 (+0000) Subject: Wait properly when a session is being interrupted. X-Git-Tag: 3.3RC0~156 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0529a581794b0789a136dfda6d2a129c406269cc;p=thirdparty%2Fshairport-sync.git Wait properly when a session is being interrupted. --- diff --git a/rtsp.c b/rtsp.c index 3dab2b34..36d269ae 100644 --- a/rtsp.c +++ b/rtsp.c @@ -1556,13 +1556,19 @@ static void handle_announce(rtsp_conn_info *conn, rtsp_message *req, rtsp_messag } if (should_wait) { - usleep(1000000); // here, it is possible for other connections to come in and nab the player. - debug(1, "Try to get the player now"); + useconds_t time_remaining = 3000000; // three seconds + + while ((time_remaining > 0) && (have_the_player == 0)) { + if (pthread_mutex_trylock(&play_lock) == 0) + have_the_player = 1; + else { + usleep(100000); + time_remaining -= 100000; + } + } + if (have_the_player == 0) + debug(1, "Connection %d: ANNOUNCE failed to get the player", conn->connection_number); } - if (pthread_mutex_trylock(&play_lock) == 0) - have_the_player = 1; - else - debug(1, "Connection %d: ANNOUNCE failed to get the player", conn->connection_number); } if (have_the_player) {