1
#include "source/common/quic/envoy_quic_clock.h"
2

            
3
namespace Envoy {
4
namespace Quic {
5

            
6
8820265
quic::QuicTime EnvoyQuicClock::ApproximateNow() const {
7
8820265
  return quic::QuicTime::Zero() + quic::QuicTime::Delta::FromMicroseconds(microsecondsSinceEpoch(
8
8820265
                                      dispatcher_.approximateMonotonicTime()));
9
8820265
}
10

            
11
2114634
quic::QuicTime EnvoyQuicClock::Now() const {
12
  // Since the expensive operation of obtaining time has to be performed anyway,
13
  // make Dispatcher update approximate time. Without this, alarms might fire
14
  // one event loop later. const_cast is necessary here because
15
  // updateApproximateMonotonicTime() is a non-const operation, and Now() is
16
  // conceptually const (even though this particular implementation has a
17
  // visible side effect). Changing Now() to non-const would necessitate
18
  // changing a number of other methods and members to non-const, which would
19
  // not increase clarity.
20
2114634
  const_cast<Event::Dispatcher&>(dispatcher_).updateApproximateMonotonicTime();
21
2114634
  return ApproximateNow();
22
2114634
}
23

            
24
167077
quic::QuicWallTime EnvoyQuicClock::WallNow() const {
25
167077
  return quic::QuicWallTime::FromUNIXMicroseconds(
26
167077
      microsecondsSinceEpoch(dispatcher_.timeSource().systemTime()));
27
167077
}
28

            
29
} // namespace Quic
30
} // namespace Envoy