proxygen
folly::HHWheelTimer::Callback Class Referenceabstract

#include <HHWheelTimer.h>

Inheritance diagram for folly::HHWheelTimer::Callback:
proxygen::HTTP2PriorityQueue::Node proxygen::HTTPSession::DrainTimeout proxygen::HTTPSession::FlowControlTimeout proxygen::HTTPSession::WriteTimeout proxygen::HTTPTransaction proxygen::HTTPTransaction::RateLimitCallback wangle::ManagedConnection proxygen::MockHTTPTransaction proxygen::HTTPSessionBase TestConnection wangle::AcceptorHandshakeManager wangle::ServerAcceptor< Pipeline >::ServerConnection proxygen::HTTPSession wangle::PeekingAcceptorHandshakeManager proxygen::HTTPDownstreamSession proxygen::HTTPUpstreamSession

Public Member Functions

 Callback ()=default
 
virtual ~Callback ()
 
virtual void timeoutExpired () noexcept=0
 
virtual void callbackCanceled () noexcept
 
void cancelTimeout ()
 
bool isScheduled () const
 
std::chrono::milliseconds getTimeRemaining ()
 

Protected Member Functions

virtual std::chrono::steady_clock::time_point getCurTime ()
 

Private Types

typedef boost::intrusive::list< Callback, boost::intrusive::constant_time_size< false > > List
 

Private Member Functions

std::chrono::milliseconds getTimeRemaining (std::chrono::steady_clock::time_point now) const
 
void setScheduled (HHWheelTimer *wheel, std::chrono::milliseconds)
 
void cancelTimeoutImpl ()
 

Private Attributes

HHWheelTimerwheel_ {nullptr}
 
std::chrono::steady_clock::time_point expiration_ {}
 
int bucket_ {-1}
 
std::shared_ptr< RequestContextrequestContext_
 

Friends

class HHWheelTimer
 

Detailed Description

A callback to be notified when a timeout has expired.

Definition at line 68 of file HHWheelTimer.h.

Member Typedef Documentation

typedef boost::intrusive:: list<Callback, boost::intrusive::constant_time_size<false> > folly::HHWheelTimer::Callback::List
private

Definition at line 145 of file HHWheelTimer.h.

Constructor & Destructor Documentation

folly::HHWheelTimer::Callback::Callback ( )
default
Callback::~Callback ( )
virtual

Definition at line 46 of file HHWheelTimer.cpp.

References cancelTimeout(), and isScheduled().

46  {
47  if (isScheduled()) {
48  cancelTimeout();
49  }
50 }

Member Function Documentation

virtual void folly::HHWheelTimer::Callback::callbackCanceled ( )
inlinevirtualnoexcept

This callback was canceled. The default implementation is to just proxy to timeoutExpired but if you care about the difference between the timeout finishing or being canceled you can override this.

Reimplemented in proxygen::HTTPTransaction::RateLimitCallback.

Definition at line 83 of file HHWheelTimer.h.

References timeoutExpired().

83  {
85  }
virtual void timeoutExpired() noexcept=0
void Callback::cancelTimeoutImpl ( )
private

Definition at line 63 of file HHWheelTimer.cpp.

References folly::HHWheelTimer::bitmap_, bucket_, folly::HHWheelTimer::buckets_, folly::HHWheelTimer::count_, expiration_, folly::makeBitIterator(), and wheel_.

Referenced by cancelTimeout(), and getTimeRemaining().

63  {
64  if (--wheel_->count_ <= 0) {
65  assert(wheel_->count_ == 0);
66  wheel_->AsyncTimeout::cancelTimeout();
67  }
68  unlink();
69  if ((-1 != bucket_) && (wheel_->buckets_[0][bucket_].empty())) {
70  auto bi = makeBitIterator(wheel_->bitmap_.begin());
71  *(bi + bucket_) = false;
72  }
73 
74  wheel_ = nullptr;
75  expiration_ = {};
76 }
BitIterator< BaseIter > makeBitIterator(const BaseIter &iter)
Definition: BitIterator.h:161
std::vector< std::size_t > bitmap_
Definition: HHWheelTimer.h:292
CallbackList buckets_[WHEEL_BUCKETS][WHEEL_SIZE]
Definition: HHWheelTimer.h:291
std::chrono::steady_clock::time_point expiration_
Definition: HHWheelTimer.h:140
std::size_t count_
Definition: HHWheelTimer.h:301
virtual std::chrono::steady_clock::time_point folly::HHWheelTimer::Callback::getCurTime ( )
inlineprotectedvirtual

Don't override this unless you're doing a test. This is mainly here so that we can override it to simulate lag in steady_clock.

Definition at line 121 of file HHWheelTimer.h.

References now().

Referenced by getTimeRemaining(), and setScheduled().

121  {
123  }
std::chrono::steady_clock::time_point now()
std::chrono::milliseconds folly::HHWheelTimer::Callback::getTimeRemaining ( )
inline

Get the time remaining until this timeout expires. Return 0 if this timeout is not scheduled or expired. Otherwise, return expiration time minus getCurTime().

Definition at line 112 of file HHWheelTimer.h.

References getCurTime().

112  {
113  return getTimeRemaining(getCurTime());
114  }
std::chrono::milliseconds getTimeRemaining()
Definition: HHWheelTimer.h:112
virtual std::chrono::steady_clock::time_point getCurTime()
Definition: HHWheelTimer.h:121
std::chrono::milliseconds folly::HHWheelTimer::Callback::getTimeRemaining ( std::chrono::steady_clock::time_point  now) const
inlineprivate

Definition at line 127 of file HHWheelTimer.h.

References cancelTimeoutImpl(), expiration_, now(), and setScheduled().

128  {
129  if (now >= expiration_) {
130  return std::chrono::milliseconds(0);
131  }
132  return std::chrono::duration_cast<std::chrono::milliseconds>(
133  expiration_ - now);
134  }
std::chrono::steady_clock::time_point now()
std::chrono::steady_clock::time_point expiration_
Definition: HHWheelTimer.h:140
bool folly::HHWheelTimer::Callback::isScheduled ( ) const
inline
void Callback::setScheduled ( HHWheelTimer wheel,
std::chrono::milliseconds  timeout 
)
private

Definition at line 52 of file HHWheelTimer.cpp.

References expiration_, getCurTime(), and wheel_.

Referenced by getTimeRemaining(), and folly::HHWheelTimer::scheduleTimeout().

54  {
55  assert(wheel_ == nullptr);
56  assert(expiration_ == decltype(expiration_){});
57 
58  wheel_ = wheel;
59 
61 }
virtual std::chrono::steady_clock::time_point getCurTime()
Definition: HHWheelTimer.h:121
std::chrono::steady_clock::time_point expiration_
Definition: HHWheelTimer.h:140

Friends And Related Function Documentation

friend class HHWheelTimer
friend

Definition at line 151 of file HHWheelTimer.h.

Referenced by folly::HHWheelTimer::isDetachable().

Member Data Documentation

int folly::HHWheelTimer::Callback::bucket_ {-1}
private

Definition at line 141 of file HHWheelTimer.h.

Referenced by cancelTimeoutImpl(), and folly::HHWheelTimer::scheduleTimeoutImpl().

std::chrono::steady_clock::time_point folly::HHWheelTimer::Callback::expiration_ {}
private

Definition at line 140 of file HHWheelTimer.h.

Referenced by cancelTimeoutImpl(), getTimeRemaining(), and setScheduled().

std::shared_ptr<RequestContext> folly::HHWheelTimer::Callback::requestContext_
private

Definition at line 147 of file HHWheelTimer.h.

Referenced by folly::HHWheelTimer::scheduleTimeout().

HHWheelTimer* folly::HHWheelTimer::Callback::wheel_ {nullptr}
private

Definition at line 139 of file HHWheelTimer.h.

Referenced by cancelTimeout(), cancelTimeoutImpl(), isScheduled(), and setScheduled().


The documentation for this class was generated from the following files: