Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-11 08:05:33

0001 //
0002 // read_at.hpp
0003 // ~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_READ_AT_HPP
0012 #define BOOST_ASIO_READ_AT_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 #include <cstddef>
0020 #include <boost/asio/async_result.hpp>
0021 #include <boost/asio/completion_condition.hpp>
0022 #include <boost/asio/detail/cstdint.hpp>
0023 #include <boost/asio/error.hpp>
0024 
0025 #if !defined(BOOST_ASIO_NO_EXTENSIONS)
0026 # include <boost/asio/basic_streambuf_fwd.hpp>
0027 #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
0028 
0029 #include <boost/asio/detail/push_options.hpp>
0030 
0031 namespace boost {
0032 namespace asio {
0033 namespace detail {
0034 
0035 template <typename> class initiate_async_read_at;
0036 #if !defined(BOOST_ASIO_NO_IOSTREAM)
0037 template <typename> class initiate_async_read_at_streambuf;
0038 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
0039 
0040 } // namespace detail
0041 
0042 /**
0043  * @defgroup read_at boost::asio::read_at
0044  *
0045  * @brief The @c read_at function is a composed operation that reads a certain
0046  * amount of data at the specified offset before returning.
0047  */
0048 /*@{*/
0049 
0050 /// Attempt to read a certain amount of data at the specified offset before
0051 /// returning.
0052 /**
0053  * This function is used to read a certain number of bytes of data from a
0054  * random access device at the specified offset. The call will block until one
0055  * of the following conditions is true:
0056  *
0057  * @li The supplied buffers are full. That is, the bytes transferred is equal to
0058  * the sum of the buffer sizes.
0059  *
0060  * @li An error occurred.
0061  *
0062  * This operation is implemented in terms of zero or more calls to the device's
0063  * read_some_at function.
0064  *
0065  * @param d The device from which the data is to be read. The type must support
0066  * the SyncRandomAccessReadDevice concept.
0067  *
0068  * @param offset The offset at which the data will be read.
0069  *
0070  * @param buffers One or more buffers into which the data will be read. The sum
0071  * of the buffer sizes indicates the maximum number of bytes to read from the
0072  * device.
0073  *
0074  * @returns The number of bytes transferred.
0075  *
0076  * @throws boost::system::system_error Thrown on failure.
0077  *
0078  * @par Example
0079  * To read into a single data buffer use the @ref buffer function as follows:
0080  * @code boost::asio::read_at(d, 42, boost::asio::buffer(data, size)); @endcode
0081  * See the @ref buffer documentation for information on reading into multiple
0082  * buffers in one go, and how to use it with arrays, boost::array or
0083  * std::vector.
0084  *
0085  * @note This overload is equivalent to calling:
0086  * @code boost::asio::read_at(
0087  *     d, 42, buffers,
0088  *     boost::asio::transfer_all()); @endcode
0089  */
0090 template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence>
0091 std::size_t read_at(SyncRandomAccessReadDevice& d,
0092     uint64_t offset, const MutableBufferSequence& buffers);
0093 
0094 /// Attempt to read a certain amount of data at the specified offset before
0095 /// returning.
0096 /**
0097  * This function is used to read a certain number of bytes of data from a
0098  * random access device at the specified offset. The call will block until one
0099  * of the following conditions is true:
0100  *
0101  * @li The supplied buffers are full. That is, the bytes transferred is equal to
0102  * the sum of the buffer sizes.
0103  *
0104  * @li An error occurred.
0105  *
0106  * This operation is implemented in terms of zero or more calls to the device's
0107  * read_some_at function.
0108  *
0109  * @param d The device from which the data is to be read. The type must support
0110  * the SyncRandomAccessReadDevice concept.
0111  *
0112  * @param offset The offset at which the data will be read.
0113  *
0114  * @param buffers One or more buffers into which the data will be read. The sum
0115  * of the buffer sizes indicates the maximum number of bytes to read from the
0116  * device.
0117  *
0118  * @param ec Set to indicate what error occurred, if any.
0119  *
0120  * @returns The number of bytes transferred.
0121  *
0122  * @par Example
0123  * To read into a single data buffer use the @ref buffer function as follows:
0124  * @code boost::asio::read_at(d, 42,
0125  *     boost::asio::buffer(data, size), ec); @endcode
0126  * See the @ref buffer documentation for information on reading into multiple
0127  * buffers in one go, and how to use it with arrays, boost::array or
0128  * std::vector.
0129  *
0130  * @note This overload is equivalent to calling:
0131  * @code boost::asio::read_at(
0132  *     d, 42, buffers,
0133  *     boost::asio::transfer_all(), ec); @endcode
0134  */
0135 template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence>
0136 std::size_t read_at(SyncRandomAccessReadDevice& d,
0137     uint64_t offset, const MutableBufferSequence& buffers,
0138     boost::system::error_code& ec);
0139 
0140 /// Attempt to read a certain amount of data at the specified offset before
0141 /// returning.
0142 /**
0143  * This function is used to read a certain number of bytes of data from a
0144  * random access device at the specified offset. The call will block until one
0145  * of the following conditions is true:
0146  *
0147  * @li The supplied buffers are full. That is, the bytes transferred is equal to
0148  * the sum of the buffer sizes.
0149  *
0150  * @li The completion_condition function object returns 0.
0151  *
0152  * This operation is implemented in terms of zero or more calls to the device's
0153  * read_some_at function.
0154  *
0155  * @param d The device from which the data is to be read. The type must support
0156  * the SyncRandomAccessReadDevice concept.
0157  *
0158  * @param offset The offset at which the data will be read.
0159  *
0160  * @param buffers One or more buffers into which the data will be read. The sum
0161  * of the buffer sizes indicates the maximum number of bytes to read from the
0162  * device.
0163  *
0164  * @param completion_condition The function object to be called to determine
0165  * whether the read operation is complete. The signature of the function object
0166  * must be:
0167  * @code std::size_t completion_condition(
0168  *   // Result of latest read_some_at operation.
0169  *   const boost::system::error_code& error,
0170  *
0171  *   // Number of bytes transferred so far.
0172  *   std::size_t bytes_transferred
0173  * ); @endcode
0174  * A return value of 0 indicates that the read operation is complete. A non-zero
0175  * return value indicates the maximum number of bytes to be read on the next
0176  * call to the device's read_some_at function.
0177  *
0178  * @returns The number of bytes transferred.
0179  *
0180  * @throws boost::system::system_error Thrown on failure.
0181  *
0182  * @par Example
0183  * To read into a single data buffer use the @ref buffer function as follows:
0184  * @code boost::asio::read_at(d, 42, boost::asio::buffer(data, size),
0185  *     boost::asio::transfer_at_least(32)); @endcode
0186  * See the @ref buffer documentation for information on reading into multiple
0187  * buffers in one go, and how to use it with arrays, boost::array or
0188  * std::vector.
0189  */
0190 template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence,
0191     typename CompletionCondition>
0192 std::size_t read_at(SyncRandomAccessReadDevice& d,
0193     uint64_t offset, const MutableBufferSequence& buffers,
0194     CompletionCondition completion_condition,
0195     constraint_t<
0196       is_completion_condition<CompletionCondition>::value
0197     > = 0);
0198 
0199 /// Attempt to read a certain amount of data at the specified offset before
0200 /// returning.
0201 /**
0202  * This function is used to read a certain number of bytes of data from a
0203  * random access device at the specified offset. The call will block until one
0204  * of the following conditions is true:
0205  *
0206  * @li The supplied buffers are full. That is, the bytes transferred is equal to
0207  * the sum of the buffer sizes.
0208  *
0209  * @li The completion_condition function object returns 0.
0210  *
0211  * This operation is implemented in terms of zero or more calls to the device's
0212  * read_some_at function.
0213  *
0214  * @param d The device from which the data is to be read. The type must support
0215  * the SyncRandomAccessReadDevice concept.
0216  *
0217  * @param offset The offset at which the data will be read.
0218  *
0219  * @param buffers One or more buffers into which the data will be read. The sum
0220  * of the buffer sizes indicates the maximum number of bytes to read from the
0221  * device.
0222  *
0223  * @param completion_condition The function object to be called to determine
0224  * whether the read operation is complete. The signature of the function object
0225  * must be:
0226  * @code std::size_t completion_condition(
0227  *   // Result of latest read_some_at operation.
0228  *   const boost::system::error_code& error,
0229  *
0230  *   // Number of bytes transferred so far.
0231  *   std::size_t bytes_transferred
0232  * ); @endcode
0233  * A return value of 0 indicates that the read operation is complete. A non-zero
0234  * return value indicates the maximum number of bytes to be read on the next
0235  * call to the device's read_some_at function.
0236  *
0237  * @param ec Set to indicate what error occurred, if any.
0238  *
0239  * @returns The number of bytes read. If an error occurs, returns the total
0240  * number of bytes successfully transferred prior to the error.
0241  */
0242 template <typename SyncRandomAccessReadDevice, typename MutableBufferSequence,
0243     typename CompletionCondition>
0244 std::size_t read_at(SyncRandomAccessReadDevice& d,
0245     uint64_t offset, const MutableBufferSequence& buffers,
0246     CompletionCondition completion_condition, boost::system::error_code& ec,
0247     constraint_t<
0248       is_completion_condition<CompletionCondition>::value
0249     > = 0);
0250 
0251 #if !defined(BOOST_ASIO_NO_EXTENSIONS)
0252 #if !defined(BOOST_ASIO_NO_IOSTREAM)
0253 
0254 /// Attempt to read a certain amount of data at the specified offset before
0255 /// returning.
0256 /**
0257  * This function is used to read a certain number of bytes of data from a
0258  * random access device at the specified offset. The call will block until one
0259  * of the following conditions is true:
0260  *
0261  * @li An error occurred.
0262  *
0263  * This operation is implemented in terms of zero or more calls to the device's
0264  * read_some_at function.
0265  *
0266  * @param d The device from which the data is to be read. The type must support
0267  * the SyncRandomAccessReadDevice concept.
0268  *
0269  * @param offset The offset at which the data will be read.
0270  *
0271  * @param b The basic_streambuf object into which the data will be read.
0272  *
0273  * @returns The number of bytes transferred.
0274  *
0275  * @throws boost::system::system_error Thrown on failure.
0276  *
0277  * @note This overload is equivalent to calling:
0278  * @code boost::asio::read_at(
0279  *     d, 42, b,
0280  *     boost::asio::transfer_all()); @endcode
0281  */
0282 template <typename SyncRandomAccessReadDevice, typename Allocator>
0283 std::size_t read_at(SyncRandomAccessReadDevice& d,
0284     uint64_t offset, basic_streambuf<Allocator>& b);
0285 
0286 /// Attempt to read a certain amount of data at the specified offset before
0287 /// returning.
0288 /**
0289  * This function is used to read a certain number of bytes of data from a
0290  * random access device at the specified offset. The call will block until one
0291  * of the following conditions is true:
0292  *
0293  * @li An error occurred.
0294  *
0295  * This operation is implemented in terms of zero or more calls to the device's
0296  * read_some_at function.
0297  *
0298  * @param d The device from which the data is to be read. The type must support
0299  * the SyncRandomAccessReadDevice concept.
0300  *
0301  * @param offset The offset at which the data will be read.
0302  *
0303  * @param b The basic_streambuf object into which the data will be read.
0304  *
0305  * @param ec Set to indicate what error occurred, if any.
0306  *
0307  * @returns The number of bytes transferred.
0308  *
0309  * @note This overload is equivalent to calling:
0310  * @code boost::asio::read_at(
0311  *     d, 42, b,
0312  *     boost::asio::transfer_all(), ec); @endcode
0313  */
0314 template <typename SyncRandomAccessReadDevice, typename Allocator>
0315 std::size_t read_at(SyncRandomAccessReadDevice& d,
0316     uint64_t offset, basic_streambuf<Allocator>& b,
0317     boost::system::error_code& ec);
0318 
0319 /// Attempt to read a certain amount of data at the specified offset before
0320 /// returning.
0321 /**
0322  * This function is used to read a certain number of bytes of data from a
0323  * random access device at the specified offset. The call will block until one
0324  * of the following conditions is true:
0325  *
0326  * @li The completion_condition function object returns 0.
0327  *
0328  * This operation is implemented in terms of zero or more calls to the device's
0329  * read_some_at function.
0330  *
0331  * @param d The device from which the data is to be read. The type must support
0332  * the SyncRandomAccessReadDevice concept.
0333  *
0334  * @param offset The offset at which the data will be read.
0335  *
0336  * @param b The basic_streambuf object into which the data will be read.
0337  *
0338  * @param completion_condition The function object to be called to determine
0339  * whether the read operation is complete. The signature of the function object
0340  * must be:
0341  * @code std::size_t completion_condition(
0342  *   // Result of latest read_some_at operation.
0343  *   const boost::system::error_code& error,
0344  *
0345  *   // Number of bytes transferred so far.
0346  *   std::size_t bytes_transferred
0347  * ); @endcode
0348  * A return value of 0 indicates that the read operation is complete. A non-zero
0349  * return value indicates the maximum number of bytes to be read on the next
0350  * call to the device's read_some_at function.
0351  *
0352  * @returns The number of bytes transferred.
0353  *
0354  * @throws boost::system::system_error Thrown on failure.
0355  */
0356 template <typename SyncRandomAccessReadDevice, typename Allocator,
0357     typename CompletionCondition>
0358 std::size_t read_at(SyncRandomAccessReadDevice& d,
0359     uint64_t offset, basic_streambuf<Allocator>& b,
0360     CompletionCondition completion_condition,
0361     constraint_t<
0362       is_completion_condition<CompletionCondition>::value
0363     > = 0);
0364 
0365 /// Attempt to read a certain amount of data at the specified offset before
0366 /// returning.
0367 /**
0368  * This function is used to read a certain number of bytes of data from a
0369  * random access device at the specified offset. The call will block until one
0370  * of the following conditions is true:
0371  *
0372  * @li The completion_condition function object returns 0.
0373  *
0374  * This operation is implemented in terms of zero or more calls to the device's
0375  * read_some_at function.
0376  *
0377  * @param d The device from which the data is to be read. The type must support
0378  * the SyncRandomAccessReadDevice concept.
0379  *
0380  * @param offset The offset at which the data will be read.
0381  *
0382  * @param b The basic_streambuf object into which the data will be read.
0383  *
0384  * @param completion_condition The function object to be called to determine
0385  * whether the read operation is complete. The signature of the function object
0386  * must be:
0387  * @code std::size_t completion_condition(
0388  *   // Result of latest read_some_at operation.
0389  *   const boost::system::error_code& error,
0390  *
0391  *   // Number of bytes transferred so far.
0392  *   std::size_t bytes_transferred
0393  * ); @endcode
0394  * A return value of 0 indicates that the read operation is complete. A non-zero
0395  * return value indicates the maximum number of bytes to be read on the next
0396  * call to the device's read_some_at function.
0397  *
0398  * @param ec Set to indicate what error occurred, if any.
0399  *
0400  * @returns The number of bytes read. If an error occurs, returns the total
0401  * number of bytes successfully transferred prior to the error.
0402  */
0403 template <typename SyncRandomAccessReadDevice, typename Allocator,
0404     typename CompletionCondition>
0405 std::size_t read_at(SyncRandomAccessReadDevice& d,
0406     uint64_t offset, basic_streambuf<Allocator>& b,
0407     CompletionCondition completion_condition, boost::system::error_code& ec,
0408     constraint_t<
0409       is_completion_condition<CompletionCondition>::value
0410     > = 0);
0411 
0412 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
0413 #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
0414 
0415 /*@}*/
0416 /**
0417  * @defgroup async_read_at boost::asio::async_read_at
0418  *
0419  * @brief The @c async_read_at function is a composed asynchronous operation
0420  * that reads a certain amount of data at the specified offset.
0421  */
0422 /*@{*/
0423 
0424 /// Start an asynchronous operation to read a certain amount of data at the
0425 /// specified offset.
0426 /**
0427  * This function is used to asynchronously read a certain number of bytes of
0428  * data from a random access device at the specified offset. It is an
0429  * initiating function for an @ref asynchronous_operation, and always returns
0430  * immediately. The asynchronous operation will continue until one of the
0431  * following conditions is true:
0432  *
0433  * @li The supplied buffers are full. That is, the bytes transferred is equal to
0434  * the sum of the buffer sizes.
0435  *
0436  * @li An error occurred.
0437  *
0438  * This operation is implemented in terms of zero or more calls to the device's
0439  * async_read_some_at function.
0440  *
0441  * @param d The device from which the data is to be read. The type must support
0442  * the AsyncRandomAccessReadDevice concept.
0443  *
0444  * @param offset The offset at which the data will be read.
0445  *
0446  * @param buffers One or more buffers into which the data will be read. The sum
0447  * of the buffer sizes indicates the maximum number of bytes to read from the
0448  * device. Although the buffers object may be copied as necessary, ownership of
0449  * the underlying memory blocks is retained by the caller, which must guarantee
0450  * that they remain valid until the completion handler is called.
0451  *
0452  * @param token The @ref completion_token that will be used to produce a
0453  * completion handler, which will be called when the read completes.
0454  * Potential completion tokens include @ref use_future, @ref use_awaitable,
0455  * @ref yield_context, or a function object with the correct completion
0456  * signature. The function signature of the completion handler must be:
0457  * @code void handler(
0458  *   // Result of operation.
0459  *   const boost::system::error_code& error,
0460  *
0461  *   // Number of bytes copied into the buffers. If an error
0462  *   // occurred, this will be the number of bytes successfully
0463  *   // transferred prior to the error.
0464  *   std::size_t bytes_transferred
0465  * ); @endcode
0466  * Regardless of whether the asynchronous operation completes immediately or
0467  * not, the completion handler will not be invoked from within this function.
0468  * On immediate completion, invocation of the handler will be performed in a
0469  * manner equivalent to using boost::asio::async_immediate().
0470  *
0471  * @par Completion Signature
0472  * @code void(boost::system::error_code, std::size_t) @endcode
0473  *
0474  * @par Example
0475  * To read into a single data buffer use the @ref buffer function as follows:
0476  * @code
0477  * boost::asio::async_read_at(d, 42, boost::asio::buffer(data, size), handler);
0478  * @endcode
0479  * See the @ref buffer documentation for information on reading into multiple
0480  * buffers in one go, and how to use it with arrays, boost::array or
0481  * std::vector.
0482  *
0483  * @note This overload is equivalent to calling:
0484  * @code boost::asio::async_read_at(
0485  *     d, 42, buffers,
0486  *     boost::asio::transfer_all(),
0487  *     handler); @endcode
0488  *
0489  * @par Per-Operation Cancellation
0490  * This asynchronous operation supports cancellation for the following
0491  * boost::asio::cancellation_type values:
0492  *
0493  * @li @c cancellation_type::terminal
0494  *
0495  * @li @c cancellation_type::partial
0496  *
0497  * if they are also supported by the @c AsyncRandomAccessReadDevice type's
0498  * async_read_some_at operation.
0499  */
0500 template <typename AsyncRandomAccessReadDevice, typename MutableBufferSequence,
0501     BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0502       std::size_t)) ReadToken = default_completion_token_t<
0503         typename AsyncRandomAccessReadDevice::executor_type>>
0504 inline auto async_read_at(AsyncRandomAccessReadDevice& d,
0505     uint64_t offset, const MutableBufferSequence& buffers,
0506     ReadToken&& token = default_completion_token_t<
0507       typename AsyncRandomAccessReadDevice::executor_type>(),
0508     constraint_t<
0509       !is_completion_condition<ReadToken>::value
0510     > = 0)
0511   -> decltype(
0512     async_initiate<ReadToken,
0513       void (boost::system::error_code, std::size_t)>(
0514         declval<detail::initiate_async_read_at<AsyncRandomAccessReadDevice>>(),
0515         token, offset, buffers, transfer_all()))
0516 {
0517   return async_initiate<ReadToken,
0518     void (boost::system::error_code, std::size_t)>(
0519       detail::initiate_async_read_at<AsyncRandomAccessReadDevice>(d),
0520       token, offset, buffers, transfer_all());
0521 }
0522 
0523 /// Start an asynchronous operation to read a certain amount of data at the
0524 /// specified offset.
0525 /**
0526  * This function is used to asynchronously read a certain number of bytes of
0527  * data from a random access device at the specified offset. It is an
0528  * initiating function for an @ref asynchronous_operation, and always returns
0529  * immediately. The asynchronous operation will continue until one of the
0530  * following conditions is true:
0531  *
0532  * @li The supplied buffers are full. That is, the bytes transferred is equal to
0533  * the sum of the buffer sizes.
0534  *
0535  * @li The completion_condition function object returns 0.
0536  *
0537  * @param d The device from which the data is to be read. The type must support
0538  * the AsyncRandomAccessReadDevice concept.
0539  *
0540  * @param offset The offset at which the data will be read.
0541  *
0542  * @param buffers One or more buffers into which the data will be read. The sum
0543  * of the buffer sizes indicates the maximum number of bytes to read from the
0544  * device. Although the buffers object may be copied as necessary, ownership of
0545  * the underlying memory blocks is retained by the caller, which must guarantee
0546  * that they remain valid until the completion handler is called.
0547  *
0548  * @param completion_condition The function object to be called to determine
0549  * whether the read operation is complete. The signature of the function object
0550  * must be:
0551  * @code std::size_t completion_condition(
0552  *   // Result of latest async_read_some_at operation.
0553  *   const boost::system::error_code& error,
0554  *
0555  *   // Number of bytes transferred so far.
0556  *   std::size_t bytes_transferred
0557  * ); @endcode
0558  * A return value of 0 indicates that the read operation is complete. A non-zero
0559  * return value indicates the maximum number of bytes to be read on the next
0560  * call to the device's async_read_some_at function.
0561  *
0562  * @param token The @ref completion_token that will be used to produce a
0563  * completion handler, which will be called when the read completes.
0564  * Potential completion tokens include @ref use_future, @ref use_awaitable,
0565  * @ref yield_context, or a function object with the correct completion
0566  * signature. The function signature of the completion handler must be:
0567  * @code void handler(
0568  *   // Result of operation.
0569  *   const boost::system::error_code& error,
0570  *
0571  *   // Number of bytes copied into the buffers. If an error
0572  *   // occurred, this will be the number of bytes successfully
0573  *   // transferred prior to the error.
0574  *   std::size_t bytes_transferred
0575  * ); @endcode
0576  * Regardless of whether the asynchronous operation completes immediately or
0577  * not, the completion handler will not be invoked from within this function.
0578  * On immediate completion, invocation of the handler will be performed in a
0579  * manner equivalent to using boost::asio::async_immediate().
0580  *
0581  * @par Completion Signature
0582  * @code void(boost::system::error_code, std::size_t) @endcode
0583  *
0584  * @par Example
0585  * To read into a single data buffer use the @ref buffer function as follows:
0586  * @code boost::asio::async_read_at(d, 42,
0587  *     boost::asio::buffer(data, size),
0588  *     boost::asio::transfer_at_least(32),
0589  *     handler); @endcode
0590  * See the @ref buffer documentation for information on reading into multiple
0591  * buffers in one go, and how to use it with arrays, boost::array or
0592  * std::vector.
0593  *
0594  * @par Per-Operation Cancellation
0595  * This asynchronous operation supports cancellation for the following
0596  * boost::asio::cancellation_type values:
0597  *
0598  * @li @c cancellation_type::terminal
0599  *
0600  * @li @c cancellation_type::partial
0601  *
0602  * if they are also supported by the @c AsyncRandomAccessReadDevice type's
0603  * async_read_some_at operation.
0604  */
0605 template <typename AsyncRandomAccessReadDevice,
0606     typename MutableBufferSequence, typename CompletionCondition,
0607     BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0608       std::size_t)) ReadToken = default_completion_token_t<
0609         typename AsyncRandomAccessReadDevice::executor_type>>
0610 inline auto async_read_at(AsyncRandomAccessReadDevice& d,
0611     uint64_t offset, const MutableBufferSequence& buffers,
0612     CompletionCondition completion_condition,
0613     ReadToken&& token = default_completion_token_t<
0614       typename AsyncRandomAccessReadDevice::executor_type>(),
0615     constraint_t<
0616       is_completion_condition<CompletionCondition>::value
0617     > = 0)
0618   -> decltype(
0619     async_initiate<ReadToken,
0620       void (boost::system::error_code, std::size_t)>(
0621         declval<detail::initiate_async_read_at<AsyncRandomAccessReadDevice>>(),
0622         token, offset, buffers,
0623         static_cast<CompletionCondition&&>(completion_condition)))
0624 {
0625   return async_initiate<ReadToken,
0626     void (boost::system::error_code, std::size_t)>(
0627       detail::initiate_async_read_at<AsyncRandomAccessReadDevice>(d),
0628       token, offset, buffers,
0629       static_cast<CompletionCondition&&>(completion_condition));
0630 }
0631 
0632 #if !defined(BOOST_ASIO_NO_EXTENSIONS)
0633 #if !defined(BOOST_ASIO_NO_IOSTREAM)
0634 
0635 /// Start an asynchronous operation to read a certain amount of data at the
0636 /// specified offset.
0637 /**
0638  * This function is used to asynchronously read a certain number of bytes of
0639  * data from a random access device at the specified offset. It is an
0640  * initiating function for an @ref asynchronous_operation, and always returns
0641  * immediately. The asynchronous operation will continue until one of the
0642  * following conditions is true:
0643  *
0644  * @li An error occurred.
0645  *
0646  * This operation is implemented in terms of zero or more calls to the device's
0647  * async_read_some_at function.
0648  *
0649  * @param d The device from which the data is to be read. The type must support
0650  * the AsyncRandomAccessReadDevice concept.
0651  *
0652  * @param offset The offset at which the data will be read.
0653  *
0654  * @param b A basic_streambuf object into which the data will be read. Ownership
0655  * of the streambuf is retained by the caller, which must guarantee that it
0656  * remains valid until the completion handler is called.
0657  *
0658  * @param token The @ref completion_token that will be used to produce a
0659  * completion handler, which will be called when the read completes.
0660  * Potential completion tokens include @ref use_future, @ref use_awaitable,
0661  * @ref yield_context, or a function object with the correct completion
0662  * signature. The function signature of the completion handler must be:
0663  * @code void handler(
0664  *   // Result of operation.
0665  *   const boost::system::error_code& error,
0666  *
0667  *   // Number of bytes copied into the buffers. If an error
0668  *   // occurred, this will be the number of bytes successfully
0669  *   // transferred prior to the error.
0670  *   std::size_t bytes_transferred
0671  * ); @endcode
0672  * Regardless of whether the asynchronous operation completes immediately or
0673  * not, the completion handler will not be invoked from within this function.
0674  * On immediate completion, invocation of the handler will be performed in a
0675  * manner equivalent to using boost::asio::async_immediate().
0676  *
0677  * @par Completion Signature
0678  * @code void(boost::system::error_code, std::size_t) @endcode
0679  *
0680  * @note This overload is equivalent to calling:
0681  * @code boost::asio::async_read_at(
0682  *     d, 42, b,
0683  *     boost::asio::transfer_all(),
0684  *     handler); @endcode
0685  *
0686  * @par Per-Operation Cancellation
0687  * This asynchronous operation supports cancellation for the following
0688  * boost::asio::cancellation_type values:
0689  *
0690  * @li @c cancellation_type::terminal
0691  *
0692  * @li @c cancellation_type::partial
0693  *
0694  * if they are also supported by the @c AsyncRandomAccessReadDevice type's
0695  * async_read_some_at operation.
0696  */
0697 template <typename AsyncRandomAccessReadDevice, typename Allocator,
0698     BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0699       std::size_t)) ReadToken = default_completion_token_t<
0700         typename AsyncRandomAccessReadDevice::executor_type>>
0701 inline auto async_read_at(AsyncRandomAccessReadDevice& d,
0702     uint64_t offset, basic_streambuf<Allocator>& b,
0703     ReadToken&& token = default_completion_token_t<
0704       typename AsyncRandomAccessReadDevice::executor_type>(),
0705     constraint_t<
0706       !is_completion_condition<ReadToken>::value
0707     > = 0)
0708   -> decltype(
0709     async_initiate<ReadToken,
0710       void (boost::system::error_code, std::size_t)>(
0711         declval<detail::initiate_async_read_at_streambuf<
0712           AsyncRandomAccessReadDevice>>(),
0713         token, offset, &b, transfer_all()))
0714 {
0715   return async_initiate<ReadToken,
0716     void (boost::system::error_code, std::size_t)>(
0717       detail::initiate_async_read_at_streambuf<AsyncRandomAccessReadDevice>(d),
0718       token, offset, &b, transfer_all());
0719 }
0720 
0721 /// Start an asynchronous operation to read a certain amount of data at the
0722 /// specified offset.
0723 /**
0724  * This function is used to asynchronously read a certain number of bytes of
0725  * data from a random access device at the specified offset. It is an
0726  * initiating function for an @ref asynchronous_operation, and always returns
0727  * immediately. The asynchronous operation will continue until one of the
0728  * following conditions is true:
0729  *
0730  * @li The completion_condition function object returns 0.
0731  *
0732  * This operation is implemented in terms of zero or more calls to the device's
0733  * async_read_some_at function.
0734  *
0735  * @param d The device from which the data is to be read. The type must support
0736  * the AsyncRandomAccessReadDevice concept.
0737  *
0738  * @param offset The offset at which the data will be read.
0739  *
0740  * @param b A basic_streambuf object into which the data will be read. Ownership
0741  * of the streambuf is retained by the caller, which must guarantee that it
0742  * remains valid until the completion handler is called.
0743  *
0744  * @param completion_condition The function object to be called to determine
0745  * whether the read operation is complete. The signature of the function object
0746  * must be:
0747  * @code std::size_t completion_condition(
0748  *   // Result of latest async_read_some_at operation.
0749  *   const boost::system::error_code& error,
0750  *
0751  *   // Number of bytes transferred so far.
0752  *   std::size_t bytes_transferred
0753  * ); @endcode
0754  * A return value of 0 indicates that the read operation is complete. A non-zero
0755  * return value indicates the maximum number of bytes to be read on the next
0756  * call to the device's async_read_some_at function.
0757  *
0758  * @param token The @ref completion_token that will be used to produce a
0759  * completion handler, which will be called when the read completes.
0760  * Potential completion tokens include @ref use_future, @ref use_awaitable,
0761  * @ref yield_context, or a function object with the correct completion
0762  * signature. The function signature of the completion handler must be:
0763  * @code void handler(
0764  *   // Result of operation.
0765  *   const boost::system::error_code& error,
0766  *
0767  *   // Number of bytes copied into the buffers. If an error
0768  *   // occurred, this will be the number of bytes successfully
0769  *   // transferred prior to the error.
0770  *   std::size_t bytes_transferred
0771  * ); @endcode
0772  * Regardless of whether the asynchronous operation completes immediately or
0773  * not, the completion handler will not be invoked from within this function.
0774  * On immediate completion, invocation of the handler will be performed in a
0775  * manner equivalent to using boost::asio::async_immediate().
0776  *
0777  * @par Completion Signature
0778  * @code void(boost::system::error_code, std::size_t) @endcode
0779  *
0780  * @par Per-Operation Cancellation
0781  * This asynchronous operation supports cancellation for the following
0782  * boost::asio::cancellation_type values:
0783  *
0784  * @li @c cancellation_type::terminal
0785  *
0786  * @li @c cancellation_type::partial
0787  *
0788  * if they are also supported by the @c AsyncRandomAccessReadDevice type's
0789  * async_read_some_at operation.
0790  */
0791 template <typename AsyncRandomAccessReadDevice,
0792     typename Allocator, typename CompletionCondition,
0793     BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0794       std::size_t)) ReadToken = default_completion_token_t<
0795         typename AsyncRandomAccessReadDevice::executor_type>>
0796 inline auto async_read_at(AsyncRandomAccessReadDevice& d, uint64_t offset,
0797     basic_streambuf<Allocator>& b, CompletionCondition completion_condition,
0798     ReadToken&& token = default_completion_token_t<
0799       typename AsyncRandomAccessReadDevice::executor_type>(),
0800     constraint_t<
0801       is_completion_condition<CompletionCondition>::value
0802     > = 0)
0803   -> decltype(
0804     async_initiate<ReadToken,
0805       void (boost::system::error_code, std::size_t)>(
0806         declval<detail::initiate_async_read_at_streambuf<
0807           AsyncRandomAccessReadDevice>>(),
0808         token, offset, &b,
0809         static_cast<CompletionCondition&&>(completion_condition)))
0810 {
0811   return async_initiate<ReadToken,
0812     void (boost::system::error_code, std::size_t)>(
0813       detail::initiate_async_read_at_streambuf<AsyncRandomAccessReadDevice>(d),
0814       token, offset, &b,
0815       static_cast<CompletionCondition&&>(completion_condition));
0816 }
0817 
0818 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
0819 #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
0820 
0821 /*@}*/
0822 
0823 } // namespace asio
0824 } // namespace boost
0825 
0826 #include <boost/asio/detail/pop_options.hpp>
0827 
0828 #include <boost/asio/impl/read_at.hpp>
0829 
0830 #endif // BOOST_ASIO_READ_AT_HPP