From a0857b203b5fc09766b9ee02285cb7b669013d81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20L=C3=BCke?= Date: Fri, 22 Nov 2024 12:11:43 +0100 Subject: [PATCH] mesy_nng: pass the last operations result value to retry_predicate --- src/mesy_nng.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/mesy_nng.h b/src/mesy_nng.h index 8f5ed95..05db625 100644 --- a/src/mesy_nng.h +++ b/src/mesy_nng.h @@ -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; +// 'res' is the result of the last nng function call. +using retry_predicate = std::function; 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 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(nng_msg_body(msg)); nng_msg_trim(msg, sizeof(T));