If events are pending, process an unspecified number of them. If no events are pending, wait until one event is received and process this event (and possibly any other events received simultaneously). If processing an event removes a watch, there is a possibility that the watched event will still be reported (if it has occurred) before pull_events() returns. do_wait - if false, returns immediatel
| 590 | // do_wait - if false, returns immediately if no events are |
| 591 | // pending. |
| 592 | void pull_events(bool do_wait) |
| 593 | { |
| 594 | struct kevent events[16]; |
| 595 | struct timespec ts; |
| 596 | |
| 597 | // wait_ts remains null for an infinite wait; it is later set to either a 0 timeout |
| 598 | // if do_wait is false (or if we otherwise won't wait due to events being detected |
| 599 | // early) or is set to an appropriate timeout for the next timer's timeout. |
| 600 | struct timespec *wait_ts = nullptr; |
| 601 | |
| 602 | // Check whether any timers are pending, and what the next timeout is. |
| 603 | Base::lock.lock(); |
| 604 | this->process_monotonic_timers(do_wait, ts, wait_ts); |
| 605 | Base::lock.unlock(); |
| 606 | |
| 607 | if (! do_wait) { |
| 608 | ts.tv_sec = 0; |
| 609 | ts.tv_nsec = 0; |
| 610 | wait_ts = &ts; |
| 611 | } |
| 612 | |
| 613 | int r = kevent(kqfd, nullptr, 0, events, 16, wait_ts); |
| 614 | if (r == -1 || r == 0) { |
| 615 | // signal or no events |
| 616 | if (r == 0 && do_wait) { |
| 617 | // timeout: |
| 618 | Base::lock.lock(); |
| 619 | this->process_monotonic_timers(); |
| 620 | Base::lock.unlock(); |
| 621 | } |
| 622 | return; |
| 623 | } |
| 624 | |
| 625 | ts.tv_sec = 0; |
| 626 | ts.tv_nsec = 0; |
| 627 | |
| 628 | do { |
| 629 | process_events(events, r); |
| 630 | r = kevent(kqfd, nullptr, 0, events, 16, &ts); |
| 631 | } while (r > 0); |
| 632 | } |
| 633 | }; |
| 634 | |
| 635 | } // namespace v3 |
nothing calls this directly
no test coverage detected