c++ - How to make io_service.run(); blocking -
i have method need io_service.run(); block method returning while actual rest call not yet done. added "init" value response body check.
restclient::response restclient::get(std::string url){ restclient::response ret = {}; ret.code = 404; ret.body = "init"; boost::asio::ssl::context ctx(boost::asio::ssl::context::sslv23); ctx.set_verify_mode(boost::asio::ssl::verify_none); //ctx.set_default_verify_paths(); boost::asio::io_service io_service; client c(io_service, ctx, "httpbin.org", "/get", "https", ret); io_service.run(); return ret; // res.body returned init }
in way io_service.run()
block method returning until call finished or timed-out?
if want run()
keep running when there no "work", can lock service queue using boost::asio::io_service::work
object:
the usual pattern use optional<io_service::work>
or shared_ptr<io_service::work>
can do
_work.reset();
when want service return run()
.
Comments
Post a Comment