proxygen
|
#include <AsyncTimeout.h>
Public Types | |
typedef TimeoutManager::InternalEnum | InternalEnum |
Public Member Functions | |
AsyncTimeout (TimeoutManager *timeoutManager) | |
AsyncTimeout (EventBase *eventBase) | |
AsyncTimeout (TimeoutManager *timeoutManager, InternalEnum internal) | |
AsyncTimeout (EventBase *eventBase, InternalEnum internal) | |
AsyncTimeout () | |
virtual | ~AsyncTimeout () |
virtual void | timeoutExpired () noexcept=0 |
bool | scheduleTimeout (uint32_t milliseconds) |
bool | scheduleTimeout (TimeoutManager::timeout_type timeout) |
void | cancelTimeout () |
bool | isScheduled () const |
void | attachTimeoutManager (TimeoutManager *timeoutManager, InternalEnum internal=InternalEnum::NORMAL) |
void | attachEventBase (EventBase *eventBase, InternalEnum internal=InternalEnum::NORMAL) |
void | detachTimeoutManager () |
void | detachEventBase () |
const TimeoutManager * | getTimeoutManager () |
struct event * | getEvent () |
Static Public Member Functions | |
template<typename TCallback > | |
static std::unique_ptr< AsyncTimeout > | make (TimeoutManager &manager, TCallback &&callback) |
template<typename TCallback > | |
static std::unique_ptr< AsyncTimeout > | schedule (TimeoutManager::timeout_type timeout, TimeoutManager &manager, TCallback &&callback) |
Static Private Member Functions | |
static void | libeventCallback (libevent_fd_t fd, short events, void *arg) |
Private Attributes | |
struct event | event_ |
TimeoutManager * | timeoutManager_ |
std::shared_ptr< RequestContext > | context_ |
AsyncTimeout is used to asynchronously wait for a timeout to occur.
Definition at line 36 of file AsyncTimeout.h.
Definition at line 38 of file AsyncTimeout.h.
|
explicit |
Create a new AsyncTimeout object, driven by the specified TimeoutManager.
Definition at line 27 of file AsyncTimeout.cpp.
References folly::TimeoutManager::attachTimeoutManager(), event_, folly::folly_event_set(), libeventCallback(), folly::TimeoutManager::NORMAL, and timeoutManager_.
|
explicit |
Definition at line 36 of file AsyncTimeout.cpp.
References folly::TimeoutManager::attachTimeoutManager(), event_, folly::folly_event_set(), libeventCallback(), folly::TimeoutManager::NORMAL, and timeoutManager_.
folly::AsyncTimeout::AsyncTimeout | ( | TimeoutManager * | timeoutManager, |
InternalEnum | internal | ||
) |
Create a new internal AsyncTimeout object.
Internal timeouts are like regular timeouts, but will not stop the TimeoutManager loop from exiting if the only remaining events are internal timeouts.
This is useful for implementing fallback timeouts to abort the TimeoutManager loop if the other events have not been processed within a specified time period: if the event loop takes too long the timeout will fire and can stop the event loop. However, if all other events complete, the event loop will exit even though the internal timeout is still installed.
Definition at line 46 of file AsyncTimeout.cpp.
References folly::TimeoutManager::attachTimeoutManager(), event_, folly::folly_event_set(), libeventCallback(), and timeoutManager_.
folly::AsyncTimeout::AsyncTimeout | ( | EventBase * | eventBase, |
InternalEnum | internal | ||
) |
Definition at line 56 of file AsyncTimeout.cpp.
References folly::TimeoutManager::attachTimeoutManager(), event_, folly::folly_event_set(), libeventCallback(), and timeoutManager_.
folly::AsyncTimeout::AsyncTimeout | ( | ) |
Create a new AsyncTimeout object, not yet assigned to a TimeoutManager.
attachEventBase() must be called prior to scheduling the timeout.
Definition at line 64 of file AsyncTimeout.cpp.
References event_, folly::folly_event_set(), and libeventCallback().
|
virtual |
AsyncTimeout destructor.
The timeout will be automatically cancelled if it is running.
Definition at line 70 of file AsyncTimeout.cpp.
References cancelTimeout().
void folly::AsyncTimeout::attachEventBase | ( | EventBase * | eventBase, |
InternalEnum | internal = InternalEnum::NORMAL |
||
) |
Definition at line 106 of file AsyncTimeout.cpp.
References attachTimeoutManager().
Referenced by fizz::AsyncFizzBase::attachEventBase(), folly::AsyncSocket::attachEventBase(), folly::AsyncSSLSocket::attachEventBase(), and folly::HHWheelTimer::isDetachable().
void folly::AsyncTimeout::attachTimeoutManager | ( | TimeoutManager * | timeoutManager, |
InternalEnum | internal = InternalEnum::NORMAL |
||
) |
Attach the timeout to a TimeoutManager.
This may only be called if the timeout is not currently attached to a TimeoutManager (either by using the default constructor, or by calling detachTimeoutManager()).
This method must be invoked in the TimeoutManager's thread.
The internal parameter specifies if this timeout should be treated as an internal event. TimeoutManager::loop() will return when there are no more non-internal events remaining.
Definition at line 95 of file AsyncTimeout.cpp.
References folly::TimeoutManager::attachTimeoutManager(), folly::TimeoutManager::isInTimeoutManagerThread(), and timeoutManager_.
Referenced by attachEventBase(), fizz::AsyncFizzBase::attachTimeoutManager(), and folly::AsyncSSLSocket::attachTimeoutManager().
void folly::AsyncTimeout::cancelTimeout | ( | ) |
Cancel the timeout, if it is running.
Definition at line 84 of file AsyncTimeout.cpp.
References folly::TimeoutManager::cancelTimeout(), context_, isScheduled(), and timeoutManager_.
Referenced by fizz::AsyncFizzBase::cancelHandshakeTimeout(), folly::AsyncSSLSocket::closeNow(), folly::AsyncSocket::closeNow(), folly::AsyncSSLSocket::failHandshake(), folly::AsyncSSLSocket::handleConnect(), folly::AsyncSocket::handleConnect(), folly::AsyncSocket::handleWrite(), proxygen::AsyncTimeoutSet::headChanged(), folly::AsyncSSLSocket::invokeConnectErr(), folly::AsyncSSLSocket::invokeConnectSuccess(), folly::AsyncSSLSocket::invokeHandshakeCB(), folly::AsyncServerSocket::pauseAccepting(), folly::HHWheelTimer::scheduleNextTimeout(), TestAsyncTransport::setReadCB(), folly::AsyncSocket::setSendTimeout(), folly::AsyncSocket::shutdownWriteNow(), folly::AsyncSocket::startFail(), folly::TEST(), and ~AsyncTimeout().
void folly::AsyncTimeout::detachEventBase | ( | ) |
Definition at line 126 of file AsyncTimeout.cpp.
References detachTimeoutManager().
Referenced by fizz::AsyncFizzBase::detachEventBase(), folly::AsyncSocket::detachEventBase(), folly::AsyncSSLSocket::detachEventBase(), folly::HHWheelTimer::isDetachable(), and TEST_F().
void folly::AsyncTimeout::detachTimeoutManager | ( | ) |
Detach the timeout from its TimeoutManager.
This may only be called when the timeout is not running. Once detached, the timeout may not be scheduled again until it is re-attached to a EventBase by calling attachEventBase().
This method must be called from the current TimeoutManager's thread.
Definition at line 112 of file AsyncTimeout.cpp.
References folly::TimeoutManager::detachTimeoutManager(), folly::FATAL, isScheduled(), and timeoutManager_.
Referenced by detachEventBase(), fizz::AsyncFizzBase::detachTimeoutManager(), and folly::AsyncSSLSocket::detachTimeoutManager().
|
inline |
Returns the internal handle to the event
Definition at line 150 of file AsyncTimeout.h.
References event_, libeventCallback(), make(), schedule(), and folly::detail::timeout.
Referenced by folly::EventBase::attachTimeoutManager(), folly::EventBase::cancelTimeout(), folly::EventBase::detachTimeoutManager(), folly::EventBase::scheduleTimeout(), TimeoutTest::setClock(), and TimeoutTest::SetUp().
|
inline |
Definition at line 143 of file AsyncTimeout.h.
References timeoutManager_.
Referenced by folly::HHWheelTimer::isDetachable().
bool folly::AsyncTimeout::isScheduled | ( | ) | const |
Returns true if the timeout is currently scheduled.
Definition at line 91 of file AsyncTimeout.cpp.
References event_, and folly::EventUtil::isEventRegistered().
Referenced by cancelTimeout(), folly::AsyncSSLSocket::closeNow(), detachTimeoutManager(), folly::AsyncSSLSocket::failHandshake(), folly::AsyncSSLSocket::handleConnect(), folly::AsyncSocket::handleWrite(), folly::AsyncSSLSocket::invalidState(), folly::AsyncSSLSocket::invokeConnectErr(), folly::AsyncSSLSocket::invokeHandshakeCB(), fizz::AsyncFizzBase::isDetachable(), folly::HHWheelTimer::isDetachable(), folly::AsyncSocket::isDetachable(), folly::AsyncSSLSocket::isDetachable(), and folly::HHWheelTimer::scheduleNextTimeout().
|
staticprivate |
Definition at line 130 of file AsyncTimeout.cpp.
References folly::TimeoutManager::bumpHandlingTime(), context_, event_, folly::event_ref_flags(), folly::libeventFdToFd(), folly::detail::timeout, timeoutExpired(), and timeoutManager_.
Referenced by AsyncTimeout(), and getEvent().
|
static |
Convenience function that wraps a function object as an AsyncTimeout instance and returns the wrapper.
Specially useful when using lambdas as AsyncTimeout observers.
Example:
void foo(TimeoutManager &manager) { std::atomic_bool done = false;
auto observer = AsyncTimeout::make(manager, [&] { std::cout << "hello, world!" << std::endl; done = true; });
observer->scheduleTimeout(std::chrono::seconds(5));
while (!done); // busy wait }
Definition at line 261 of file AsyncTimeout.h.
Referenced by getEvent(), schedule(), and folly::TEST().
|
static |
Convenience function that wraps a function object as an AsyncTimeout instance and returns the wrapper after scheduling it using the given TimeoutManager.
This is equivalent to calling make_async_timeout
followed by a scheduleTimeout
on the resulting wrapper.
Specially useful when using lambdas as AsyncTimeout observers.
Example:
void foo(TimeoutManager &manager) { std::atomic_bool done = false;
auto observer = AsyncTimeout::schedule( std::chrono::seconds(5), manager, [&] { std::cout << "hello, world!" << std::endl; done = true; } );
while (!done); // busy wait }
Definition at line 270 of file AsyncTimeout.h.
References make().
Referenced by getEvent(), and folly::TEST().
bool folly::AsyncTimeout::scheduleTimeout | ( | uint32_t | milliseconds | ) |
Schedule the timeout to fire in the specified number of milliseconds.
After the specified number of milliseconds has elapsed, timeoutExpired() will be invoked by the TimeoutManager's main loop.
If the timeout is already running, it will be rescheduled with the new timeout value.
milliseconds | The timeout duration, in milliseconds. |
Definition at line 80 of file AsyncTimeout.cpp.
Referenced by folly::AsyncServerSocket::enterBackoff(), TestAsyncTransport::fireNextReadEvent(), folly::AsyncSocket::handleWrite(), proxygen::AsyncTimeoutSet::headChanged(), folly::MemoryIdlerTimeout::runLoopCallback(), folly::AsyncSocket::scheduleConnectTimeout(), TestAsyncTransport::scheduleNextReadEvent(), folly::HHWheelTimer::scheduleNextTimeout(), folly::AsyncSSLSocket::Timeout::scheduleTimeout(), proxygen::AsyncTimeoutSet::scheduleTimeout(), folly::AsyncSocket::setSendTimeout(), fizz::server::SlidingBloomReplayCache::SlidingBloomReplayCache(), fizz::AsyncFizzBase::startHandshakeTimeout(), TEST(), fizz::server::SlidingBloomReplayCache::timeoutExpired(), proxygen::AsyncTimeoutSet::timeoutExpired(), and folly::AsyncSocket::writeImpl().
bool folly::AsyncTimeout::scheduleTimeout | ( | TimeoutManager::timeout_type | timeout | ) |
Definition at line 74 of file AsyncTimeout.cpp.
References context_, folly::RequestContext::saveContext(), folly::TimeoutManager::scheduleTimeout(), and timeoutManager_.
|
pure virtualnoexcept |
timeoutExpired() is invoked when the timeout period has expired.
Implemented in IdleTimeTimeoutSeries, folly::EventBaseAborter, folly::AsyncSocket::WriteTimeout, ReschedulingTimeout, TestTimeout, UDPClient, folly::HHWheelTimer, UDPClient, folly::detail::async_timeout_wrapper< TCallback >, wangle::ConnectionManager::DrainHelper, proxygen::AsyncTimeoutSet, folly::AsyncServerSocket::BackoffTimeout, folly::AsyncSSLSocket::Timeout, TestAsyncTransport, DelayedWrite, fizz::server::SlidingBloomReplayCache, TestTimeout, fizz::AsyncFizzBase::HandshakeTimeout, folly::MemoryIdlerTimeout, TestTimeout, folly::TimeoutManager::CobTimeouts::CobTimeout, and TestTimeout.
Referenced by libeventCallback(), TimeoutTest::setClock(), and fizz::test::TEST_F().
|
private |
Definition at line 231 of file AsyncTimeout.h.
Referenced by cancelTimeout(), libeventCallback(), and scheduleTimeout().
|
private |
Definition at line 221 of file AsyncTimeout.h.
Referenced by AsyncTimeout(), getEvent(), isScheduled(), and libeventCallback().
|
private |
Definition at line 228 of file AsyncTimeout.h.
Referenced by AsyncTimeout(), attachTimeoutManager(), cancelTimeout(), detachTimeoutManager(), getTimeoutManager(), libeventCallback(), and scheduleTimeout().