Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Side by Side Diff: net/tools/quic/test_tools/mock_epoll_server.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 13
14 FakeTimeEpollServer::~FakeTimeEpollServer() { 14 FakeTimeEpollServer::~FakeTimeEpollServer() {
15 } 15 }
16 16
17 int64 FakeTimeEpollServer::NowInUsec() const { 17 int64 FakeTimeEpollServer::NowInUsec() const {
18 return now_in_usec_; 18 return now_in_usec_;
19 } 19 }
20 20
21 MockEpollServer::MockEpollServer() : until_in_usec_(-1) { 21 MockEpollServer::MockEpollServer() : until_in_usec_(-1) {
22 } 22 }
23 23
24 MockEpollServer::~MockEpollServer() { 24 MockEpollServer::~MockEpollServer() {
25 } 25 }
26 26
27 int MockEpollServer::epoll_wait_impl(int epfd, 27 int MockEpollServer::epoll_wait_impl(int epfd,
28 struct epoll_event* events, 28 struct epoll_event* events,
29 int max_events, 29 int max_events,
30 int timeout_in_ms) { 30 int timeout_in_ms) {
31 int num_events = 0; 31 int num_events = 0;
32 while (!event_queue_.empty() && 32 while (!event_queue_.empty() && num_events < max_events &&
33 num_events < max_events &&
34 event_queue_.begin()->first <= NowInUsec() && 33 event_queue_.begin()->first <= NowInUsec() &&
35 ((until_in_usec_ == -1) || 34 ((until_in_usec_ == -1) ||
36 (event_queue_.begin()->first < until_in_usec_)) 35 (event_queue_.begin()->first < until_in_usec_))) {
37 ) {
38 int64 event_time_in_usec = event_queue_.begin()->first; 36 int64 event_time_in_usec = event_queue_.begin()->first;
39 events[num_events] = event_queue_.begin()->second; 37 events[num_events] = event_queue_.begin()->second;
40 if (event_time_in_usec > NowInUsec()) { 38 if (event_time_in_usec > NowInUsec()) {
41 set_now_in_usec(event_time_in_usec); 39 set_now_in_usec(event_time_in_usec);
42 } 40 }
43 event_queue_.erase(event_queue_.begin()); 41 event_queue_.erase(event_queue_.begin());
44 ++num_events; 42 ++num_events;
45 } 43 }
46 if (num_events == 0) { // then we'd have waited 'till the timeout. 44 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. 45 if (until_in_usec_ < 0) { // then we don't care what the final time is.
48 if (timeout_in_ms > 0) { 46 if (timeout_in_ms > 0) {
49 AdvanceBy(timeout_in_ms * 1000); 47 AdvanceBy(timeout_in_ms * 1000);
50 } 48 }
51 } else { // except we assume that we don't wait for the timeout 49 } else { // except we assume that we don't wait for the timeout
52 // period if until_in_usec_ is a positive number. 50 // period if until_in_usec_ is a positive number.
53 set_now_in_usec(until_in_usec_); 51 set_now_in_usec(until_in_usec_);
54 // And reset until_in_usec_ to signal no waiting (as 52 // And reset until_in_usec_ to signal no waiting (as
55 // the AdvanceByExactly* stuff is meant to be one-shot, 53 // the AdvanceByExactly* stuff is meant to be one-shot,
56 // as are all similar EpollServer functions) 54 // as are all similar EpollServer functions)
57 until_in_usec_ = -1; 55 until_in_usec_ = -1;
58 } 56 }
59 } 57 }
60 if (until_in_usec_ >= 0) { 58 if (until_in_usec_ >= 0) {
61 CHECK(until_in_usec_ >= NowInUsec()); 59 CHECK(until_in_usec_ >= NowInUsec());
62 } 60 }
63 return num_events; 61 return num_events;
64 } 62 }
65 63
66 } // namespace test 64 } // namespace test
67 } // namespace tools 65 } // namespace tools
68 } // namespace net 66 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698