This source file includes following definitions.
- NowInUsec
- epoll_wait_impl
#include "net/tools/quic/test_tools/mock_epoll_server.h"
namespace net {
namespace tools {
namespace test {
FakeTimeEpollServer::FakeTimeEpollServer(): now_in_usec_(0) {
}
FakeTimeEpollServer::~FakeTimeEpollServer() {
}
int64 FakeTimeEpollServer::NowInUsec() const {
return now_in_usec_;
}
MockEpollServer::MockEpollServer() : until_in_usec_(-1) {
}
MockEpollServer::~MockEpollServer() {
}
int MockEpollServer::epoll_wait_impl(int epfd,
struct epoll_event* events,
int max_events,
int timeout_in_ms) {
int num_events = 0;
while (!event_queue_.empty() &&
num_events < max_events &&
event_queue_.begin()->first <= NowInUsec() &&
((until_in_usec_ == -1) ||
(event_queue_.begin()->first < until_in_usec_))
) {
int64 event_time_in_usec = event_queue_.begin()->first;
events[num_events] = event_queue_.begin()->second;
if (event_time_in_usec > NowInUsec()) {
set_now_in_usec(event_time_in_usec);
}
event_queue_.erase(event_queue_.begin());
++num_events;
}
if (num_events == 0) {
if (until_in_usec_ < 0) {
if (timeout_in_ms > 0) {
AdvanceBy(timeout_in_ms * 1000);
}
} else {
set_now_in_usec(until_in_usec_);
until_in_usec_ = -1;
}
}
if (until_in_usec_ >= 0) {
CHECK(until_in_usec_ >= NowInUsec());
}
return num_events;
}
}
}
}