Thread-safe request/acknowledgement synchronisation manager.
More...
#include <ack_manager.h>
|
| 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.
|
|
| | 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 &¬ify_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.
|
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.
◆ NotifyCallback
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
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
◆ AckManager()
| vlink::AckManager::AckManager |
( |
| ) |
|
|
noexcept |
◆ ~AckManager()
| vlink::AckManager::~AckManager |
( |
| ) |
|
|
noexcept |
◆ 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.
◆ create_request()
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.
◆ notify()
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
-
| request | Token of the request to acknowledge. |
| notify_callback | Optional callback to fill the response before waking the caller. |
- Returns
true if the request was found and notified; false otherwise.
◆ process()
Registers the request, invokes the send callback, and blocks until acknowledged.
Steps:
- Adds
request to the pending set (returns false immediately if the manager is interrupted).
- Calls
process_callback(); if it returns false the request is removed and process() returns false.
- Blocks on a per-request condition variable:
- If
ms < 0: waits indefinitely.
- If
ms >= 0: waits for at most ms milliseconds.
- Returns
true if woken by notify(); false on timeout or interruption.
- Parameters
-
| request | Token returned by create_request(). |
| ms | Wait timeout in milliseconds; negative = infinite. |
| process_callback | Callable that sends the request; returns false to abort. |
- Returns
true if notified successfully; false on failure or timeout.
◆ 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
-
- Returns
true if the request was found and erased; false otherwise.
The documentation for this class was generated from the following file: