我开始使用Boost Asio的TCP套接字。 read_some
和receive
之间的区别是什么,write_some
和send
之间的区别是什么?谢谢!read_some/write_some和receive/send之间的区别?
10
A
回答
8
据我记得,read_some和收到实际上是一样的。我认为只需要调用read_some,反之亦然。在一个命名来源于治疗插座为文件(读/写)的想法,而另一人,而来自于连接(发送/接收)的观点。 write_some和发送也应如此。
0
相同。 。都调用了这个 - > get_service()发送()
/// Send some data on the socket.
/**
* This function is used to send data on the stream socket. The function
* call will block until one or more bytes of the data has been sent
* successfully, or an until error occurs.
*
* @param buffers One or more data buffers to be sent on the socket.
*
* @returns The number of bytes sent.
*
* @throws boost::system::system_error Thrown on failure.
*
* @note The send operation may not transmit all of the data to the peer.
* Consider using the @ref write function if you need to ensure that all data
* is written before the blocking operation completes.
*
* @par Example
* To send a single data buffer use the @ref buffer function as follows:
* @code
* socket.send(boost::asio::buffer(data, size));
* @endcode
* See the @ref buffer documentation for information on sending multiple
* buffers in one go, and how to use it with arrays, boost::array or
* std::vector.
*/
template <typename ConstBufferSequence>
std::size_t send(const ConstBufferSequence& buffers)
{
boost::system::error_code ec;
std::size_t s = this->get_service().send(
this->get_implementation(), buffers, 0, ec);
boost::asio::detail::throw_error(ec, "send");
return s;
}
////////////////////////////////////////////
template <typename ConstBufferSequence>
std::size_t write_some(const ConstBufferSequence& buffers)
{
boost::system::error_code ec;
std::size_t s = this->get_service().send(
this->get_implementation(), buffers, 0, ec);
boost::asio::detail::throw_error(ec, "write_some");
return s;
}
从basic_stream_socket.hpp
4
在BOOST ASIO documentation,部分TCP客户端说:
的数据可以被读取或写入到receive(),async_receive(),send()或async_send()成员函数使用 连接的TCP套接字。 然而,因为这些可能导致short writes or reads, 应用程序通常会使用以下操作来代替: 的read(),async_read(),write()方法和ASYNC_WRITE()。
相关问题
- 1. 之间的〜/和的区别../
- 2. '#','%'和'$'之间的区别
- 3. {!!之间的区别!!}和{{}}
- 4. '+ ='和'= +'之间的区别?
- 5. “。+”和“。+?”之间的区别
- 6. .eq之间的区别。和==
- 7. #。/和#之间的区别。 ./
- 8. !=和!之间的区别==
- 9. “%〜dp0”和“。\”之间的区别?
- 10. | =和^ = css之间的区别
- 11. 之间的区别。和#
- 12. ==和case之间的区别?
- 13. “**/* /”和“** /”之间的区别?
- 14. jQuery - '。'之间的区别和“#”
- 15. “?1”和“?”之间的区别
- 16. `%in%`和`==`之间的区别
- 17. fmod和%之间的区别
- 18. 之间的区别:+和:+
- 19. 类区域和堆之间的区别
- 20. SPFile和PublishingPage类别之间的区别
- 21. 子类和类别之间的区别?
- 22. System.Timers.Timer Enabled = true和.Start()之间的区别Enabled = true和.Start()之间的区别
- 23. isForeground()和onExposed和onObscured之间的区别
- 24. $ .ajax()和$ .get()和$ .load()之间的区别
- 25. 和intent和setcontentview之间的区别
- 26. Java和C#和.NET之间的区别
- 27. NSthread和NStimer和NSNotifcation之间的区别?
- 28. sys.log()和console.log()和console.error()之间的区别?
- 29. 关注与责任之间的区别(即SRP和SoC之间的区别)?
- 30. make中的“$(shell ...)”和“$$(...)”之间的区别
你有一定的参考/链接?我在boost文档中找不到任何内容,boost示例不使用'send' /'receive'。 – overcoder