We started redesigning GpuMemoryBuffer interface to handle multiple buffers [0].
[chromium-blink-merge.git] / net / tools / quic / test_tools / mock_epoll_server.cc
blob4101c5e9ab023a0f5624e989065ca993be3b3eff
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"
7 namespace net {
8 namespace tools {
9 namespace test {
11 FakeTimeEpollServer::FakeTimeEpollServer(): now_in_usec_(0) {
14 FakeTimeEpollServer::~FakeTimeEpollServer() {
17 int64 FakeTimeEpollServer::NowInUsec() const {
18 return now_in_usec_;
21 MockEpollServer::MockEpollServer() : until_in_usec_(-1) {
24 MockEpollServer::~MockEpollServer() {
27 int MockEpollServer::epoll_wait_impl(int epfd,
28 struct epoll_event* events,
29 int max_events,
30 int timeout_in_ms) {
31 int num_events = 0;
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_))
37 ) {
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());
44 ++num_events;
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)
57 until_in_usec_ = -1;
60 if (until_in_usec_ >= 0) {
61 CHECK(until_in_usec_ >= NowInUsec());
63 return num_events;
66 } // namespace test
67 } // namespace tools
68 } // namespace net