|
VLink 2.0.0
A high-performance communication middleware
|
Thread-safe request/acknowledgement synchronisation manager. 更多...
#include <ack_manager.h>
Public 类型 | |
| 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 成员函数 | |
| 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.
| using vlink::AckManager::NotifyCallback = std::function<void()> |
| using vlink::AckManager::ProcessCallback = std::function<bool()> |
| 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.
|
noexcept |
Default constructor.
|
noexcept |
Destructor.
|
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.
|
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.
RequestPtr with a monotonically increasing sequence number.
|
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).
| request | Token of the request to acknowledge. |
| notify_callback | Optional callback to fill the response before waking the caller. |
true if the request was found and notified; false otherwise.
|
nodiscardnoexcept |
Registers the request, invokes the send callback, and blocks until acknowledged.
Steps:
request to the pending set (returns false immediately if the manager is interrupted).process_callback(); if it returns false the request is removed and process() returns false.ms < 0: waits indefinitely.ms >= 0: waits for at most ms milliseconds.true if woken by notify(); false on timeout or interruption.| request | Token returned by create_request(). |
| ms | Wait timeout in milliseconds; negative = infinite. |
| process_callback | Callable that sends the request; returns false to abort. |
true if notified successfully; false on failure or timeout.
|
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.
| request | Token to remove. |
true if the request was found and erased; false otherwise.