- Notifications
You must be signed in to change notification settings - Fork425
Switch from boost/thread/future.hpp to C++11 future.#841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
@davidbtucker FYI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Hi@igorpeshansky -- I'm going to need a little time to review this properly. Can you provide a bit more context?
We've encountered problems in the past with the 'ready(...)' accessor which is why we've moved back to using the Boost.Future implementation which allows for checking whether a future is ready without waiting.
@deanberris Thanks for taking a look! The problem is that #include<boost/network/protocol/http/client.hpp>#include<boost/network/protocol/http/server.hpp>#include<iostream>#include<thread>namespacehttp= boost::network::http;classServer {structHandler;using http_server = http::server<Handler>;public:Server() : handler_(),server_(http_server::options(handler_).address("127.0.0.1").port("")) { server_.listen(); http_server& server = server_; server_thread_ =std::thread([&server] { server.run(); }); }~Server() { server_.stop(); server_thread_.join(); } std::stringport() {return server_.port(); }private:structHandler {voidoperator()(http_server::requestconst &request, http_server::connection_ptr connection) { connection->set_status(http_server::connection::ok);//connection->set_headers(std::map<std::string, std::string>({// {"Content-Type", "text/plain"},//})); connection->write(""); } }; Handler handler_; http_server server_; std::thread server_thread_;};intmain(int ac,char** av) {// Start a server in a separate thread, and allow it to choose an// available port. Server server; http::client client; http::client::requestrequest(std::string("http://127.0.0.1:") + server.port());try {try { http::client::response response = client.get(request);if (status(response) <300) { std::cerr <<"Success:" <<body(response) << std::endl; }else { std::cerr <<"Failure:" <<status(response) <<"" <<status_message(response) << std::endl; } }catch (const std::exception_ptr& eptr) { std::cerr <<"Huh? An exception_ptr?" << std::endl;std::rethrow_exception(eptr); } }catch (const boost::system::system_error& e) { std::cerr <<"Boost Exception:" << e.what() << std::endl; }catch (const std::exception& e) { std::cerr <<"Exception:" << e.what() << std::endl; }} Without this change, the output is:
With this change, it's just:
An alternative could be to add a specialization for |
Thanks for explaining@igorpeshansky -- there were changes in 0.13-release which addresses some of the internals of the HTTP connection handling which has to do with exception handling/propagation. I'm wondering whether we should be attempting to cherry-pick that (or port it) into master -- and whether that's the correct fix for this particular problem. I actually don't see where, in your example, how we're throwing exceptions at all. Is there something else I'm missing? |
Uh oh!
There was an error while loading.Please reload this page.
This fixes bugs with rethrown exceptions (e.g., avoids
std::exception_ptr
being thrown).Shouldfix#776 and#872.