简体   繁体   English

Boost :: asio async_write_some vs async_send

[英]Boost::asio async_write_some vs async_send

I noticed only just now that async_write_some and async_send (second overload) functions in boost::asio are completely the same: 我刚刚注意到boost::asio中的async_write_someasync_send (第二个重载)函数完全相同:

async_write_some defenition: 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: async_send定义:

...
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? 为什么boost::asio库中有两个相同的函数? 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. stream.async_write_some()允许一般地写入异步流I / O对象。 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. 例如,此抽象允许更高级别的async_write()组合操作一般写入ip::tcp::socketssl:streamserial_port.async_write_some async_write_some()成员函数是AsyncWriteStream类型要求的一部分。
  • socket.async_send() allows one to generically write to sockets without regard to the protocol. socket.async_send()允许一个人一般地写入套接字而不考虑协议。 For example, this abstraction allows for one to generically write to ip::tcp::socket , ip::udp::socket , local::*_protocol::socket , and generic::*_protocol::socket . 例如,这种抽象允许一个人一般写入ip::tcp::socketip::udp::socketlocal::*_protocol::socketgeneric::*_protocol::socket The presence of socket.async_send() models closely to the established BSD socket API. socket.async_send()的存在与已建立的BSD套接字API密切相关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM