call coro_rpc function return bool failed crossplatform (#608)

This commit is contained in:
ggyy 2024-02-25 22:42:12 +08:00 committed by GitHub
parent e352ffa246
commit a9ccad6855
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 29 additions and 1 deletions

View File

@ -17,9 +17,32 @@
#include <string_view>
#include "magic_names.hpp"
template <size_t N>
constexpr std::string_view string_view_array_has(
const std::array<std::string_view, N>& 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 <auto func>
constexpr std::string_view get_func_name() {
return std::string_view{refvalue::qualified_name_of_v<func>};
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<func>};
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

View File

@ -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;

View File

@ -21,6 +21,7 @@
#include <ylt/coro_rpc/coro_rpc_context.hpp>
std::string hello_world();
bool return_bool_hello_world();
int A_add_B(int a, int b);
void hello_with_delay(coro_rpc::context<std::string> conn, std::string hello);
std::string echo(std::string_view sv);

View File

@ -26,6 +26,8 @@ int main() {
coro_rpc_server server2{/*thread=*/1, /*port=*/8802};
server.register_handler<return_bool_hello_world>();
// regist normal function for rpc
server.register_handler<hello_world, A_add_B, hello_with_delay, echo,
nested_echo, coro_echo, echo_with_attachment,