From: Mike Brady Date: Thu, 29 Nov 2018 22:03:49 +0000 (+0000) Subject: Move closing of ports to the player thread cleanup. They can be bound without the... X-Git-Tag: 3.3RC0~124 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0eac2b9cb3664235f8fb30481d48983553a14f77;p=thirdparty%2Fshairport-sync.git Move closing of ports to the player thread cleanup. They can be bound without the UDP threads ever having been called, so they must be closed when the player thread exits. --- diff --git a/player.c b/player.c index 57d7527b..9c0482c7 100644 --- a/player.c +++ b/player.c @@ -1448,6 +1448,14 @@ void player_thread_cleanup_handler(void *arg) { pthread_join(conn->rtp_audio_thread, NULL); debug(2, "Audio thread terminated."); + debug(2, "Closing timing, control and audio sockets..."); + if (conn->control_socket) + close(conn->control_socket); + if (conn->timing_socket) + close(conn->timing_socket); + if (conn->audio_socket) + close(conn->audio_socket); + if (conn->outbuf) { free(conn->outbuf); conn->outbuf = NULL; diff --git a/rtp.c b/rtp.c index b8b1ea5b..0de094c6 100644 --- a/rtp.c +++ b/rtp.c @@ -97,16 +97,8 @@ uint64_t local_to_remote_time_difference_now(rtsp_conn_info *conn) { return conn->local_to_remote_time_difference + (uint64_t)(drift * (uint64_t)0x100000000); } -void rtp_audio_receiver_cleanup_handler(void *arg) { - int oldState; - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState); - debug(3, "Audio Receiver Cleanup."); - rtsp_conn_info *conn = (rtsp_conn_info *)arg; - debug(3, "Close Audio Socket."); - close(conn->audio_socket); - debug(3, "Audio Receiver Cleanup Successful."); - usleep(20000); // microseconds - pthread_setcancelstate(oldState, NULL); +void rtp_audio_receiver_cleanup_handler(__attribute__((unused)) void *arg) { + debug(3, "Audio Receiver Cleanup Done."); } void *rtp_audio_receiver(void *arg) { @@ -240,18 +232,8 @@ void *rtp_audio_receiver(void *arg) { pthread_exit(NULL); } -void rtp_control_handler_cleanup_handler(void *arg) { - int oldState; - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState); - debug(3, "Control Receiver Cleanup."); - rtsp_conn_info *conn = (rtsp_conn_info *)arg; - debug(3, "Shut Down Control Socket."); - shutdown(conn->control_socket, SHUT_RDWR); - debug(3, "Close Control Socket."); - close(conn->control_socket); - debug(3, "Control Receiver Cleanup Successful."); - usleep(20000); // microseconds - pthread_setcancelstate(oldState, NULL); +void rtp_control_handler_cleanup_handler(__attribute__((unused)) void *arg) { + debug(3, "Control Receiver Cleanup Done."); } void *rtp_control_receiver(void *arg) { @@ -564,18 +546,15 @@ void *rtp_timing_sender(void *arg) { } void rtp_timing_receiver_cleanup_handler(void *arg) { - int oldState; - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState); debug(3, "Timing Receiver Cleanup."); rtsp_conn_info *conn = (rtsp_conn_info *)arg; debug(3, "Cancel Timing Requester."); pthread_cancel(conn->timer_requester); + int oldState; + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState); debug(3, "Join Timing Requester."); pthread_join(conn->timer_requester, NULL); - debug(3, "Close Timing Socket."); - close(conn->timing_socket); debug(3, "Timing Receiver Cleanup Successful."); - usleep(20000); // microseconds pthread_setcancelstate(oldState, NULL); }