VLink  2.0.0
A high-performance communication middleware
vlink::AckManager Class Referencefinal

Thread-safe coordinator that pairs RPC requests with their acknowledgements. More...

#include <ack_manager.h>

Collaboration diagram for vlink::AckManager:

Public Types

using ProcessCallback = MoveFunction< bool()>
 Send callback supplied to process(); returning false aborts the wait. More...
 
using NotifyCallback = MoveFunction< void()>
 Optional fill-in callback invoked from inside notify() under the lock. More...
 
using RequestPtr = std::shared_ptr< Request >
 Shared handle representing a single in-flight RPC request. More...
 

Public Member Functions

 AckManager () noexcept
 Constructs an empty manager. More...
 
 ~AckManager () noexcept
 Destroys the manager and releases any remaining pending records. More...
 
RequestPtr create_request () noexcept
 Allocates a new request token with the next monotonic sequence number. More...
 
bool process (RequestPtr request, int ms, ProcessCallback &&process_callback) noexcept
 Publishes request via process_callback and blocks until it is acknowledged. More...
 
bool notify (RequestPtr request, NotifyCallback &&notify_callback=nullptr) noexcept
 Resolves request and, if supplied, runs notify_callback before waking the caller. More...
 
bool remove (RequestPtr request) noexcept
 Cancels request without waking any waiter. More...
 
void clear () noexcept
 Interrupts every pending wait and refuses new ones until reset_interrupted(). More...
 
void reset_interrupted () noexcept
 Permits new process() calls again after a previous clear(). More...
 

Detailed Description

Thread-safe coordinator that pairs RPC requests with their acknowledgements.

Stores a sorted set of in-flight RequestPtr handles indexed by their sequence number and uses one condition variable per request to wake the blocked caller when notify() arrives. Used internally by every ClientImpl subclass to provide the blocking call() semantics exposed at the public Client API.

Member Typedef Documentation

◆ NotifyCallback

Optional fill-in callback invoked from inside notify() under the lock.

Lets the transport copy the response into the caller's buffer before the waiting thread is resumed. May be nullptr.

◆ ProcessCallback

Send callback supplied to process(); returning false aborts the wait.

Invoked while the request is already part of the pending set, so any concurrent notify() that arrives before the callback returns is safe.

◆ RequestPtr

using vlink::AckManager::RequestPtr = std::shared_ptr<Request>

Shared handle representing a single in-flight RPC request.

Returned by create_request() and consumed by process(), notify() and remove(). Equality is implied by the monotonic sequence number.

Constructor & Destructor Documentation

◆ AckManager()

vlink::AckManager::AckManager ( )
noexcept

Constructs an empty manager.

◆ ~AckManager()

vlink::AckManager::~AckManager ( )
noexcept

Destroys the manager and releases any remaining pending records.

Member Function Documentation

◆ clear()

void vlink::AckManager::clear ( )
noexcept

Interrupts every pending wait and refuses new ones until reset_interrupted().

Bumps the generation counter, drains the pending set into a local copy and notifies every condition variable so that the affected process() calls return false. Used during node shutdown to avoid blocking destructors.

◆ create_request()

RequestPtr vlink::AckManager::create_request ( )
noexcept

Allocates a new request token with the next monotonic sequence number.

Returns
Shared handle ready to be passed to process().

◆ notify()

bool vlink::AckManager::notify ( RequestPtr  request,
NotifyCallback &&  notify_callback = nullptr 
)
noexcept

Resolves request and, if supplied, runs notify_callback before waking the caller.

Erases the entry from the pending set, executes notify_callback while holding the request lock so the caller observes the side effects before resuming, and signals the condition variable.

Parameters
requestToken to acknowledge.
notify_callbackOptional callable executed before notification.
Returns
true if the request was still pending and was resolved; false otherwise.

◆ process()

bool vlink::AckManager::process ( RequestPtr  request,
int  ms,
ProcessCallback &&  process_callback 
)
noexcept

Publishes request via process_callback and blocks until it is acknowledged.

The method performs four steps:

  1. Registers request in the pending set; returns false straight away if clear() has been called and not yet reset.
  2. Invokes process_callback to dispatch the request. When the callback returns false the entry is removed and process() also returns false.
  3. Sleeps on a per-request condition variable until notify() / remove() fires or ms expires. A negative ms blocks forever.
  4. Returns true on a successful notify(); false on timeout, abort or clear() interruption.
Parameters
requestToken obtained from create_request().
msWait budget in milliseconds; negative for unlimited.
process_callbackSend callback; returning false aborts the wait.
Returns
true on acknowledgement, false otherwise.

◆ remove()

bool vlink::AckManager::remove ( RequestPtr  request)
noexcept

Cancels request without waking any waiter.

Parameters
requestToken to drop from the pending set.
Returns
true if the entry existed and was removed; false otherwise.

◆ reset_interrupted()

void vlink::AckManager::reset_interrupted ( )
noexcept

Permits new process() calls again after a previous clear().

Does not unblock requests interrupted by the earlier clear(); the generation tag they were created in remains cancelled.


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