Logo Search packages:      
Sourcecode: dbus version File versions

int _dbus_poll ( DBusPollFD fds,
int  n_fds,
int  timeout_milliseconds 
)

Wrapper for poll().

Parameters:
fds the file descriptors to poll
n_fds number of descriptors in the array
timeout_milliseconds timeout or -1 for infinite
Returns:
numbers of fds with revents, or <0 on error

Definition at line 1923 of file dbus-sysdeps.c.

References _dbus_warn(), DBusPollFD::events, DBusPollFD::fd, and DBusPollFD::revents.

Referenced by unix_do_iteration().

{
#ifdef HAVE_POLL
  /* This big thing is a constant expression and should get optimized
   * out of existence. So it's more robust than a configure check at
   * no cost.
   */
  if (_DBUS_POLLIN == POLLIN &&
      _DBUS_POLLPRI == POLLPRI &&
      _DBUS_POLLOUT == POLLOUT &&
      _DBUS_POLLERR == POLLERR &&
      _DBUS_POLLHUP == POLLHUP &&
      _DBUS_POLLNVAL == POLLNVAL &&
      sizeof (DBusPollFD) == sizeof (struct pollfd) &&
      _DBUS_STRUCT_OFFSET (DBusPollFD, fd) ==
      _DBUS_STRUCT_OFFSET (struct pollfd, fd) &&
      _DBUS_STRUCT_OFFSET (DBusPollFD, events) ==
      _DBUS_STRUCT_OFFSET (struct pollfd, events) &&
      _DBUS_STRUCT_OFFSET (DBusPollFD, revents) ==
      _DBUS_STRUCT_OFFSET (struct pollfd, revents))
    {
      return poll ((struct pollfd*) fds,
                   n_fds, 
                   timeout_milliseconds);
    }
  else
    {
      /* We have to convert the DBusPollFD to an array of
       * struct pollfd, poll, and convert back.
       */
      _dbus_warn ("didn't implement poll() properly for this system yet\n");
      return -1;
    }
#else /* ! HAVE_POLL */

  fd_set read_set, write_set, err_set;
  int max_fd = 0;
  int i;
  struct timeval tv;
  int ready;
  
  FD_ZERO (&read_set);
  FD_ZERO (&write_set);
  FD_ZERO (&err_set);

  for (i = 0; i < n_fds; i++)
    {
      DBusPollFD f = fds[i];

      if (f.events & _DBUS_POLLIN)
      FD_SET (f.fd, &read_set);

      if (f.events & _DBUS_POLLOUT)
      FD_SET (f.fd, &write_set);

      FD_SET (f.fd, &err_set);

      max_fd = MAX (max_fd, f.fd);
    }
    
  tv.tv_sec = timeout_milliseconds / 1000;
  tv.tv_usec = (timeout_milliseconds % 1000) * 1000;

  ready = select (max_fd + 1, &read_set, &write_set, &err_set, &tv);

  if (ready > 0)
    {
      for (i = 0; i < n_fds; i++)
      {
        DBusPollFD f = fds[i];

        f.revents = 0;

        if (FD_ISSET (f.fd, &read_set))
          f.revents |= _DBUS_POLLIN;

        if (FD_ISSET (f.fd, &write_set))
          f.revents |= _DBUS_POLLOUT;

        if (FD_ISSET (f.fd, &err_set))
          f.revents |= _DBUS_POLLERR;
      }
    }

  return ready;
#endif
}


Generated by  Doxygen 1.6.0   Back to index