From 878bf5730c6f13721790c627d0cd34e4debd5df0 Mon Sep 17 00:00:00 2001 From: qicosmos Date: Sun, 5 Oct 2025 19:12:24 +0800 Subject: [PATCH] fix for windows --- include/rest_rpc/rest_rpc_protocol.hpp | 16 +++++++++------- include/rest_rpc/rpc_client.hpp | 23 +++++++++++------------ include/rest_rpc/rpc_server.hpp | 2 +- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/include/rest_rpc/rest_rpc_protocol.hpp b/include/rest_rpc/rest_rpc_protocol.hpp index 7966834..eb1dc04 100644 --- a/include/rest_rpc/rest_rpc_protocol.hpp +++ b/include/rest_rpc/rest_rpc_protocol.hpp @@ -6,8 +6,9 @@ #include #endif -#if defined(__APPLE__) || defined(_WIN32) +#if defined(__APPLE__) #else +namespace rest_rpc::detail { inline uint64_t htonll(uint64_t value) { return ((uint64_t)htonl(value & 0xFFFFFFFF) << 32) | htonl(value >> 32); } @@ -15,6 +16,7 @@ inline uint64_t htonll(uint64_t value) { inline uint64_t ntohll(uint64_t value) { return ((uint64_t)ntohl(value & 0xFFFFFFFF) << 32) | ntohl(value >> 32); } +} // namespace rest_rpc::detail #endif namespace rest_rpc { @@ -32,15 +34,15 @@ struct rest_rpc_header { inline void prepare_for_send(rest_rpc_header &header) { header.function_id = htonl(header.function_id); - header.seq_num = htonll(header.seq_num); - header.body_len = htonll(header.body_len); - header.attach_length = htonll(header.attach_length); + header.seq_num = detail::htonll(header.seq_num); + header.body_len = detail::htonll(header.body_len); + header.attach_length = detail::htonll(header.attach_length); } inline void parse_recieved(rest_rpc_header &header) { header.function_id = ntohl(header.function_id); - header.seq_num = ntohll(header.seq_num); - header.body_len = ntohll(header.body_len); - header.attach_length = ntohll(header.attach_length); + header.seq_num = detail::ntohll(header.seq_num); + header.body_len = detail::ntohll(header.body_len); + header.attach_length = detail::ntohll(header.attach_length); } } // namespace rest_rpc \ No newline at end of file diff --git a/include/rest_rpc/rpc_client.hpp b/include/rest_rpc/rpc_client.hpp index 2593838..582638e 100644 --- a/include/rest_rpc/rpc_client.hpp +++ b/include/rest_rpc/rpc_client.hpp @@ -20,9 +20,7 @@ template struct call_result { R value; }; -template <> struct call_result { - rpc_errc ec; -}; +template <> struct call_result { rpc_errc ec; }; class rpc_client { public: @@ -35,9 +33,9 @@ public: std::chrono::steady_clock::duration duration = std::chrono::seconds(5)) { asio::ip::tcp::resolver resolver(socket_.get_executor()); - auto r = co_await (watchdog(duration) || - resolver.async_resolve( - host, port, asio::as_tuple(asio::use_awaitable))); + auto r = co_await(watchdog(duration) || + resolver.async_resolve( + host, port, asio::as_tuple(asio::use_awaitable))); if (r.index() == 0) { REST_LOG_ERROR << "resolve timeout"; co_return make_error_code(rpc_errc::resolve_timeout); @@ -56,7 +54,7 @@ public: } auto endpoint = it->endpoint(); - auto conn_r = co_await ( + auto conn_r = co_await( watchdog(duration) || socket_.async_connect(endpoint, asio::as_tuple(asio::use_awaitable))); if (conn_r.index() == 0) { @@ -107,8 +105,8 @@ public: rest_rpc_header header{}; header.function_id = get_key(); using R = function_return_type_t; - auto r = co_await (watchdog(duration) || - call_impl(header, std::forward(args)...)); + auto r = co_await(watchdog(duration) || + call_impl(header, std::forward(args)...)); if (r.index() == 0) { co_return call_result{rpc_errc::request_timeout}; } @@ -117,7 +115,8 @@ public: template asio::awaitable> subscribe(std::string_view topic) { - uint32_t topic_id = MD5::MD5Hash32(topic.data(), topic.size()); // topic id + uint32_t topic_id = + MD5::MD5Hash32(topic.data(), (uint32_t)topic.size()); // topic id bool b = false; call_result ret{}; auto it = sub_ops_.find(topic_id); @@ -132,12 +131,12 @@ public: co_return call_result{rpc_errc::duplicate_topic}; } - std::tie(b, ret) = co_await ( + std::tie(b, ret) = co_await( asio::async_compose( std::ref(it->second), asio::use_awaitable) && call_impl(header)); } else { - std::tie(b, ret) = co_await ( + std::tie(b, ret) = co_await( asio::async_compose( std::ref(it->second), asio::use_awaitable) && wait_response()); diff --git a/include/rest_rpc/rpc_server.hpp b/include/rest_rpc/rpc_server.hpp index 0462314..7a27f04 100644 --- a/include/rest_rpc/rpc_server.hpp +++ b/include/rest_rpc/rpc_server.hpp @@ -109,7 +109,7 @@ public: template asio::awaitable publish(std::string_view topic, T &&t) { - auto id = MD5::MD5Hash32(topic.data(), topic.size()); + auto id = MD5::MD5Hash32(topic.data(), (uint32_t)topic.size()); auto conns = get_connections(); for (auto &[_, conn] : conns) { if (conn->topic_id() == id) {