LCOV - code coverage report
Current view: top level - source/common/quic - envoy_quic_alarm.cc (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 19 19 100.0 %
Date: 2024-01-05 06:35:25 Functions: 5 6 83.3 %

          Line data    Source code
       1             : #include "source/common/quic/envoy_quic_alarm.h"
       2             : 
       3             : #include <algorithm>
       4             : 
       5             : namespace Envoy {
       6             : namespace Quic {
       7             : 
       8             : EnvoyQuicAlarm::EnvoyQuicAlarm(Event::Dispatcher& dispatcher, const quic::QuicClock& clock,
       9             :                                quic::QuicArenaScopedPtr<quic::QuicAlarm::Delegate> delegate)
      10             :     : QuicAlarm(std::move(delegate)), dispatcher_(dispatcher),
      11        7725 :       timer_(dispatcher_.createTimer([this]() { Fire(); })), clock_(clock) {}
      12             : 
      13        1850 : void EnvoyQuicAlarm::CancelImpl() { timer_->disableTimer(); }
      14             : 
      15        2394 : void EnvoyQuicAlarm::SetImpl() {
      16        2394 :   quic::QuicTime::Delta duration = getDurationBeforeDeadline();
      17             :   // Round up the duration so that any duration < 1us will not be triggered within current event
      18             :   // loop. QUICHE alarm is not expected to be scheduled in current event loop. This bit is a bummer
      19             :   // in QUICHE, and we are working on the fix. Once QUICHE is fixed of expecting this behavior, we
      20             :   // no longer need to round up the duration.
      21             :   // TODO(antoniovicente) Remove the std::max(1, ...) when decommissioning the
      22             :   // envoy.reloadable_features.activate_timers_next_event_loop runtime flag.
      23        2394 :   timer_->enableHRTimer(
      24        2394 :       std::chrono::microseconds(std::max(static_cast<int64_t>(1), duration.ToMicroseconds())));
      25        2394 : }
      26             : 
      27         544 : void EnvoyQuicAlarm::UpdateImpl() {
      28             :   // Since Timer::enableTimer() overrides its deadline from previous calls,
      29             :   // there is no need to disable the timer before enabling it again.
      30         544 :   SetImpl();
      31         544 : }
      32             : 
      33        2394 : quic::QuicTime::Delta EnvoyQuicAlarm::getDurationBeforeDeadline() {
      34        2394 :   quic::QuicTime::Delta duration(quic::QuicTime::Delta::Zero());
      35        2394 :   quic::QuicTime now = clock_.ApproximateNow();
      36        2394 :   quic::QuicTime tmp = deadline();
      37        2394 :   if (tmp > now) {
      38        1786 :     duration = tmp - now;
      39        1786 :   }
      40        2394 :   return duration;
      41        2394 : }
      42             : 
      43             : } // namespace Quic
      44             : } // namespace Envoy

Generated by: LCOV version 1.15