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_some和async_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? Are there any historical reasons?
为什么boost :: asio库中有两个相同的函数?有历史原因吗?
Thanks!
谢谢!
1 个解决方案
#1
3
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-levelasync_write()
composed operation to generically write toip::tcp::socket
,ssl:stream
,serial_port
, etc. Theasync_write_some()
member function is part of the AsyncWriteStream type requirement. - stream.async_write_some()允许一般地写入异步流I / O对象。例如,此抽象允许更高级别的async_write()组合操作一般写入ip :: tcp :: socket,ssl:stream,serial_port等.async_write_some()成员函数是AsyncWriteStream类型要求的一部分。
-
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 toip::tcp::socket
,ip::udp::socket
,local::*_protocol::socket
, andgeneric::*_protocol::socket
. The presence ofsocket.async_send()
models closely to the established BSD socket API. - socket.async_send()允许一个人一般地写入套接字而不考虑协议。例如,这种抽象允许一个人一般写入ip :: tcp :: socket,ip :: udp :: socket,local :: * _ protocol :: socket和generic :: * _ protocol :: socket。 socket.async_send()的存在与已建立的BSD套接字API密切相关。
#1
3
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-levelasync_write()
composed operation to generically write toip::tcp::socket
,ssl:stream
,serial_port
, etc. Theasync_write_some()
member function is part of the AsyncWriteStream type requirement. - stream.async_write_some()允许一般地写入异步流I / O对象。例如,此抽象允许更高级别的async_write()组合操作一般写入ip :: tcp :: socket,ssl:stream,serial_port等.async_write_some()成员函数是AsyncWriteStream类型要求的一部分。
-
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 toip::tcp::socket
,ip::udp::socket
,local::*_protocol::socket
, andgeneric::*_protocol::socket
. The presence ofsocket.async_send()
models closely to the established BSD socket API. - socket.async_send()允许一个人一般地写入套接字而不考虑协议。例如,这种抽象允许一个人一般写入ip :: tcp :: socket,ip :: udp :: socket,local :: * _ protocol :: socket和generic :: * _ protocol :: socket。 socket.async_send()的存在与已建立的BSD套接字API密切相关。