Подтвердить что ты не робот

Разница между read_some/write_some и получением/отправкой?

Я начинаю работать с сокетами Boost Asio TCP. В чем разница между read_some и receive и в чем разница между write_some и send? Спасибо!

4b9b3361

Ответ 1

Насколько я помню, read_some и получать на самом деле делают то же самое. Я думаю, что получает только вызовы read_some или наоборот. Одно из названий исходит из идеи рассматривать сокет как файл (чтение/запись), в то время как другой - скорее из соединения (send/receive) точки Посмотреть. То же самое должно быть верно для write_some и отправить.

Ответ 2

В Документация BOOST ASIO, раздел Клиенты TCP:

Данные могут быть прочитаны или записаны в подключенный TCP-сокет, используя receive(), async_receive(), send() или async_send(). Однако, поскольку это может привести к короткой записи или читает, вместо этого приложение обычно использует следующие операции: read(), async_read(), write() и async_write().

Ответ 3

то же самое. оба вызова this- > get_service(). send()

 /// 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;
}

from basic_stream_socket.hpp