VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
vlink::AckManager类 参考final

Thread-safe request/acknowledgement synchronisation manager. 更多...

#include <ack_manager.h>

vlink::AckManager 的协作图:

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 &&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.

详细描述

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

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.

构造及析构函数说明

◆ AckManager()

vlink::AckManager::AckManager ( )
noexcept

Default constructor.

这是这个函数的调用关系图:

◆ ~AckManager()

vlink::AckManager::~AckManager ( )
noexcept

Destructor.

函数调用图:

成员函数说明

◆ 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()

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.

返回
A new RequestPtr with a monotonically increasing sequence number.
函数调用图:
这是这个函数的调用关系图:

◆ 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).

参数
requestToken of the request to acknowledge.
notify_callbackOptional callback to fill the response before waking the caller.
返回
true if the request was found and notified; false otherwise.
函数调用图:
这是这个函数的调用关系图:

◆ 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.
参数
requestToken returned by create_request().
msWait timeout in milliseconds; negative = infinite.
process_callbackCallable that sends the request; returns false to abort.
返回
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.

参数
requestToken to remove.
返回
true if the request was found and erased; false otherwise.
函数调用图:
这是这个函数的调用关系图:

该类的文档由以下文件生成: