Skip to content

Commit

Permalink
call coro_rpc function return bool failed crossplatform (#608)
Browse files Browse the repository at this point in the history
  • Loading branch information
yangxingpping authored Feb 25, 2024
1 parent e352ffa commit a9ccad6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
25 changes: 24 additions & 1 deletion include/ylt/util/function_name.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/coro_rpc/examples/base_examples/rpc_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/coro_rpc/examples/base_examples/rpc_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/coro_rpc/examples/base_examples/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a9ccad6

Please sign in to comment.