Boost::asio async_write_some 对比 async_send
Boost::asio async_write_some vs async_send
刚才才注意到boost::asio
中的async_write_some
和async_send
(二次重载)函数完全一样:
async_write_some
防守:
...
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
定义:
...
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));
}
...
为什么boost::asio
库中有两个相同的函数?有什么历史原因吗?
谢谢!
它们提供两种不同的抽象:
stream.async_write_some()
允许一般写入异步流 I/O 对象。例如,此抽象允许更高级别的 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 类型要求。
socket.async_send()
允许一个人在不考虑协议的情况下一般地写入套接字。例如,这种抽象允许一般写入 ip::tcp::socket
、ip::udp::socket
、local::*_protocol::socket
和 generic::*_protocol::socket
。 socket.async_send()
模型的存在与已建立的 BSD 套接字密切相关 API.
刚才才注意到boost::asio
中的async_write_some
和async_send
(二次重载)函数完全一样:
async_write_some
防守:
...
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
定义:
...
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));
}
...
为什么boost::asio
库中有两个相同的函数?有什么历史原因吗?
谢谢!
它们提供两种不同的抽象:
stream.async_write_some()
允许一般写入异步流 I/O 对象。例如,此抽象允许更高级别的async_write()
composed operation to generically write toip::tcp::socket
,ssl:stream
,serial_port
, etc. Theasync_write_some()
member function is part of the AsyncWriteStream 类型要求。socket.async_send()
允许一个人在不考虑协议的情况下一般地写入套接字。例如,这种抽象允许一般写入ip::tcp::socket
、ip::udp::socket
、local::*_protocol::socket
和generic::*_protocol::socket
。socket.async_send()
模型的存在与已建立的 BSD 套接字密切相关 API.