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.
4 
5 #include "net/quic/platform/impl/quic_epoll_clock.h"
6 
7 #include "net/third_party/quiche/src/epoll_server/simple_epoll_server.h"
8 #include "net/third_party/quiche/src/quic/platform/api/quic_flag_utils.h"
9 #include "net/third_party/quiche/src/quic/platform/api/quic_flags.h"
10 
11 namespace quic {
12 
QuicEpollClock(epoll_server::SimpleEpollServer * epoll_server)13 QuicEpollClock::QuicEpollClock(epoll_server::SimpleEpollServer* epoll_server)
14     : epoll_server_(epoll_server), largest_time_(QuicTime::Zero()) {}
15 
~QuicEpollClock()16 QuicEpollClock::~QuicEpollClock() {}
17 
ApproximateNow() const18 QuicTime QuicEpollClock::ApproximateNow() const {
19   return CreateTimeFromMicroseconds(epoll_server_->ApproximateNowInUsec());
20 }
21 
Now() const22 QuicTime QuicEpollClock::Now() const {
23   QuicTime now = CreateTimeFromMicroseconds(epoll_server_->NowInUsec());
24 
25   if (now <= largest_time_) {
26     // Time not increasing, return |largest_time_|.
27     return largest_time_;
28   }
29 
30   largest_time_ = now;
31   return largest_time_;
32 }
33 
WallNow() const34 QuicWallTime QuicEpollClock::WallNow() const {
35   return QuicWallTime::FromUNIXMicroseconds(
36       epoll_server_->ApproximateNowInUsec());
37 }
38 
ConvertWallTimeToQuicTime(const QuicWallTime & walltime) const39 QuicTime QuicEpollClock::ConvertWallTimeToQuicTime(
40     const QuicWallTime& walltime) const {
41   return QuicTime::Zero() +
42          QuicTime::Delta::FromMicroseconds(walltime.ToUNIXMicroseconds());
43 }
44 
45 }  // namespace quic
46