- fd_set rfds, wfds;
- int ret, max_fileno, sbo = 0;
- char status_buf[STRINGSIZE] = "";
- struct timeval tv;
-repeat:
- FD_ZERO(&rfds);
- FD_ZERO(&wfds);
- max_fileno = 0;
- if (audiod_status != AUDIOD_ON)
- kill_all_decoders();
- else if (playing)
- start_current_receiver();
- max_fileno = set_stream_fds(&wfds);
- /* stat pipe (read) */
- if (stat_pipe >= 0 && audiod_status == AUDIOD_OFF)
- close_stat_pipe();
- if (stat_pipe < 0 && audiod_status != AUDIOD_OFF) {
- stat_pipe = open_stat_pipe();
- sbo = 0;
- status_buf[0] = '\0';
- }
- if (stat_pipe >= 0 && audiod_status != AUDIOD_OFF) {
- 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 */
- 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;
- ret = pre_select(&rfds, &wfds, &tv);
- 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,
- strerror(errno));