From 2b6e7c950de75d20fb4abd7fa060d2f3aaf3673f Mon Sep 17 00:00:00 2001 From: ggyy Date: Sun, 25 Feb 2024 13:21:32 +0800 Subject: [PATCH 1/5] fix get_func_name return values are different on windows and linux when rpc return bool type --- include/ylt/util/function_name.h | 31 ++++++++++++++++++- .../examples/base_examples/rpc_service.cpp | 4 +++ .../examples/base_examples/rpc_service.h | 1 + .../examples/base_examples/server.cpp | 2 ++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/include/ylt/util/function_name.h b/include/ylt/util/function_name.h index eebff9345..b36cac044 100644 --- a/include/ylt/util/function_name.h +++ b/include/ylt/util/function_name.h @@ -17,9 +17,38 @@ #include #include "magic_names.hpp" + +using namespace std::string_view_literals; + +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..8dbbddd8f 100644 --- a/src/coro_rpc/examples/base_examples/rpc_service.cpp +++ b/src/coro_rpc/examples/base_examples/rpc_service.cpp @@ -30,6 +30,10 @@ 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 Date: Sun, 25 Feb 2024 15:18:56 +0800 Subject: [PATCH 2/5] format code --- include/ylt/util/function_name.h | 24 ++++++++----------- .../examples/base_examples/rpc_service.cpp | 2 +- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/include/ylt/util/function_name.h b/include/ylt/util/function_name.h index b36cac044..bc47f433a 100644 --- a/include/ylt/util/function_name.h +++ b/include/ylt/util/function_name.h @@ -21,8 +21,7 @@ using namespace std::string_view_literals; template -constexpr std::string_view string_view_array_has( - const std::array& array, std::string_view value) { +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; @@ -34,20 +33,17 @@ namespace coro_rpc { template constexpr std::string_view get_func_name() { 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 "} + 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); + 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 std::string_view{qualified_name.data() + func_style.length(), qualified_name.length() - func_style.length()}; } return qualified_name; }; diff --git a/src/coro_rpc/examples/base_examples/rpc_service.cpp b/src/coro_rpc/examples/base_examples/rpc_service.cpp index 8dbbddd8f..6b0b48854 100644 --- a/src/coro_rpc/examples/base_examples/rpc_service.cpp +++ b/src/coro_rpc/examples/base_examples/rpc_service.cpp @@ -31,7 +31,7 @@ std::string hello_world() { } bool return_bool_hello_world() { - return true; + return true; } int A_add_B(int a, int b) { From ada7e9bf4dfb941134fa1f0da663edc25f22ebb9 Mon Sep 17 00:00:00 2001 From: ggyy Date: Sun, 25 Feb 2024 19:29:25 +0800 Subject: [PATCH 3/5] remove use namespace --- include/ylt/util/function_name.h | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/include/ylt/util/function_name.h b/include/ylt/util/function_name.h index bc47f433a..c1f78350a 100644 --- a/include/ylt/util/function_name.h +++ b/include/ylt/util/function_name.h @@ -18,10 +18,9 @@ #include "magic_names.hpp" -using namespace std::string_view_literals; - template -constexpr std::string_view string_view_array_has(const std::array& array, std::string_view value) { +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; @@ -32,18 +31,17 @@ constexpr std::string_view string_view_array_has(const std::array constexpr std::string_view get_func_name() { - 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); + 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 std::string_view{qualified_name.data() + func_style.length(), + qualified_name.length() - func_style.length()}; } return qualified_name; }; From 6b3cf1e9f4ee887b091e5becf91d003ab7746418 Mon Sep 17 00:00:00 2001 From: ggyy Date: Sun, 25 Feb 2024 20:07:42 +0800 Subject: [PATCH 4/5] Update rpc_service.cpp --- src/coro_rpc/examples/base_examples/rpc_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coro_rpc/examples/base_examples/rpc_service.cpp b/src/coro_rpc/examples/base_examples/rpc_service.cpp index 6b0b48854..43dab52be 100644 --- a/src/coro_rpc/examples/base_examples/rpc_service.cpp +++ b/src/coro_rpc/examples/base_examples/rpc_service.cpp @@ -30,7 +30,7 @@ std::string hello_world() { return "hello_world"; } -bool return_bool_hello_world() { +bool return_bool_hello_world() { return true; } From ebe6658747315e9b42b25aecdf8a64c6bb64d8e7 Mon Sep 17 00:00:00 2001 From: ggyy Date: Sun, 25 Feb 2024 22:09:15 +0800 Subject: [PATCH 5/5] Update rpc_service.cpp --- src/coro_rpc/examples/base_examples/rpc_service.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/coro_rpc/examples/base_examples/rpc_service.cpp b/src/coro_rpc/examples/base_examples/rpc_service.cpp index 43dab52be..5b45d7c26 100644 --- a/src/coro_rpc/examples/base_examples/rpc_service.cpp +++ b/src/coro_rpc/examples/base_examples/rpc_service.cpp @@ -30,9 +30,7 @@ std::string hello_world() { return "hello_world"; } -bool return_bool_hello_world() { - return true; -} +bool return_bool_hello_world() { return true; } int A_add_B(int a, int b) { ELOGV(INFO, "call A+B");