1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/tools/quic/test_tools/mock_epoll_server.h"
11 FakeTimeEpollServer::FakeTimeEpollServer(): now_in_usec_(0) {
14 FakeTimeEpollServer::~FakeTimeEpollServer() {
17 int64
FakeTimeEpollServer::NowInUsec() const {
21 MockEpollServer::MockEpollServer() : until_in_usec_(-1) {
24 MockEpollServer::~MockEpollServer() {
27 int MockEpollServer::epoll_wait_impl(int epfd
,
28 struct epoll_event
* events
,
32 while (!event_queue_
.empty() &&
33 num_events
< max_events
&&
34 event_queue_
.begin()->first
<= NowInUsec() &&
35 ((until_in_usec_
== -1) ||
36 (event_queue_
.begin()->first
< until_in_usec_
))
38 int64 event_time_in_usec
= event_queue_
.begin()->first
;
39 events
[num_events
] = event_queue_
.begin()->second
;
40 if (event_time_in_usec
> NowInUsec()) {
41 set_now_in_usec(event_time_in_usec
);
43 event_queue_
.erase(event_queue_
.begin());
46 if (num_events
== 0) { // then we'd have waited 'till the timeout.
47 if (until_in_usec_
< 0) { // then we don't care what the final time is.
48 if (timeout_in_ms
> 0) {
49 AdvanceBy(timeout_in_ms
* 1000);
51 } else { // except we assume that we don't wait for the timeout
52 // period if until_in_usec_ is a positive number.
53 set_now_in_usec(until_in_usec_
);
54 // And reset until_in_usec_ to signal no waiting (as
55 // the AdvanceByExactly* stuff is meant to be one-shot,
56 // as are all similar EpollServer functions)
60 if (until_in_usec_
>= 0) {
61 CHECK(until_in_usec_
>= NowInUsec());