Logo Search packages:      
Sourcecode: libmpdclient version File versions  Download package

enum mpd_idle mpd_recv_idle ( struct mpd_connection connection,
bool  disable_timeout 
)

Waits until MPD sends the list of idle events and returns it in a bit mask.

Parameters:
connection the connection to MPD
disable_timeout if true, then libmpdclients temporarily disables the configured timeout (see mpd_connection_set_timeout()): this function blocks forever, until either MPD sends a response, or an error occurs.
Returns:
the event bit mask, or 0 on error or if there were no events

Definition at line 91 of file idle.c.

References mpd_idle_parse_pair(), mpd_recv_idle(), mpd_recv_pair(), mpd_return_pair(), and mpd_connection::timeout.

Referenced by mpd_recv_idle(), mpd_run_idle(), mpd_run_idle_mask(), and mpd_run_noidle().

{
      enum mpd_idle flags = 0;
      struct mpd_pair *pair;
      struct timeval old_timeout;

      assert(connection != NULL);

      /* temporarily disable the connection timeout */
      if (disable_timeout) {
            /* make sure that the output buffer is empty before we
               turn off the timeout - this is important because we
               want to detect a send failure more quickly */
            if (!mpd_flush(connection))
                  return 0;

            old_timeout = connection->timeout;
            connection->timeout = (struct timeval){
                  .tv_sec = 0,
                  .tv_usec = 0,
            };
      } else {
            /* work around bogus gcc warning "may be used
               uninitialized"; gcc is too dumb to see that we're
               accessing old_timeout only if it was initialized */
            old_timeout = (struct timeval){
                  .tv_sec = 0,
                  .tv_usec = 0,
            };
      }

      while ((pair = mpd_recv_pair(connection)) != NULL) {
            flags |= mpd_idle_parse_pair(pair);

            mpd_return_pair(connection, pair);
      }

      /* re-enable timeout */
      if (disable_timeout)
            connection->timeout = old_timeout;

      return flags;
}


Generated by  Doxygen 1.6.0   Back to index