I noticed only just now that async_write_some and async_send (second overload) functions in boost::asio are completely the same:
async_write_some defenition:
...
template <typename ConstBufferSequence, typename WriteHandler>
  BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
      void (boost::system::error_code, std::size_t))
  async_write_some(const ConstBufferSequence& buffers,
      BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
  {
    // If you get an error on the following line it means that your handler does
    // not meet the documented type requirements for a WriteHandler.
    BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
    return this->get_service().async_send(this->get_implementation(),
        buffers, 0, BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
  }
...
async_send definition:
...
template <typename ConstBufferSequence, typename WriteHandler>
  BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
      void (boost::system::error_code, std::size_t))
  async_send(const ConstBufferSequence& buffers,
      BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
  {
    // If you get an error on the following line it means that your handler does
    // not meet the documented type requirements for a WriteHandler.
    BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
    return this->get_service().async_send(
        this->get_implementation(), buffers, 0,
        BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
  }
...
Why there is two identical functions in boost::asio library? Are there any historical reasons?
Thanks!
They provide two different abstractions:
stream.async_write_some() allows one to generically write to asynchronous stream I/O objects.  For example, this abstraction allows for the higher-level async_write() composed operation to generically write to ip::tcp::socket, ssl:stream, serial_port, etc.  The async_write_some() member function is part of the AsyncWriteStream type requirement.socket.async_send() allows one to generically write to sockets without regard to the protocol.  For example, this abstraction allows for one to generically write to ip::tcp::socket, ip::udp::socket, local::*_protocol::socket, and generic::*_protocol::socket.  The presence of socket.async_send() models closely to the established BSD socket API.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With