VLink  2.0.0
A high-performance communication middleware
ack_manager.h File Reference

Pending-request bookkeeping used to implement blocking RPC calls. More...

#include <memory>
#include <mutex>
#include <set>
#include "../base/condition_variable.h"
#include "../base/functional.h"
#include "../base/macros.h"
Include dependency graph for ack_manager.h:

Go to the source code of this file.

Classes

class  vlink::AckManager
 Thread-safe coordinator that pairs RPC requests with their acknowledgements. More...
 
struct  vlink::AckManager::Request::Compare
 

Namespaces

 

Detailed Description

Pending-request bookkeeping used to implement blocking RPC calls.

This is an internal implementation header used by the public Client template and the method-model transport backends; it is not part of the user API. AckManager links the thread that initiates a request with the transport thread that delivers its acknowledgement: callers obtain a RequestPtr, hand it to process() (which both publishes the wire frame through a supplied send callback and blocks on a per-request condition variable), and the matching notify() / remove() call resolves the wait once the response is in flight.

Request state diagram
create_request() process()
[none] --------------------> [pending] -----------> [waiting]
^ |
| notify() / remove() |
+-----------------------+
| timeout | clear()
v v
[resolved] [interrupted]
API summary
Method Caller Effect
create_request() RPC caller Allocates a unique sequence number and pending entry.
process() RPC caller Sends, blocks, returns true on notify().
notify() Transport callback Removes pending entry and wakes the waiting caller.
remove() RPC caller / cleanup Cancels an entry without waking a waiter.
clear() Node shutdown Aborts all waits and refuses new process() calls.
reset_interrupted() Node resume Re-enables new process() calls after clear().
Example
auto req = mgr.create_request();
bool ok = mgr.process(req, 200, [&]() {
return transport.send(req_bytes); // returning false aborts the wait
});
// Transport thread, upon receiving a matching reply:
mgr.notify(req, [&]() {
response_bytes = std::move(reply_payload);
});
Thread safety
All public methods are safe to call from any thread. Multiple concurrent process() calls may be in flight at the same time; each request is tracked independently and is keyed by a monotonically increasing sequence number.