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));