]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - audiod.c
Minor audiod mainloop cleanup
[paraslash.git] / audiod.c
index 56d022fac1c3293ef303f819515941261c8f1777..695a6cfd32077e0ee0477078076ab2f8b8f11d29 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -1520,7 +1520,7 @@ static int open_stat_pipe(void)
        return ret;
 }
 
        return ret;
 }
 
-static int pre_select(fd_set *rfds, fd_set *wfds, struct timeval *tv)
+static int audiod_pre_select(fd_set *rfds, fd_set *wfds, struct timeval *tv)
 {
        int i, ret, max = -1;
 
 {
        int i, ret, max = -1;
 
@@ -1571,15 +1571,21 @@ static void __noreturn audiod_mainloop(void)
        char status_buf[STRINGSIZE] = "";
        struct timeval tv;
 repeat:
        char status_buf[STRINGSIZE] = "";
        struct timeval tv;
 repeat:
-       FD_ZERO(&rfds);
        FD_ZERO(&wfds);
        FD_ZERO(&wfds);
-       max_fileno = 0;
+       FD_ZERO(&rfds);
+       /* always check signal pipe and the local socket */
+       FD_SET(signal_pipe, &rfds);
+       max_fileno = signal_pipe;
+       FD_SET(audiod_socket, &rfds);
+       max_fileno = MAX(max_fileno, audiod_socket);
+
        if (audiod_status != AUDIOD_ON)
                kill_all_decoders();
        else if (playing)
                start_current_receiver();
        if (audiod_status != AUDIOD_ON)
                kill_all_decoders();
        else if (playing)
                start_current_receiver();
-       max_fileno = set_stream_fds(&wfds);
-       /* stat pipe (read) */
+
+       max_fileno = MAX(max_fileno, set_stream_fds(&wfds));
+       /* status pipe */
        if (stat_pipe >= 0 && audiod_status == AUDIOD_OFF)
                close_stat_pipe();
        if (stat_pipe < 0 && audiod_status != AUDIOD_OFF) {
        if (stat_pipe >= 0 && audiod_status == AUDIOD_OFF)
                close_stat_pipe();
        if (stat_pipe < 0 && audiod_status != AUDIOD_OFF) {
@@ -1591,18 +1597,12 @@ repeat:
                FD_SET(stat_pipe, &rfds);
                max_fileno = MAX(max_fileno, stat_pipe);
        }
                FD_SET(stat_pipe, &rfds);
                max_fileno = MAX(max_fileno, stat_pipe);
        }
-       /* always check signal pipe */
-       FD_SET(signal_pipe, &rfds);
-       max_fileno = MAX(max_fileno, signal_pipe);
        /* local socket */
        /* local socket */
-       if (audiod_socket < 0)
-               audiod_get_socket(); /* doesn't return on errors */
-       FD_SET(audiod_socket, &rfds);
-       max_fileno = MAX(max_fileno, audiod_socket);
        tv.tv_sec = 0;
        tv.tv_usec = 200 * 1000;
        tv.tv_sec = 0;
        tv.tv_usec = 200 * 1000;
-       ret = pre_select(&rfds, &wfds, &tv);
+       ret = audiod_pre_select(&rfds, &wfds, &tv);
        max_fileno = MAX(max_fileno, ret);
        max_fileno = MAX(max_fileno, ret);
+
        ret = select(max_fileno + 1, &rfds, &wfds, NULL, &tv);
        if (ret < 0 && errno != EINTR)
                PARA_ERROR_LOG("select returned %d (%s)\n", ret,
        ret = select(max_fileno + 1, &rfds, &wfds, NULL, &tv);
        if (ret < 0 && errno != EINTR)
                PARA_ERROR_LOG("select returned %d (%s)\n", ret,
@@ -1690,5 +1690,6 @@ int __noreturn main(int argc, char *argv[])
        setup_signal_handling();
        if (conf.daemon_given)
                daemon_init();
        setup_signal_handling();
        if (conf.daemon_given)
                daemon_init();
+       audiod_get_socket(); /* doesn't return on errors */
        audiod_mainloop();
 }
        audiod_mainloop();
 }