diff --git a/include/asio_net/rpc_core b/include/asio_net/rpc_core index 31c13f7..dfd3b0c 160000 --- a/include/asio_net/rpc_core +++ b/include/asio_net/rpc_core @@ -1 +1 @@ -Subproject commit 31c13f7b6b714ad5109eec54c2dcbfbf5f5e8fc3 +Subproject commit dfd3b0c3aebe4fc528d594d9c175d9d6e482a4dc diff --git a/test/rpc_2.cpp b/test/rpc_2.cpp index 3bc7b1c..c1c1afb 100644 --- a/test/rpc_2.cpp +++ b/test/rpc_2.cpp @@ -20,8 +20,14 @@ int main(int argc, char** argv) { // server std::thread([] { - asio::io_context context; auto rpc = rpc_core::rpc::create(); + rpc->subscribe("cmd", [](const std::string& data) -> std::string { + LOG("session on cmd: %s", data.c_str()); + ASSERT(data == "hello"); + return "world"; + }); + + asio::io_context context; static rpc_server server(context, PORT, rpc_config{.rpc = rpc}); // static for test session lifecycle server.on_session = [&](const std::weak_ptr& rs) { LOG("on_session:"); @@ -31,19 +37,16 @@ int main(int argc, char** argv) { LOG("session on_close:"); pass_flag_session_close = true; }; - session->rpc->subscribe("cmd", [](const std::string& data) -> std::string { - LOG("session on cmd: %s", data.c_str()); - ASSERT(data == "hello"); - return "world"; - }); }; server.start(true); }).detach(); // client std::thread([] { - asio::io_context context; auto rpc = rpc_core::rpc::create(); + rpc->cmd("cmd")->msg(std::string("hello"))->call(); // no effect + + asio::io_context context; static rpc_client client(context, rpc_config{.rpc = rpc}); // static for test session lifecycle client.on_open = [&](const std::shared_ptr& rpc_) { LOG("client on_open:"); @@ -66,6 +69,9 @@ int main(int argc, char** argv) { }; client.open("localhost", PORT); client.run(); + + LOG("client exited"); + rpc->cmd("cmd")->msg(std::string("hello"))->call(); // no effect }).join(); ASSERT(pass_flag_rpc_pass);