Modify

Ticket #9000 (closed Feature Requests: fixed)

Opened 8 months ago

Last modified 7 months ago

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.

Attachments

Change History

comment:1 Changed 8 months ago by vinnie.falco@…

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 Changed 7 months ago by chris_kohlhoff

  • Status changed from new to closed
  • Resolution set to fixed

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

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.