Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use_op incorrectly moves lvalue reference arguments passed to async_initiate #68

Closed
anarthal opened this issue Aug 12, 2023 · 0 comments

Comments

@anarthal
Copy link

This statement

// ws is a beast::websocket::stream, request is an http::request<http::string_body>
co_await ws.async_accept(request, as_tuple(use_op));

Leaves ws in an invalid state by moving the websocket stream's implementation, which is a shared_ptr passed by lvalue reference to asio::async_initiate.

The problem is in op.hpp, within these lines:

  template <typename Initiation, typename... InitArgs>
  static auto initiate(Initiation && initiation,
                       boost::async::use_op_t,
                       InitArgs &&... args)
      -> op_impl<std::decay_t<Initiation>, std::decay_t<InitArgs>...>
  {
    return op_impl<std::decay_t<Initiation>, std::decay_t<InitArgs>...>(
        std::forward<Initiation>(initiation),
        std::forward<InitArgs>(args)...);
  }

This decay will end up moving lvalue references. Comparing this to other Asio's completion tokens, this should be:

  template <typename Initiation, typename... InitArgs>
  static auto initiate(Initiation initiation, boost::async::use_op_t,
                       InitArgs... args) -> op_impl<Initiation, InitArgs...> {
    return op_impl<Initiation, InitArgs...>(std::move(initiation),
                                            std::move(args)...);
  }

With this change, the code works.

klemens-morgenstern added a commit that referenced this issue Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants