call coro_rpc function return bool failed crossplatform (#608)
This commit is contained in:
parent
e352ffa246
commit
a9ccad6855
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue