Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
igorpeshansky wants to merge1 commit intocpp-netlib:main
base:main
Choose a base branch
Loading
fromigorpeshansky:igorp-std-future

Conversation

igorpeshansky
Copy link

@igorpeshanskyigorpeshansky commentedMay 25, 2018
edited
Loading

This fixes bugs with rethrown exceptions (e.g., avoidsstd::exception_ptr being thrown).

Shouldfix#776 and#872.

@igorpeshansky
Copy link
Author

@davidbtucker FYI.

@deanberrisdeanberris self-requested a reviewMay 26, 2018 13:22
Copy link
Member

@deanberrisdeanberris left a 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.

@igorpeshansky
Copy link
Author

@deanberris Thanks for taking a look!

The problem is thatboost::future has a bug in handlingstd::exception_ptr (there is a specialization ofset_exception forboost::exception_ptr, but not forstd::exception_ptr, so it ends up callingboost::copy_exception on an instance ofstd::exception_ptr). The following code demonstrates the issue:

#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:

Huh? An exception_ptr?Exception: Invalid Version Part.

With this change, it's just:

Exception: Invalid Version Part.

An alternative could be to add a specialization forboost::future::set_exception(std::exception_ptr), but that seems like a much more involved option...

@deanberris
Copy link
Member

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?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@deanberrisdeanberrisdeanberris left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

boost::exception_detail::clone_impl thrown with 0.13-release
2 participants
@igorpeshansky@deanberris

[8]ページ先頭

©2009-2025 Movatter.jp