mesy_nng: pass the last operations result value to retry_predicate
This commit is contained in:
parent
9e95897283
commit
a0857b203b
1 changed files with 5 additions and 4 deletions
|
@ -204,7 +204,8 @@ inline void log_pipe_info(nng_pipe p, const char *info)
|
|||
spdlog::info("{}: {}={}", info, NNG_OPT_REMADDR, remoteAddress);
|
||||
}
|
||||
|
||||
using retry_predicate = std::function<bool ()>;
|
||||
// 'res' is the result of the last nng function call.
|
||||
using retry_predicate = std::function<bool (int res)>;
|
||||
|
||||
class RetryNTimes
|
||||
{
|
||||
|
@ -213,7 +214,7 @@ class RetryNTimes
|
|||
: maxTries_(maxTries)
|
||||
{}
|
||||
|
||||
bool operator()()
|
||||
bool operator()(int)
|
||||
{
|
||||
return attempt_++ < maxTries_;
|
||||
}
|
||||
|
@ -242,7 +243,7 @@ inline int send_message_retry(nng_socket socket, nng_msg *msg, retry_predicate r
|
|||
if (res == NNG_ETIMEDOUT)
|
||||
spdlog::trace("send_message_retry: {} - send timeout (msg={})", debugInfo, fmt::ptr(msg));
|
||||
|
||||
if (!rp())
|
||||
if (!rp(res))
|
||||
return res;
|
||||
}
|
||||
} while (res == NNG_ETIMEDOUT);
|
||||
|
@ -286,7 +287,7 @@ std::optional<T> msg_trim_read(nng_msg *msg)
|
|||
{
|
||||
const auto oldlen = nng_msg_len(msg); (void) oldlen;
|
||||
if (nng_msg_len(msg) < sizeof(T))
|
||||
return {};
|
||||
return std::nullopt;
|
||||
|
||||
T result = *reinterpret_cast<T *>(nng_msg_body(msg));
|
||||
nng_msg_trim(msg, sizeof(T));
|
||||
|
|
Loading…
Reference in a new issue