Opened 9 years ago

Closed 9 years ago

#9000 closed Feature Requests (fixed)

asio::buffered_stream and family missing rvalue-move support

Reported by: vinnie.falco@… Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.54.0 Severity: Optimization
Keywords: rvalue references Cc:

Description

The classes asio::buffered_read_stream and asio::buffered_write_stream are missing support for rvalue-move for the handler arguments. I can't say I'm truly an expert but for example, I believe that the function definition for buffered_read_stream::async_read_some should look like this:

  template <typename MutableBufferSequence, typename ReadHandler>
  void async_read_some(const MutableBufferSequence& buffers,
      BOOST_ASIO_MOVE_ARG(ReadHandler) handler)
  {
    if (boost::asio::buffer_size(buffers) == 0)
    {
      get_io_service().post(detail::bind_handler(
            BOOST_ASIO_MOVE_CAST(ReadHandler)(handler), boost::system::error_code(), 0));
    }
    else if (storage_.empty())
    {
      async_fill(read_some_handler<MutableBufferSequence, ReadHandler>(
            get_io_service(), storage_, buffers,
                BOOST_ASIO_MOVE_CAST(ReadHandler)(handler)));
    }
    else
    {
      std::size_t length = copy(buffers);
      get_io_service().post(detail::bind_handler(
            BOOST_ASIO_MOVE_CAST(ReadHandler)(handler), boost::system::error_code(), length));
    }
  }

Note that classes like asio::basic_stream_socket all use BOOST_ASIO_MOVE_ARG and BOOST_ASIO_MOVE_CAST for their treatment of handlers.

If I am incorrect please advise me so I can correct my own code because this is the model I am following.

Change History (2)

comment:1 by vinnie.falco@…, 9 years ago

Let me also add that the use of detail::bind_handler is obsolete, at least in 1.54. It would be preferable to write:

get_io_service ().wrap (BOOST_ASIO_MOVE_CAST(ReadHandler)(handler) (boost::system::error_code(), 0);

Furthermore, the return value of calling the functor returned by [b]io_service::wrapb should be returned, as it could be a BOOST_ASIO_INITFN_RESULT_TYPE:

return get_io_service ().wrap (BOOST_ASIO_MOVE_CAST(ReadHandler)(handler) (boost::system::error_code(), 0);

But amending asio::buffered_*_stream to support future returns is the subject of another ticket...

comment:2 by chris_kohlhoff, 9 years ago

Resolution: fixed
Status: newclosed

Fixed on trunk in [85798]. Merged to release in [85838]. See also #9001.

Note: See TracTickets for help on using tickets.