From 0eaa5aa942813d4f21b725e0e041fbf45e7c3041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20L=C3=BCke?= Date: Thu, 26 Dec 2024 15:28:00 +0100 Subject: [PATCH] mnode_nng: reformat --- include/mesytec-mnode/mnode_nng.h | 48 +++++++++++++++---------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/include/mesytec-mnode/mnode_nng.h b/include/mesytec-mnode/mnode_nng.h index 5fb8f27..68b6349 100644 --- a/include/mesytec-mnode/mnode_nng.h +++ b/include/mesytec-mnode/mnode_nng.h @@ -7,8 +7,8 @@ #include #include #include -#include #include +#include #include #include @@ -93,7 +93,7 @@ inline int set_socket_timeouts(nng_socket socket, nng_duration timeout = Default return 0; } -using socket_factory = std::function; +using socket_factory = std::function; inline nng_socket make_socket(socket_factory factory, nng_duration timeout = DefaultTimeout) { @@ -159,20 +159,25 @@ inline std::string get_local_address(nng_socket s) void log_pipe_info(nng_pipe p, const char *info_text); // 'nng_res' is the result of the last nng function call. -using retry_predicate = std::function; +using retry_predicate = std::function; -int send_message_retry(nng_socket socket, nng_msg *msg, retry_predicate rp, const char *debugInfo = ""); +int send_message_retry(nng_socket socket, nng_msg *msg, retry_predicate rp, + const char *debugInfo = ""); struct RetryNTimes { - explicit RetryNTimes(size_t maxTries = 3) : maxTries(maxTries) {} + explicit RetryNTimes(size_t maxTries = 3) + : maxTries(maxTries) + { + } bool operator()(int) { return attempt++ < maxTries; } size_t maxTries; size_t attempt = 0u; }; -inline int send_message_retry(nng_socket socket, nng_msg *msg, size_t maxTries = 3, const char *debugInfo = "") +inline int send_message_retry(nng_socket socket, nng_msg *msg, size_t maxTries = 3, + const char *debugInfo = "") { return send_message_retry(socket, msg, RetryNTimes(maxTries), debugInfo); } @@ -185,16 +190,17 @@ inline int send_empty_message(nng_socket socket, size_t maxTries = 3) } // Read type T from the front of msg and trim the message by sizeof(T). -template -std::optional msg_trim_read(nng_msg *msg) +template std::optional msg_trim_read(nng_msg *msg) { - const auto oldlen = nng_msg_len(msg); (void) oldlen; + const auto oldlen = nng_msg_len(msg); + (void)oldlen; if (nng_msg_len(msg) < sizeof(T)) return std::nullopt; T result = *reinterpret_cast(nng_msg_body(msg)); nng_msg_trim(msg, sizeof(T)); - const auto newlen = nng_msg_len(msg); (void) newlen; + const auto newlen = nng_msg_len(msg); + (void)newlen; assert(newlen + sizeof(T) == oldlen); return result; } @@ -205,8 +211,8 @@ const char *nng_stat_type_to_string(int nng_stat_type); // Important: as of nng-1.8.0 sockets stats are only implemented for pair1 type // sockets! -template -void visit_nng_stats(nng_stat *stat, Visitor visitor, unsigned depth=0) +template +void visit_nng_stats(nng_stat *stat, Visitor visitor, unsigned depth = 0) { visitor(stat, depth); @@ -216,7 +222,7 @@ void visit_nng_stats(nng_stat *stat, Visitor visitor, unsigned depth=0) { for (auto child = nng_stat_child(stat); child; child = nng_stat_next(child)) { - visit_nng_stats(child, visitor, depth+1); + visit_nng_stats(child, visitor, depth + 1); } } } @@ -225,10 +231,7 @@ std::string format_stat(nng_stat *stat); using unique_msg = std::unique_ptr; -inline unique_msg make_unique_msg(nng_msg *msg = nullptr) -{ - return unique_msg(msg, &nng_msg_free); -} +inline unique_msg make_unique_msg(nng_msg *msg = nullptr) { return unique_msg(msg, &nng_msg_free); } inline std::pair receive_message(nng_socket sock, int flags = 0) { @@ -236,10 +239,10 @@ inline std::pair receive_message(nng_socket sock, int flags = 0 if (auto res = nng_recvmsg(sock, &msg, flags)) { - return { make_unique_msg(), res }; + return {make_unique_msg(), res}; } - return { make_unique_msg(msg), 0 }; + return {make_unique_msg(msg), 0}; } inline int send_message(nng_socket sock, unique_msg &msg, int flags = 0) @@ -329,11 +332,8 @@ inline unique_msg clone_message(const nng_msg *msg) return make_unique_msg(newMsg); } -inline unique_msg clone_message(const unique_msg &msg) -{ - return clone_message(msg.get()); -} +inline unique_msg clone_message(const unique_msg &msg) { return clone_message(msg.get()); } -} +} // namespace mesytec::mnode::nng #endif /* B18E3651_CA9A_43BC_AA25_810EA16533CD */