OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/tools/quic/test_tools/mock_epoll_server.h" | 5 #include "net/tools/quic/test_tools/mock_epoll_server.h" |
6 | 6 |
7 namespace net { | 7 namespace net { |
8 namespace tools { | 8 namespace tools { |
9 namespace test { | 9 namespace test { |
10 | 10 |
11 FakeTimeEpollServer::FakeTimeEpollServer() : now_in_usec_(0) {} | 11 FakeTimeEpollServer::FakeTimeEpollServer() : now_in_usec_(0) {} |
12 | 12 |
13 FakeTimeEpollServer::~FakeTimeEpollServer() {} | 13 FakeTimeEpollServer::~FakeTimeEpollServer() {} |
14 | 14 |
15 int64 FakeTimeEpollServer::NowInUsec() const { | 15 int64_t FakeTimeEpollServer::NowInUsec() const { |
16 return now_in_usec_; | 16 return now_in_usec_; |
17 } | 17 } |
18 | 18 |
19 MockEpollServer::MockEpollServer() : until_in_usec_(-1) {} | 19 MockEpollServer::MockEpollServer() : until_in_usec_(-1) {} |
20 | 20 |
21 MockEpollServer::~MockEpollServer() {} | 21 MockEpollServer::~MockEpollServer() {} |
22 | 22 |
23 int MockEpollServer::epoll_wait_impl(int epfd, | 23 int MockEpollServer::epoll_wait_impl(int epfd, |
24 struct epoll_event* events, | 24 struct epoll_event* events, |
25 int max_events, | 25 int max_events, |
26 int timeout_in_ms) { | 26 int timeout_in_ms) { |
27 int num_events = 0; | 27 int num_events = 0; |
28 while (!event_queue_.empty() && num_events < max_events && | 28 while (!event_queue_.empty() && num_events < max_events && |
29 event_queue_.begin()->first <= NowInUsec() && | 29 event_queue_.begin()->first <= NowInUsec() && |
30 ((until_in_usec_ == -1) || | 30 ((until_in_usec_ == -1) || |
31 (event_queue_.begin()->first < until_in_usec_))) { | 31 (event_queue_.begin()->first < until_in_usec_))) { |
32 int64 event_time_in_usec = event_queue_.begin()->first; | 32 int64_t event_time_in_usec = event_queue_.begin()->first; |
33 events[num_events] = event_queue_.begin()->second; | 33 events[num_events] = event_queue_.begin()->second; |
34 if (event_time_in_usec > NowInUsec()) { | 34 if (event_time_in_usec > NowInUsec()) { |
35 set_now_in_usec(event_time_in_usec); | 35 set_now_in_usec(event_time_in_usec); |
36 } | 36 } |
37 event_queue_.erase(event_queue_.begin()); | 37 event_queue_.erase(event_queue_.begin()); |
38 ++num_events; | 38 ++num_events; |
39 } | 39 } |
40 if (num_events == 0) { // then we'd have waited 'till the timeout. | 40 if (num_events == 0) { // then we'd have waited 'till the timeout. |
41 if (until_in_usec_ < 0) { // then we don't care what the final time is. | 41 if (until_in_usec_ < 0) { // then we don't care what the final time is. |
42 if (timeout_in_ms > 0) { | 42 if (timeout_in_ms > 0) { |
(...skipping 10 matching lines...) Expand all Loading... |
53 } | 53 } |
54 if (until_in_usec_ >= 0) { | 54 if (until_in_usec_ >= 0) { |
55 CHECK(until_in_usec_ >= NowInUsec()); | 55 CHECK(until_in_usec_ >= NowInUsec()); |
56 } | 56 } |
57 return num_events; | 57 return num_events; |
58 } | 58 } |
59 | 59 |
60 } // namespace test | 60 } // namespace test |
61 } // namespace tools | 61 } // namespace tools |
62 } // namespace net | 62 } // namespace net |
OLD | NEW |