From decc19cb38ee00b08bce145847ac0fdf2c5fc7e7 Mon Sep 17 00:00:00 2001 From: Gitea Date: Fri, 24 May 2019 16:25:47 +0800 Subject: [PATCH] add sync run --- examples/client/main.cpp | 3 +-- include/rpc_client.hpp | 4 ++++ include/rpc_server.h | 10 ++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/examples/client/main.cpp b/examples/client/main.cpp index f3f0491..e2e3216 100644 --- a/examples/client/main.cpp +++ b/examples/client/main.cpp @@ -350,8 +350,7 @@ void test_callback() { }, test1); } - std::string str; - std::cin >> str; + client.run(); } void wait_for_notification(rpc_client& client) { diff --git a/include/rpc_client.hpp b/include/rpc_client.hpp index ef02657..1a2766c 100644 --- a/include/rpc_client.hpp +++ b/include/rpc_client.hpp @@ -65,6 +65,10 @@ namespace rest_rpc { stop(); } + void run(){ + thd_->join(); + } + void set_connect_timeout(size_t seconds) { connect_timeout_ = seconds; } diff --git a/include/rpc_server.h b/include/rpc_server.h index e465562..03a4894 100644 --- a/include/rpc_server.h +++ b/include/rpc_server.h @@ -27,11 +27,17 @@ namespace rest_rpc { stop_check_ = true; check_thread_->join(); io_service_pool_.stop(); - thd_->join(); + if(thd_){ + thd_->join(); + } + } + + void async_run() { + thd_ = std::make_shared([this] { io_service_pool_.run(); }); } void run() { - thd_ = std::make_shared([this] { io_service_pool_.run(); }); + io_service_pool_.run(); } template