summaryrefslogtreecommitdiff
path: root/boost/asio/read.hpp
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2019-12-05 15:22:41 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2019-12-05 15:22:41 +0900
commit3c1df2168531ad5580076ae08d529054689aeedd (patch)
tree941aff6f86393eecacddfec252a8508c7e8351c9 /boost/asio/read.hpp
parentd6a306e745acfee00e81ccaf3324a2a03516db41 (diff)
downloadboost-3c1df2168531ad5580076ae08d529054689aeedd.tar.gz
boost-3c1df2168531ad5580076ae08d529054689aeedd.tar.bz2
boost-3c1df2168531ad5580076ae08d529054689aeedd.zip
Imported Upstream version 1.70.0upstream/1.70.0
Diffstat (limited to 'boost/asio/read.hpp')
-rw-r--r--boost/asio/read.hpp370
1 files changed, 333 insertions, 37 deletions
diff --git a/boost/asio/read.hpp b/boost/asio/read.hpp
index efa373c3cf..3c4868605b 100644
--- a/boost/asio/read.hpp
+++ b/boost/asio/read.hpp
@@ -2,7 +2,7 @@
// read.hpp
// ~~~~~~~~
//
-// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Copyright (c) 2003-2019 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)
@@ -224,6 +224,8 @@ std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
is_mutable_buffer_sequence<MutableBufferSequence>::value
>::type* = 0);
+#if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
+
/// 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
@@ -251,11 +253,12 @@ std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
* s, buffers,
* boost::asio::transfer_all()); @endcode
*/
-template <typename SyncReadStream, typename DynamicBuffer>
+template <typename SyncReadStream, typename DynamicBuffer_v1>
std::size_t read(SyncReadStream& s,
- BOOST_ASIO_MOVE_ARG(DynamicBuffer) buffers,
+ BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
typename enable_if<
- is_dynamic_buffer<typename decay<DynamicBuffer>::type>::value
+ is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
+ && !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
>::type* = 0);
/// Attempt to read a certain amount of data from a stream before returning.
@@ -284,12 +287,13 @@ std::size_t read(SyncReadStream& s,
* s, buffers,
* boost::asio::transfer_all(), ec); @endcode
*/
-template <typename SyncReadStream, typename DynamicBuffer>
+template <typename SyncReadStream, typename DynamicBuffer_v1>
std::size_t read(SyncReadStream& s,
- BOOST_ASIO_MOVE_ARG(DynamicBuffer) buffers,
+ BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
boost::system::error_code& ec,
typename enable_if<
- is_dynamic_buffer<typename decay<DynamicBuffer>::type>::value
+ is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
+ && !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
>::type* = 0);
/// Attempt to read a certain amount of data from a stream before returning.
@@ -328,13 +332,14 @@ std::size_t read(SyncReadStream& s,
*
* @throws boost::system::system_error Thrown on failure.
*/
-template <typename SyncReadStream, typename DynamicBuffer,
+template <typename SyncReadStream, typename DynamicBuffer_v1,
typename CompletionCondition>
std::size_t read(SyncReadStream& s,
- BOOST_ASIO_MOVE_ARG(DynamicBuffer) buffers,
+ BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
CompletionCondition completion_condition,
typename enable_if<
- is_dynamic_buffer<typename decay<DynamicBuffer>::type>::value
+ is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
+ && !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
>::type* = 0);
/// Attempt to read a certain amount of data from a stream before returning.
@@ -374,13 +379,14 @@ std::size_t read(SyncReadStream& s,
* @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 DynamicBuffer,
+template <typename SyncReadStream, typename DynamicBuffer_v1,
typename CompletionCondition>
std::size_t read(SyncReadStream& s,
- BOOST_ASIO_MOVE_ARG(DynamicBuffer) buffers,
+ BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
CompletionCondition completion_condition, boost::system::error_code& ec,
typename enable_if<
- is_dynamic_buffer<typename decay<DynamicBuffer>::type>::value
+ is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
+ && !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
>::type* = 0);
#if !defined(BOOST_ASIO_NO_EXTENSIONS)
@@ -528,6 +534,162 @@ std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b,
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
#endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
+#endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
+
+/// 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 specified dynamic buffer sequence is full (that is, it has reached
+ * maximum size).
+ *
+ * @li An error occurred.
+ *
+ * This operation is implemented in terms of zero 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 The dynamic buffer sequence into which the data will be read.
+ *
+ * @returns The number of bytes transferred.
+ *
+ * @throws boost::system::system_error Thrown on failure.
+ *
+ * @note This overload is equivalent to calling:
+ * @code boost::asio::read(
+ * s, buffers,
+ * boost::asio::transfer_all()); @endcode
+ */
+template <typename SyncReadStream, typename DynamicBuffer_v2>
+std::size_t read(SyncReadStream& s, DynamicBuffer_v2 buffers,
+ typename enable_if<
+ is_dynamic_buffer_v2<DynamicBuffer_v2>::value
+ >::type* = 0);
+
+/// 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 buffer is full (that is, it has reached maximum size).
+ *
+ * @li An error occurred.
+ *
+ * This operation is implemented in terms of zero 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 The dynamic buffer sequence into which the data will be read.
+ *
+ * @param ec Set to indicate what error occurred, if any.
+ *
+ * @returns The number of bytes transferred.
+ *
+ * @note This overload is equivalent to calling:
+ * @code boost::asio::read(
+ * s, buffers,
+ * boost::asio::transfer_all(), ec); @endcode
+ */
+template <typename SyncReadStream, typename DynamicBuffer_v2>
+std::size_t read(SyncReadStream& s, DynamicBuffer_v2 buffers,
+ boost::system::error_code& ec,
+ typename enable_if<
+ is_dynamic_buffer_v2<DynamicBuffer_v2>::value
+ >::type* = 0);
+
+/// 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 specified dynamic buffer sequence is full (that is, it has reached
+ * maximum size).
+ *
+ * @li The completion_condition function object returns 0.
+ *
+ * This operation is implemented in terms of zero 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 The dynamic buffer sequence 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 std::size_t completion_condition(
+ * // Result of latest read_some operation.
+ * const boost::system::error_code& error,
+ *
+ * // Number of bytes transferred so far.
+ * std::size_t bytes_transferred
+ * ); @endcode
+ * A return value of 0 indicates that the read operation is complete. A non-zero
+ * return value indicates the maximum number of bytes to be read on the next
+ * call to the stream's read_some function.
+ *
+ * @returns The number of bytes transferred.
+ *
+ * @throws boost::system::system_error Thrown on failure.
+ */
+template <typename SyncReadStream, typename DynamicBuffer_v2,
+ typename CompletionCondition>
+std::size_t read(SyncReadStream& s, DynamicBuffer_v2 buffers,
+ CompletionCondition completion_condition,
+ typename enable_if<
+ is_dynamic_buffer_v2<DynamicBuffer_v2>::value
+ >::type* = 0);
+
+/// 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 specified dynamic buffer sequence is full (that is, it has reached
+ * maximum size).
+ *
+ * @li The completion_condition function object returns 0.
+ *
+ * This operation is implemented in terms of zero 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 The dynamic buffer sequence 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 std::size_t completion_condition(
+ * // Result of latest read_some operation.
+ * const boost::system::error_code& error,
+ *
+ * // Number of bytes transferred so far.
+ * std::size_t bytes_transferred
+ * ); @endcode
+ * A return value of 0 indicates that the read operation is complete. A non-zero
+ * return value indicates the maximum number of bytes to be read on the next
+ * call to the stream's read_some function.
+ *
+ * @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 DynamicBuffer_v2,
+ typename CompletionCondition>
+std::size_t read(SyncReadStream& s, DynamicBuffer_v2 buffers,
+ CompletionCondition completion_condition, boost::system::error_code& ec,
+ typename enable_if<
+ is_dynamic_buffer_v2<DynamicBuffer_v2>::value
+ >::type* = 0);
/*@}*/
/**
@@ -579,9 +741,9 @@ std::size_t read(SyncReadStream& s, basic_streambuf<Allocator>& b,
* // prior to the error.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
- * not, the handler will not be invoked from within this function. Invocation of
- * the handler will be performed in a manner equivalent to using
- * boost::asio::io_context::post().
+ * not, the handler will not be invoked from within this function. On
+ * immediate completion, invocation of the handler will be performed in a
+ * manner equivalent to using boost::asio::post().
*
* @par Example
* To read into a single data buffer use the @ref buffer function as follows:
@@ -657,9 +819,9 @@ async_read(AsyncReadStream& s, const MutableBufferSequence& buffers,
* // prior to the error.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
- * not, the handler will not be invoked from within this function. Invocation of
- * the handler will be performed in a manner equivalent to using
- * boost::asio::io_context::post().
+ * not, the handler will not be invoked from within this function. On
+ * immediate completion, invocation of the handler will be performed in a
+ * manner equivalent to using boost::asio::post().
*
* @par Example
* To read into a single data buffer use the @ref buffer function as follows:
@@ -682,6 +844,8 @@ async_read(AsyncReadStream& s, const MutableBufferSequence& buffers,
is_mutable_buffer_sequence<MutableBufferSequence>::value
>::type* = 0);
+#if !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
+
/// Start an asynchronous operation to read a certain amount of data from a
/// stream.
/**
@@ -722,9 +886,9 @@ async_read(AsyncReadStream& s, const MutableBufferSequence& buffers,
* // prior to the error.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
- * not, the handler will not be invoked from within this function. Invocation of
- * the handler will be performed in a manner equivalent to using
- * boost::asio::io_context::post().
+ * not, the handler will not be invoked from within this function. On
+ * immediate completion, invocation of the handler will be performed in a
+ * manner equivalent to using boost::asio::post().
*
* @note This overload is equivalent to calling:
* @code boost::asio::async_read(
@@ -733,14 +897,15 @@ async_read(AsyncReadStream& s, const MutableBufferSequence& buffers,
* handler); @endcode
*/
template <typename AsyncReadStream,
- typename DynamicBuffer, typename ReadHandler>
+ typename DynamicBuffer_v1, typename ReadHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
void (boost::system::error_code, std::size_t))
async_read(AsyncReadStream& s,
- BOOST_ASIO_MOVE_ARG(DynamicBuffer) buffers,
+ BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
BOOST_ASIO_MOVE_ARG(ReadHandler) handler,
typename enable_if<
- is_dynamic_buffer<typename decay<DynamicBuffer>::type>::value
+ is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
+ && !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
>::type* = 0);
/// Start an asynchronous operation to read a certain amount of data from a
@@ -797,20 +962,21 @@ async_read(AsyncReadStream& s,
* // prior to the error.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
- * not, the handler will not be invoked from within this function. Invocation of
- * the handler will be performed in a manner equivalent to using
- * boost::asio::io_context::post().
+ * not, the handler will not be invoked from within this function. On
+ * immediate completion, invocation of the handler will be performed in a
+ * manner equivalent to using boost::asio::post().
*/
-template <typename AsyncReadStream, typename DynamicBuffer,
+template <typename AsyncReadStream, typename DynamicBuffer_v1,
typename CompletionCondition, typename ReadHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
void (boost::system::error_code, std::size_t))
async_read(AsyncReadStream& s,
- BOOST_ASIO_MOVE_ARG(DynamicBuffer) buffers,
+ BOOST_ASIO_MOVE_ARG(DynamicBuffer_v1) buffers,
CompletionCondition completion_condition,
BOOST_ASIO_MOVE_ARG(ReadHandler) handler,
typename enable_if<
- is_dynamic_buffer<typename decay<DynamicBuffer>::type>::value
+ is_dynamic_buffer_v1<typename decay<DynamicBuffer_v1>::type>::value
+ && !is_dynamic_buffer_v2<typename decay<DynamicBuffer_v1>::type>::value
>::type* = 0);
#if !defined(BOOST_ASIO_NO_EXTENSIONS)
@@ -854,9 +1020,9 @@ async_read(AsyncReadStream& s,
* // prior to the error.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
- * not, the handler will not be invoked from within this function. Invocation of
- * the handler will be performed in a manner equivalent to using
- * boost::asio::io_context::post().
+ * not, the handler will not be invoked from within this function. On
+ * immediate completion, invocation of the handler will be performed in a
+ * manner equivalent to using boost::asio::post().
*
* @note This overload is equivalent to calling:
* @code boost::asio::async_read(
@@ -922,9 +1088,9 @@ async_read(AsyncReadStream& s, basic_streambuf<Allocator>& b,
* // prior to the error.
* ); @endcode
* Regardless of whether the asynchronous operation completes immediately or
- * not, the handler will not be invoked from within this function. Invocation of
- * the handler will be performed in a manner equivalent to using
- * boost::asio::io_context::post().
+ * not, the handler will not be invoked from within this function. On
+ * immediate completion, invocation of the handler will be performed in a
+ * manner equivalent to using boost::asio::post().
*/
template <typename AsyncReadStream, typename Allocator,
typename CompletionCondition, typename ReadHandler>
@@ -936,6 +1102,136 @@ async_read(AsyncReadStream& s, basic_streambuf<Allocator>& b,
#endif // !defined(BOOST_ASIO_NO_IOSTREAM)
#endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
+#endif // !defined(BOOST_ASIO_NO_DYNAMIC_BUFFER_V1)
+
+/// Start an asynchronous operation to read a certain amount of data from a
+/// stream.
+/**
+ * This function is used to asynchronously read a certain number of bytes of
+ * data from a stream. The function call always returns immediately. The
+ * asynchronous operation will continue until one of the following conditions is
+ * true:
+ *
+ * @li The specified dynamic buffer sequence is full (that is, it has reached
+ * maximum size).
+ *
+ * @li An error occurred.
+ *
+ * This operation is implemented in terms of zero or more calls to the stream's
+ * async_read_some function, and is known as a <em>composed operation</em>. The
+ * program must ensure that the stream performs no other read operations (such
+ * as async_read, the stream's async_read_some function, or any other composed
+ * operations that perform reads) until this operation completes.
+ *
+ * @param s The stream from which the data is to be read. The type must support
+ * the AsyncReadStream concept.
+ *
+ * @param buffers The dynamic buffer sequence into which the data will be read.
+ * Although the buffers object may be copied as necessary, ownership of the
+ * underlying memory blocks is retained by the caller, which must guarantee
+ * that they remain valid until the handler is called.
+ *
+ * @param handler The handler to be called when the read operation completes.
+ * Copies will be made of the handler as required. The function signature of the
+ * handler must be:
+ * @code void handler(
+ * const boost::system::error_code& error, // Result of operation.
+ *
+ * std::size_t bytes_transferred // Number of bytes copied into the
+ * // buffers. If an error occurred,
+ * // this will be the number of
+ * // bytes successfully transferred
+ * // prior to the error.
+ * ); @endcode
+ * Regardless of whether the asynchronous operation completes immediately or
+ * not, the handler will not be invoked from within this function. On
+ * immediate completion, invocation of the handler will be performed in a
+ * manner equivalent to using boost::asio::post().
+ *
+ * @note This overload is equivalent to calling:
+ * @code boost::asio::async_read(
+ * s, buffers,
+ * boost::asio::transfer_all(),
+ * handler); @endcode
+ */
+template <typename AsyncReadStream,
+ typename DynamicBuffer_v2, typename ReadHandler>
+BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
+ void (boost::system::error_code, std::size_t))
+async_read(AsyncReadStream& s, DynamicBuffer_v2 buffers,
+ BOOST_ASIO_MOVE_ARG(ReadHandler) handler,
+ typename enable_if<
+ is_dynamic_buffer_v2<DynamicBuffer_v2>::value
+ >::type* = 0);
+
+/// Start an asynchronous operation to read a certain amount of data from a
+/// stream.
+/**
+ * This function is used to asynchronously read a certain number of bytes of
+ * data from a stream. The function call always returns immediately. The
+ * asynchronous operation will continue until one of the following conditions is
+ * true:
+ *
+ * @li The specified dynamic buffer sequence is full (that is, it has reached
+ * maximum size).
+ *
+ * @li The completion_condition function object returns 0.
+ *
+ * This operation is implemented in terms of zero or more calls to the stream's
+ * async_read_some function, and is known as a <em>composed operation</em>. The
+ * program must ensure that the stream performs no other read operations (such
+ * as async_read, the stream's async_read_some function, or any other composed
+ * operations that perform reads) until this operation completes.
+ *
+ * @param s The stream from which the data is to be read. The type must support
+ * the AsyncReadStream concept.
+ *
+ * @param buffers The dynamic buffer sequence into which the data will be read.
+ * Although the buffers object may be copied as necessary, ownership of the
+ * underlying memory blocks is retained by the caller, which must guarantee
+ * that they remain valid until the handler is called.
+ *
+ * @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 std::size_t completion_condition(
+ * // Result of latest async_read_some operation.
+ * const boost::system::error_code& error,
+ *
+ * // Number of bytes transferred so far.
+ * std::size_t bytes_transferred
+ * ); @endcode
+ * A return value of 0 indicates that the read operation is complete. A non-zero
+ * return value indicates the maximum number of bytes to be read on the next
+ * call to the stream's async_read_some function.
+ *
+ * @param handler The handler to be called when the read operation completes.
+ * Copies will be made of the handler as required. The function signature of the
+ * handler must be:
+ * @code void handler(
+ * const boost::system::error_code& error, // Result of operation.
+ *
+ * std::size_t bytes_transferred // Number of bytes copied into the
+ * // buffers. If an error occurred,
+ * // this will be the number of
+ * // bytes successfully transferred
+ * // prior to the error.
+ * ); @endcode
+ * Regardless of whether the asynchronous operation completes immediately or
+ * not, the handler will not be invoked from within this function. On
+ * immediate completion, invocation of the handler will be performed in a
+ * manner equivalent to using boost::asio::post().
+ */
+template <typename AsyncReadStream, typename DynamicBuffer_v2,
+ typename CompletionCondition, typename ReadHandler>
+BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
+ void (boost::system::error_code, std::size_t))
+async_read(AsyncReadStream& s, DynamicBuffer_v2 buffers,
+ CompletionCondition completion_condition,
+ BOOST_ASIO_MOVE_ARG(ReadHandler) handler,
+ typename enable_if<
+ is_dynamic_buffer_v2<DynamicBuffer_v2>::value
+ >::type* = 0);
/*@}*/