VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
vlink::AckManager Class Referencefinal

Thread-safe request/acknowledgement synchronisation manager. More...

#include <ack_manager.h>

Collaboration diagram for vlink::AckManager:

Public Types

using ProcessCallback = std::function<bool()>
 Callback invoked by process() to send the request over the transport.
using NotifyCallback = std::function<void()>
 Optional callback invoked inside notify() while holding the request lock.
using RequestPtr = std::shared_ptr<Request>
 Shared ownership handle for an in-flight request token.

Public Member Functions

 AckManager () noexcept
 Default constructor.
 ~AckManager () noexcept
 Destructor.
RequestPtr create_request () noexcept
 Allocates a new in-flight request token with a unique sequence number.
bool process (RequestPtr request, int ms, ProcessCallback &&process_callback) noexcept
 Registers the request, invokes the send callback, and blocks until acknowledged.
bool notify (RequestPtr request, NotifyCallback &&notify_callback=nullptr) noexcept
 Acknowledges a pending request and optionally fills the response.
bool remove (RequestPtr request) noexcept
 Removes a pending request without notifying the waiting caller.
void clear () noexcept
 Interrupts all pending requests and wakes all blocked process() calls.

Detailed Description

Thread-safe request/acknowledgement synchronisation manager.

Manages a set of in-flight requests, each represented by a RequestPtr. Used internally by ClientImpl implementations to implement blocking call() semantics.

Member Typedef Documentation

◆ NotifyCallback

using vlink::AckManager::NotifyCallback = std::function<void()>

Optional callback invoked inside notify() while holding the request lock.

Provides the responder a chance to fill the response buffer before the waiting process() thread is woken. May be nullptr.

◆ ProcessCallback

using vlink::AckManager::ProcessCallback = std::function<bool()>

Callback invoked by process() to send the request over the transport.

Called while the request is already registered in the pending set. Should return false if the send fails (e.g. no server connected), causing process() to remove the request and return false immediately.

◆ RequestPtr

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

Shared ownership handle for an in-flight request token.

Returned by create_request() and passed to process(), notify(), and remove(). Requests are ordered by a monotonic sequence number.

Constructor & Destructor Documentation

◆ AckManager()

vlink::AckManager::AckManager ( )
noexcept

Default constructor.

Here is the caller graph for this function:

◆ ~AckManager()

vlink::AckManager::~AckManager ( )
noexcept

Destructor.

Here is the call graph for this function:

Member Function Documentation

◆ clear()

void vlink::AckManager::clear ( )
noexcept

Interrupts all pending requests and wakes all blocked process() calls.

Sets the interrupted flag so that new process() calls return false immediately, swaps out the pending set, and notify_all() on every pending request's condition variable. Called during node shutdown to avoid deadlocks.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_request()

RequestPtr vlink::AckManager::create_request ( )
nodiscardnoexcept

Allocates a new in-flight request token with a unique sequence number.

The returned RequestPtr must be passed to process() to register the request and block until the corresponding notify() call.

Returns
A new RequestPtr with a monotonically increasing sequence number.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ notify()

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

Acknowledges a pending request and optionally fills the response.

Removes request from the pending set, calls notify_callback (if set) while holding the request lock, then signals the condition variable to wake the blocked process() call.

Returns false when request is not found in the pending set (e.g. already timed out or removed).

Parameters
requestToken of the request to acknowledge.
notify_callbackOptional callback to fill the response before waking the caller.
Returns
true if the request was found and notified; false otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process()

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

Registers the request, invokes the send callback, and blocks until acknowledged.

Steps:

  1. Adds request to the pending set (returns false immediately if the manager is interrupted).
  2. Calls process_callback(); if it returns false the request is removed and process() returns false.
  3. Blocks on a per-request condition variable:
    • If ms < 0: waits indefinitely.
    • If ms >= 0: waits for at most ms milliseconds.
  4. Returns true if woken by notify(); false on timeout or interruption.
Parameters
requestToken returned by create_request().
msWait timeout in milliseconds; negative = infinite.
process_callbackCallable that sends the request; returns false to abort.
Returns
true if notified successfully; false on failure or timeout.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove()

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

Removes a pending request without notifying the waiting caller.

Use this to cancel a request before it is acknowledged, e.g. when the transport determines the request cannot be delivered.

Parameters
requestToken to remove.
Returns
true if the request was found and erased; false otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

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