📄 read.hpp
字号:
//// read.hpp// ~~~~~~~~//// Copyright (c) 2003-2007 Christopher M. Kohlhoff (chris at kohlhoff dot com)//// Distributed under the Boost Software License, Version 1.0. (See accompanying// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)//#ifndef ASIO_READ_HPP#define ASIO_READ_HPP#if defined(_MSC_VER) && (_MSC_VER >= 1200)# pragma once#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)#include "asio/detail/push_options.hpp"#include "asio/detail/push_options.hpp"#include <cstddef>#include <boost/config.hpp>#include "asio/detail/pop_options.hpp"#include "asio/basic_streambuf.hpp"#include "asio/error.hpp"namespace asio {/** * @defgroup read asio::read *//*@{*//// Attempt to read a certain amount of data from a stream before returning./** * This function is used to read a certain number of bytes of data from a * stream. The call will block until one of the following conditions is true: * * @li The supplied buffers are full. That is, the bytes transferred is equal to * the sum of the buffer sizes. * * @li An error occurred. * * This operation is implemented in terms of one or more calls to the stream's * read_some function. * * @param s The stream from which the data is to be read. The type must support * the SyncReadStream concept. * * @param buffers One or more buffers into which the data will be read. The sum * of the buffer sizes indicates the maximum number of bytes to read from the * stream. * * @returns The number of bytes transferred. * * @throws asio::system_error Thrown on failure. * * @par Example * To read into a single data buffer use the @ref buffer function as follows: * @code asio::read(s, asio::buffer(data, size)); @endcode * See the @ref buffer documentation for information on reading into multiple * buffers in one go, and how to use it with arrays, boost::array or * std::vector. * * @note This overload is equivalent to calling: * @code asio::read( * s, buffers, * asio::transfer_all()); @endcode */template <typename SyncReadStream, typename MutableBufferSequence>std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers);/// Attempt to read a certain amount of data from a stream before returning./** * This function is used to read a certain number of bytes of data from a * stream. The call will block until one of the following conditions is true: * * @li The supplied buffers are full. That is, the bytes transferred is equal to * the sum of the buffer sizes. * * @li The completion_condition function object returns true. * * This operation is implemented in terms of one or more calls to the stream's * read_some function. * * @param s The stream from which the data is to be read. The type must support * the SyncReadStream concept. * * @param buffers One or more buffers into which the data will be read. The sum * of the buffer sizes indicates the maximum number of bytes to read from the * stream. * * @param completion_condition The function object to be called to determine * whether the read operation is complete. The signature of the function object * must be: * @code bool completion_condition( * const asio::error_code& error, // Result of latest read_some * // operation. * * std::size_t bytes_transferred // Number of bytes transferred * // so far. * ); @endcode * A return value of true indicates that the read operation is complete. False * indicates that further calls to the stream's read_some function are required. * * @returns The number of bytes transferred. * * @throws asio::system_error Thrown on failure. * * @par Example * To read into a single data buffer use the @ref buffer function as follows: * @code asio::read(s, asio::buffer(data, size), * asio::transfer_at_least(32)); @endcode * See the @ref buffer documentation for information on reading into multiple * buffers in one go, and how to use it with arrays, boost::array or * std::vector. */template <typename SyncReadStream, typename MutableBufferSequence, typename CompletionCondition>std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers, CompletionCondition completion_condition);/// Attempt to read a certain amount of data from a stream before returning./** * This function is used to read a certain number of bytes of data from a * stream. The call will block until one of the following conditions is true: * * @li The supplied buffers are full. That is, the bytes transferred is equal to * the sum of the buffer sizes. * * @li The completion_condition function object returns true. * * This operation is implemented in terms of one or more calls to the stream's * read_some function. * * @param s The stream from which the data is to be read. The type must support * the SyncReadStream concept. * * @param buffers One or more buffers into which the data will be read. The sum * of the buffer sizes indicates the maximum number of bytes to read from the * stream. * * @param completion_condition The function object to be called to determine * whether the read operation is complete. The signature of the function object * must be: * @code bool completion_condition( * const asio::error_code& error, // Result of latest read_some * // operation. * * std::size_t bytes_transferred // Number of bytes transferred * // so far. * ); @endcode * A return value of true indicates that the read operation is complete. False * indicates that further calls to the stream's read_some function are required. * * @param ec Set to indicate what error occurred, if any. * * @returns The number of bytes read. If an error occurs, returns the total * number of bytes successfully transferred prior to the error. */template <typename SyncReadStream, typename MutableBufferSequence, typename CompletionCondition>std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers, CompletionCondition completion_condition, asio::error_code& ec);/// Attempt to read a certain amount of data from a stream before returning./** * This function is used to read a certain number of bytes of data from a * stream. The call will block until one of the following conditions is true: * * @li An error occurred. * * This operation is implemented in terms of one or more calls to the stream's * read_some function. * * @param s The stream from which the data is to be read. The type must support * the SyncReadStream concept. * * @param b The basic_streambuf object into which the data will be read. * * @returns The number of bytes transferred. * * @throws asio::system_error Thrown on failure. * * @note This overload is equivalent to calling: * @code asio::read( * s, b, * asio::transfer_all()); @endcode */template <typename SyncReadStream, typename Allocator>std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b);/// Attempt to read a certain amount of data from a stream before returning./** * This function is used to read a certain number of bytes of data from a * stream. The call will block until one of the following conditions is true: * * @li The completion_condition function object returns true. * * This operation is implemented in terms of one or more calls to the stream's * read_some function. * * @param s The stream from which the data is to be read. The type must support * the SyncReadStream concept. * * @param b The basic_streambuf object into which the data will be read. * * @param completion_condition The function object to be called to determine * whether the read operation is complete. The signature of the function object * must be: * @code bool completion_condition( * const asio::error_code& error, // Result of latest read_some * // operation. * * std::size_t bytes_transferred // Number of bytes transferred * // so far. * ); @endcode * A return value of true indicates that the read operation is complete. False * indicates that further calls to the stream's read_some function are required. * * @returns The number of bytes transferred. * * @throws asio::system_error Thrown on failure. */template <typename SyncReadStream, typename Allocator, typename CompletionCondition>std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b, CompletionCondition completion_condition);/// Attempt to read a certain amount of data from a stream before returning./** * This function is used to read a certain number of bytes of data from a * stream. The call will block until one of the following conditions is true: * * @li The completion_condition function object returns true. * * This operation is implemented in terms of one or more calls to the stream's * read_some function. * * @param s The stream from which the data is to be read. The type must support * the SyncReadStream concept. * * @param b The basic_streambuf object into which the data will be read. * * @param completion_condition The function object to be called to determine * whether the read operation is complete. The signature of the function object * must be: * @code bool completion_condition( * const asio::error_code& error, // Result of latest read_some * // operation. * * std::size_t bytes_transferred // Number of bytes transferred * // so far. * ); @endcode * A return value of true indicates that the read operation is complete. False * indicates that further calls to the stream's read_some function are required. * * @param ec Set to indicate what error occurred, if any.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -