Exemplo n.º 1
0
long EventLoop::earliest_expire_time()
{
    TimerPtr timer = timer_heap_.top();
    if (!timer)
        return -1;
    long delay = timer->expire_msec() - current_msec_;
    return (delay > 0) ? delay : 0;
}
Exemplo n.º 2
0
int EventLoop::get_ready_events()
{
    int nevents = expired_timers_.size() + fired_events_.size();
    if (nevents == 0) {
        long delta = current_msec_;
        long earliest = earliest_expire_time();
        nevents = poller_->dispatch(fired_events_, earliest);

        update_time();
        delta = current_msec_ - delta;
        if (delta) {
            TimerPtr timer = timer_heap_.top();
            while (timer && timer->expire_msec() <= current_msec_) {
                expired_timers_.push_back(timer);
                timer_heap_.pop();
                timer = timer_heap_.top();
                ++nevents;
            }
        }
    }
    return nevents;
}