]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Move closing of ports to the player thread cleanup. They can be bound without the...
authorMike Brady <mikebrady@eircom.net>
Thu, 29 Nov 2018 22:03:49 +0000 (22:03 +0000)
committerMike Brady <mikebrady@eircom.net>
Thu, 29 Nov 2018 22:03:49 +0000 (22:03 +0000)
player.c
rtp.c

index 57d7527b90f9351d66b94cb362202ac8efe784c5..9c0482c737effb003c3f1af68d252de763ca2abe 100644 (file)
--- 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 b8b1ea5b44eb13a12f32bb4dd0cad35835607794..0de094c677b63cc0ca2deda05e78e5443276534d 100644 (file)
--- 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);
 }