proxygen
proxygen::AsyncTimeoutSet::Callback Class Referenceabstract

#include <AsyncTimeoutSet.h>

Inheritance diagram for proxygen::AsyncTimeoutSet::Callback:
proxygen::AckTimeout TestTimeout TestTimeoutDelayed TestTimeoutDelayed

Public Member Functions

 Callback ()
 
virtual ~Callback ()
 
virtual void timeoutExpired () noexcept=0
 
void cancelTimeout ()
 
bool isScheduled () const
 

Private Member Functions

std::chrono::milliseconds getTimeRemaining (std::chrono::milliseconds now) const
 
void setScheduled (AsyncTimeoutSet *timeoutSet, Callback *prev)
 
void cancelTimeoutImpl ()
 

Private Attributes

std::shared_ptr< folly::RequestContextcontext_
 
AsyncTimeoutSettimeoutSet_ {nullptr}
 
Callbackprev_ {nullptr}
 
Callbacknext_ {nullptr}
 
std::chrono::milliseconds expiration_ {0}
 

Friends

class AsyncTimeoutSet
 

Detailed Description

A callback to be notified when a timeout has expired.

AsyncTimeoutSet::Callback is very similar to AsyncTimeout. The primary distinction is that AsyncTimeout can choose its timeout interval each time it is scheduled. On the other hand, AsyncTimeoutSet::Callback always uses the timeout interval defined by the AsyncTimeoutSet where it is scheduled.

Definition at line 54 of file AsyncTimeoutSet.h.

Constructor & Destructor Documentation

proxygen::AsyncTimeoutSet::Callback::Callback ( )
inline

Definition at line 56 of file AsyncTimeoutSet.h.

References folly::pushmi::__adl::noexcept(), timeoutExpired(), and ~Callback().

56 {}
proxygen::AsyncTimeoutSet::Callback::~Callback ( )
virtual

Definition at line 32 of file AsyncTimeoutSet.cpp.

Referenced by Callback().

32  {
33  if (isScheduled()) {
34  cancelTimeout();
35  }
36 }

Member Function Documentation

void proxygen::AsyncTimeoutSet::Callback::cancelTimeout ( )
inline

Cancel the timeout, if it is running.

If the timeout is not scheduled, cancelTimeout() does nothing.

Definition at line 70 of file AsyncTimeoutSet.h.

References cancelTimeoutImpl(), and timeoutSet_.

Referenced by proxygen::AsyncTimeoutSet::scheduleTimeout(), TEST_F(), and proxygen::AsyncTimeoutSet::timeoutExpired().

70  {
71  if (timeoutSet_ == nullptr) {
72  // We're not scheduled, so there's nothing to do.
73  return;
74  }
76  }
void proxygen::AsyncTimeoutSet::Callback::cancelTimeoutImpl ( )
private

Definition at line 52 of file AsyncTimeoutSet.cpp.

References proxygen::AsyncTimeoutSet::AsyncTimeoutSet(), and proxygen::getTimeoutClock().

Referenced by cancelTimeout(), and getTimeRemaining().

52  {
53  if (next_ == nullptr) {
54  assert(timeoutSet_->tail_ == this);
56  } else {
57  assert(timeoutSet_->tail_ != this);
58  next_->prev_ = prev_;
59  }
60 
61  if (prev_ == nullptr) {
62  assert(timeoutSet_->head_ == this);
65  } else {
66  assert(timeoutSet_->head_ != this);
67  prev_->next_ = next_;
68  }
69 
70  timeoutSet_ = nullptr;
71  prev_ = nullptr;
72  next_ = nullptr;
73  expiration_ = {};
74 }
std::chrono::milliseconds expiration_
std::chrono::milliseconds proxygen::AsyncTimeoutSet::Callback::getTimeRemaining ( std::chrono::milliseconds  now) const
inlineprivate

Definition at line 87 of file AsyncTimeoutSet.h.

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

88  {
89  if (now >= expiration_) {
90  return std::chrono::milliseconds(0);
91  }
92  return expiration_ - now;
93  }
std::chrono::steady_clock::time_point now()
std::chrono::milliseconds expiration_
bool proxygen::AsyncTimeoutSet::Callback::isScheduled ( ) const
inline

Return true if this timeout is currently scheduled, and false otherwise.

Definition at line 81 of file AsyncTimeoutSet.h.

References timeoutSet_.

81  {
82  return timeoutSet_ != nullptr;
83  }
void proxygen::AsyncTimeoutSet::Callback::setScheduled ( AsyncTimeoutSet timeoutSet,
Callback prev 
)
private

Definition at line 38 of file AsyncTimeoutSet.cpp.

References proxygen::AsyncTimeoutSet::TimeoutClock::millisecondsSinceEpoch(), proxygen::AsyncTimeoutSet::timeoutClock_, and proxygen::timePointInitialized().

Referenced by getTimeRemaining(), and proxygen::AsyncTimeoutSet::scheduleTimeout().

39  {
40  assert(timeoutSet_ == nullptr);
41  assert(prev_ == nullptr);
42  assert(next_ == nullptr);
44 
45  timeoutSet_ = timeoutSet;
46  prev_ = prev;
47  next_ = nullptr;
48  expiration_ = timeoutSet->timeoutClock_.millisecondsSinceEpoch() +
50 }
std::chrono::milliseconds getInterval() const
std::chrono::milliseconds expiration_
bool timePointInitialized(const T &time)
Definition: Time.h:35
virtual void proxygen::AsyncTimeoutSet::Callback::timeoutExpired ( )
pure virtualnoexcept

Friends And Related Function Documentation

Member Data Documentation

std::shared_ptr<folly::RequestContext> proxygen::AsyncTimeoutSet::Callback::context_
private
std::chrono::milliseconds proxygen::AsyncTimeoutSet::Callback::expiration_ {0}
private

Definition at line 103 of file AsyncTimeoutSet.h.

Referenced by getTimeRemaining().

Callback* proxygen::AsyncTimeoutSet::Callback::next_ {nullptr}
private

Definition at line 102 of file AsyncTimeoutSet.h.

Referenced by proxygen::AsyncTimeoutSet::scheduleTimeout().

Callback* proxygen::AsyncTimeoutSet::Callback::prev_ {nullptr}
private

Definition at line 101 of file AsyncTimeoutSet.h.

Referenced by proxygen::AsyncTimeoutSet::scheduleTimeout().

AsyncTimeoutSet* proxygen::AsyncTimeoutSet::Callback::timeoutSet_ {nullptr}
private

Definition at line 100 of file AsyncTimeoutSet.h.

Referenced by cancelTimeout(), and isScheduled().


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