Kea 2.7.6
|
Wrapper class around callout handle which automatically resets handle's state. More...
#include <callout_handle.h>
Public Member Functions | |
ScopedCalloutHandleState (const CalloutHandlePtr &callout_handle) | |
Constructor. | |
~ScopedCalloutHandleState () | |
Destructor. | |
Public Attributes | |
std::function< void()> | on_completion_ |
Continuation callback. | |
Wrapper class around callout handle which automatically resets handle's state.
The Kea servers often require to associate processed packets with CalloutHandle
instances. This is to facilitate the case when the hooks library passes information between the callouts using the 'context' stored in the callout handle. The callouts invoked throughout the packet lifetime have access to the context information for the given packet.
The association between the packets and the callout handles is achieved by giving the ownership of the CalloutHandle
objects to the Pkt
objects. When the Pkt
object goes out of scope, it should also release the pointer to the owned CalloutHandle
object. However, this causes a risk of circular dependency between the shared pointer to the Pkt
object and the shared pointer to the CalloutHandle
it owns, because the pointer to the packet is often set as an argument of the callout handle prior to invoking a callout.
In order to break the circular dependency, the arguments of the callout handle must be deleted as soon as they are not needed anymore. This class is a wrapper around the callout handle object, which resets its state during construction and destruction. All Kea hook points must use this class within the scope where the HooksManager::callCallouts
is invoked to reset the state of the callout handle. The state is reset when this object goes out of scope.
Currently, the following operations are performed during the reset:
CalloutHandle::NEXT_STEP
CONTINUEThis class must never be modified to also delete the context information from the callout handle. The context is intended to be used to share stateful data across callouts and hook points and its contents must exist for the duration of the packet lifecycle. Otherwise, we could simply re-create the callout handle for each hook point and we wouldn't need this RAII class.
Definition at line 510 of file callout_handle.h.
|
explicit |
Constructor.
Resets state of the callout handle.
callout_handle | reference to the pointer to the callout handle which state should be reset. |
isc::BadValue | if the callout handle is null. |
Definition at line 138 of file callout_handle.cc.
References isc_throw.
isc::hooks::ScopedCalloutHandleState::~ScopedCalloutHandleState | ( | ) |
Destructor.
Resets state of the callout handle.
Definition at line 148 of file callout_handle.cc.
References on_completion_.
std::function<void()> isc::hooks::ScopedCalloutHandleState::on_completion_ |
Continuation callback.
Definition at line 528 of file callout_handle.h.
Referenced by ~ScopedCalloutHandleState().