Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-12 08:08:29

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