From a9ccad68558a0b7c2e0d28d63a3eaa2e984b39e3 Mon Sep 17 00:00:00 2001 From: ggyy Date: Sun, 25 Feb 2024 22:42:12 +0800 Subject: [PATCH] call coro_rpc function return bool failed crossplatform (#608) --- include/ylt/util/function_name.h | 25 ++++++++++++++++++- .../examples/base_examples/rpc_service.cpp | 2 ++ .../examples/base_examples/rpc_service.h | 1 + .../examples/base_examples/server.cpp | 2 ++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/ylt/util/function_name.h b/include/ylt/util/function_name.h index eebff9345..c1f78350a 100644 --- a/include/ylt/util/function_name.h +++ b/include/ylt/util/function_name.h @@ -17,9 +17,32 @@ #include #include "magic_names.hpp" + +template +constexpr std::string_view string_view_array_has( + const std::array& array, std::string_view value) { + for (const auto& v : array) { + if (value.find(v) == 0) + return v; + } + return std::string_view{""}; +} + namespace coro_rpc { template constexpr std::string_view get_func_name() { - return std::string_view{refvalue::qualified_name_of_v}; + constexpr std::array func_style_array{ + std::string_view{"__cdecl "}, std::string_view{"__clrcall "}, + std::string_view{"__stdcall "}, std::string_view{"__fastcall "}, + std::string_view{"__thiscall "}, std::string_view{"__vectorcall "}}; + constexpr auto qualified_name = + std::string_view{refvalue::qualified_name_of_v}; + constexpr auto func_style = + string_view_array_has(func_style_array, qualified_name); + if constexpr (func_style.length() > 0) { + return std::string_view{qualified_name.data() + func_style.length(), + qualified_name.length() - func_style.length()}; + } + return qualified_name; }; } // namespace coro_rpc diff --git a/src/coro_rpc/examples/base_examples/rpc_service.cpp b/src/coro_rpc/examples/base_examples/rpc_service.cpp index e85d8ca95..5b45d7c26 100644 --- a/src/coro_rpc/examples/base_examples/rpc_service.cpp +++ b/src/coro_rpc/examples/base_examples/rpc_service.cpp @@ -30,6 +30,8 @@ std::string hello_world() { return "hello_world"; } +bool return_bool_hello_world() { return true; } + int A_add_B(int a, int b) { ELOGV(INFO, "call A+B"); return a + b; diff --git a/src/coro_rpc/examples/base_examples/rpc_service.h b/src/coro_rpc/examples/base_examples/rpc_service.h index 145dfe1bd..1198009b7 100644 --- a/src/coro_rpc/examples/base_examples/rpc_service.h +++ b/src/coro_rpc/examples/base_examples/rpc_service.h @@ -21,6 +21,7 @@ #include std::string hello_world(); +bool return_bool_hello_world(); int A_add_B(int a, int b); void hello_with_delay(coro_rpc::context conn, std::string hello); std::string echo(std::string_view sv); diff --git a/src/coro_rpc/examples/base_examples/server.cpp b/src/coro_rpc/examples/base_examples/server.cpp index 5efb49d4a..e6cedb2dc 100644 --- a/src/coro_rpc/examples/base_examples/server.cpp +++ b/src/coro_rpc/examples/base_examples/server.cpp @@ -26,6 +26,8 @@ int main() { coro_rpc_server server2{/*thread=*/1, /*port=*/8802}; + server.register_handler(); + // regist normal function for rpc server.register_handler