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 #ifndef NET_QUIC_PLATFORM_IMPL_QUIC_EPOLL_CLOCK_H_ 6 #define NET_QUIC_PLATFORM_IMPL_QUIC_EPOLL_CLOCK_H_ 7 8 #include "base/compiler_specific.h" 9 #include "base/macros.h" 10 #include "net/third_party/quiche/src/quic/core/quic_clock.h" 11 #include "net/third_party/quiche/src/quic/core/quic_time.h" 12 13 namespace epoll_server { 14 15 class SimpleEpollServer; 16 17 } // namespace epoll_server 18 19 namespace quic { 20 21 // Clock to efficiently retrieve an approximately accurate time from an 22 // net::EpollServer. 23 class QuicEpollClock : public QuicClock { 24 public: 25 explicit QuicEpollClock(epoll_server::SimpleEpollServer* epoll_server); 26 ~QuicEpollClock() override; 27 28 // Returns the approximate current time as a QuicTime object. 29 QuicTime ApproximateNow() const override; 30 31 // Returns the current time as a QuicTime object. 32 // Note: this uses significant resources, please use only if needed. 33 QuicTime Now() const override; 34 35 // Returns the current time as a QuicWallTime object. 36 // Note: this uses significant resources, please use only if needed. 37 QuicWallTime WallNow() const override; 38 39 // Override to do less work in this implementation. The epoll clock is 40 // already based on system (unix epoch) time, no conversion required. 41 QuicTime ConvertWallTimeToQuicTime( 42 const QuicWallTime& walltime) const override; 43 44 protected: 45 epoll_server::SimpleEpollServer* epoll_server_; 46 // Largest time returned from Now() so far. 47 mutable QuicTime largest_time_; 48 49 private: 50 DISALLOW_COPY_AND_ASSIGN(QuicEpollClock); 51 }; 52 53 } // namespace quic 54 55 #endif // NET_QUIC_PLATFORM_IMPL_QUIC_EPOLL_CLOCK_H_ 56