Example #1
0
int KqueuPoller::Poll(EventLoop& loop , struct timespec& timeout) {
  int retval = 0;
  if (timeout.tv_sec == 0 && timeout.tv_nsec == 0) {
    retval = kevent(kqueufd_, NULL, 0, kevent_ptr_, kEventSize, NULL);
  } else {
    retval = kevent(kqueufd_, NULL, 0, kevent_ptr_, kEventSize, &timeout);
  }
  if (retval > 0) {
    for (int i = 0; i < retval; ++i) {
      ActiveEvent ae;
      ae.mask = 0;
      ae.fd = kevent_ptr_[i].ident;
      if (kevent_ptr_[i].filter == EVFILT_READ) ae.mask |= READABLE;
      if (kevent_ptr_[i].filter == EVFILT_WRITE) ae.mask |= WRITABLE;
      loop.PollData().push_back(ae);
    }
  }
  return retval;
}