mnode_nng: reformat
This commit is contained in:
parent
9bdd79e910
commit
0eaa5aa942
1 changed files with 24 additions and 24 deletions
|
@ -7,8 +7,8 @@
|
|||
#include <nng/protocol/pipeline0/push.h>
|
||||
#include <nng/protocol/pubsub0/pub.h>
|
||||
#include <nng/protocol/pubsub0/sub.h>
|
||||
#include <nng/protocol/reqrep0/req.h>
|
||||
#include <nng/protocol/reqrep0/rep.h>
|
||||
#include <nng/protocol/reqrep0/req.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
|
@ -161,18 +161,23 @@ 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<bool(int nng_res)>;
|
||||
|
||||
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<typename T>
|
||||
std::optional<T> msg_trim_read(nng_msg *msg)
|
||||
template <typename T> std::optional<T> 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<T *>(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;
|
||||
}
|
||||
|
@ -225,10 +231,7 @@ std::string format_stat(nng_stat *stat);
|
|||
|
||||
using unique_msg = std::unique_ptr<nng_msg, decltype(&nng_msg_free)>;
|
||||
|
||||
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<unique_msg, int> receive_message(nng_socket sock, 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 */
|
||||
|
|
Loading…
Reference in a new issue