]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Move UDP port cloure to the RTSP thread, don't allow calls to mdns_* to be cancelled...
authorMike Brady <mikebrady@eircom.net>
Fri, 30 Nov 2018 14:55:04 +0000 (14:55 +0000)
committerMike Brady <mikebrady@eircom.net>
Fri, 30 Nov 2018 14:55:04 +0000 (14:55 +0000)
player.c
rtp.c
rtsp.c

index 9c0482c737effb003c3f1af68d252de763ca2abe..cd9a9b8d916cf9372e4f232792e8c4ac374b2c88 100644 (file)
--- a/player.c
+++ b/player.c
@@ -1448,14 +1448,6 @@ 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;
@@ -1736,7 +1728,9 @@ void *player_thread_func(void *arg) {
 
   pthread_cleanup_push(player_thread_cleanup_handler, arg); // undo what's been done so far
 
-// stop looking elsewhere for DACP stuff
+  // stop looking elsewhere for DACP stuff
+  int oldState;
+  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState);
 
 #ifdef CONFIG_DACP_CLIENT
   // debug(1, "Set dacp server info");
@@ -1753,6 +1747,7 @@ void *player_thread_func(void *arg) {
     // almost certainly, this has pthread cancellation points in it -- beware
     conn->dapo_private_storage = mdns_dacp_monitor(conn->dacp_id);
 #endif
+  pthread_setcancelstate(oldState, NULL);
 
   // set the default volume to whaterver it was before, as stored in the config airplay_volume
   debug(2, "Set initial volume to %f.", config.airplay_volume);
diff --git a/rtp.c b/rtp.c
index 0de094c677b63cc0ca2deda05e78e5443276534d..1da6097f0558b940546fe1b8272dba49607e3fd2 100644 (file)
--- a/rtp.c
+++ b/rtp.c
@@ -847,13 +847,15 @@ static uint16_t bind_port(int ip_family, const char *self_ip_address, uint32_t s
   if (local_socket == -1)
     die("Could not allocate a socket.");
 
-  int val = 1;
-  ret = setsockopt(local_socket, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
-  if (ret < 0) {
-    char errorstring[1024];
-    strerror_r(errno, (char *)errorstring, sizeof(errorstring));
-    debug(1, "Error %d: \"%s\". Couldn't set SO_REUSEADDR");
-  }
+  /*
+    int val = 1;
+    ret = setsockopt(local_socket, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
+    if (ret < 0) {
+      char errorstring[1024];
+      strerror_r(errno, (char *)errorstring, sizeof(errorstring));
+      debug(1, "Error %d: \"%s\". Couldn't set SO_REUSEADDR");
+    }
+  */
 
   SOCKADDR myaddr;
   int tryCount = 0;
diff --git a/rtsp.c b/rtsp.c
index f383168368c3f972b809f1995e72d445634d0f7e..0b3625bd732afc8336e9d8c1ac75d6f216bdce04 100644 (file)
--- a/rtsp.c
+++ b/rtsp.c
@@ -555,18 +555,21 @@ enum rtsp_read_request_response rtsp_read_request(rtsp_conn_info *conn, rtsp_mes
   int msg_size = -1;
 
   while (msg_size < 0) {
-    fd_set readfds;
-    FD_ZERO(&readfds);
-    FD_SET(conn->fd, &readfds);
-    do {
-      memory_barrier();
-    } while (conn->stop == 0 &&
-             pselect(conn->fd + 1, &readfds, NULL, NULL, NULL, &pselect_sigset) <= 0);
+    /*
+fd_set readfds;
+FD_ZERO(&readfds);
+FD_SET(conn->fd, &readfds);
+do {
+  memory_barrier();
+} while (conn->stop == 0 &&
+         pselect(conn->fd + 1, &readfds, NULL, NULL, NULL, &pselect_sigset) <= 0);
+*/
     if (conn->stop != 0) {
       debug(3, "RTSP conversation thread %d shutdown requested.", conn->connection_number);
       reply = rtsp_read_request_response_immediate_shutdown_requested;
       goto shutdown;
     }
+
     nread = read(conn->fd, buf + inbuf, buflen - inbuf);
 
     if (nread == 0) {
@@ -640,6 +643,8 @@ enum rtsp_read_request_response rtsp_read_request(rtsp_conn_info *conn, rtsp_mes
         warning_message_sent = 1;
       }
     }
+
+    /*
     fd_set readfds;
     FD_ZERO(&readfds);
     FD_SET(conn->fd, &readfds);
@@ -647,6 +652,8 @@ enum rtsp_read_request_response rtsp_read_request(rtsp_conn_info *conn, rtsp_mes
       memory_barrier();
     } while (conn->stop == 0 &&
              pselect(conn->fd + 1, &readfds, NULL, NULL, NULL, &pselect_sigset) <= 0);
+    */
+
     if (conn->stop != 0) {
       debug(1, "RTSP shutdown requested.");
       reply = rtsp_read_request_response_immediate_shutdown_requested;
@@ -2070,6 +2077,14 @@ void rtsp_conversation_thread_cleanup_function(void *arg) {
   if (conn->player_thread)
     player_stop(conn);
 
+  debug(3, "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->fd > 0) {
     debug(3, "Connection %d: closing fd %d.", conn->connection_number, conn->fd);
     close(conn->fd);
@@ -2517,7 +2532,7 @@ void rtsp_listen_loop(void) {
       //      conn->thread = rtsp_conversation_thread;
       //      conn->stop = 0; // record's memory has been zeroed
       //      conn->authorized = 0; // record's memory has been zeroed
-      fcntl(conn->fd, F_SETFL, O_NONBLOCK);
+      // fcntl(conn->fd, F_SETFL, O_NONBLOCK);
 
       ret = pthread_create(&conn->thread, NULL, rtsp_conversation_thread_func,
                            conn); // also acts as a memory barrier