Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:12

0001 //
0002 // write_at.hpp
0003 // ~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 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 
0193 /// Write a certain amount of data at a specified offset before returning.
0194 /**
0195  * This function is used to write a certain number of bytes of data to a random
0196  * access device at a specified offset. The call will block until one of the
0197  * following conditions is true:
0198  *
0199  * @li All of the data in the supplied buffers has been written. That is, the
0200  * bytes transferred is equal to the sum of the buffer sizes.
0201  *
0202  * @li The completion_condition function object returns 0.
0203  *
0204  * This operation is implemented in terms of zero or more calls to the device's
0205  * write_some_at function.
0206  *
0207  * @param d The device to which the data is to be written. The type must support
0208  * the SyncRandomAccessWriteDevice concept.
0209  *
0210  * @param offset The offset at which the data will be written.
0211  *
0212  * @param buffers One or more buffers containing the data to be written. The sum
0213  * of the buffer sizes indicates the maximum number of bytes to write to the
0214  * device.
0215  *
0216  * @param completion_condition The function object to be called to determine
0217  * whether the write operation is complete. The signature of the function object
0218  * must be:
0219  * @code std::size_t completion_condition(
0220  *   // Result of latest write_some_at operation.
0221  *   const boost::system::error_code& error,
0222  *
0223  *   // Number of bytes transferred so far.
0224  *   std::size_t bytes_transferred
0225  * ); @endcode
0226  * A return value of 0 indicates that the write operation is complete. A
0227  * non-zero return value indicates the maximum number of bytes to be written on
0228  * the next call to the device's write_some_at function.
0229  *
0230  * @param ec Set to indicate what error occurred, if any.
0231  *
0232  * @returns The number of bytes written. If an error occurs, returns the total
0233  * number of bytes successfully transferred prior to the error.
0234  */
0235 template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence,
0236     typename CompletionCondition>
0237 std::size_t write_at(SyncRandomAccessWriteDevice& d,
0238     uint64_t offset, const ConstBufferSequence& buffers,
0239     CompletionCondition completion_condition, boost::system::error_code& ec);
0240 
0241 #if !defined(BOOST_ASIO_NO_EXTENSIONS)
0242 #if !defined(BOOST_ASIO_NO_IOSTREAM)
0243 
0244 /// Write all of the supplied data at the specified offset before returning.
0245 /**
0246  * This function is used to write a certain number of bytes of data to a random
0247  * access device at a specified offset. The call will block until one of the
0248  * following conditions is true:
0249  *
0250  * @li All of the data in the supplied basic_streambuf has been written.
0251  *
0252  * @li An error occurred.
0253  *
0254  * This operation is implemented in terms of zero or more calls to the device's
0255  * write_some_at function.
0256  *
0257  * @param d The device to which the data is to be written. The type must support
0258  * the SyncRandomAccessWriteDevice concept.
0259  *
0260  * @param offset The offset at which the data will be written.
0261  *
0262  * @param b The basic_streambuf object from which data will be written.
0263  *
0264  * @returns The number of bytes transferred.
0265  *
0266  * @throws boost::system::system_error Thrown on failure.
0267  *
0268  * @note This overload is equivalent to calling:
0269  * @code boost::asio::write_at(
0270  *     d, 42, b,
0271  *     boost::asio::transfer_all()); @endcode
0272  */
0273 template <typename SyncRandomAccessWriteDevice, typename Allocator>
0274 std::size_t write_at(SyncRandomAccessWriteDevice& d,
0275     uint64_t offset, basic_streambuf<Allocator>& b);
0276 
0277 /// Write all of the supplied data at the specified offset before returning.
0278 /**
0279  * This function is used to write a certain number of bytes of data to a random
0280  * access device at a specified offset. The call will block until one of the
0281  * following conditions is true:
0282  *
0283  * @li All of the data in the supplied basic_streambuf has been written.
0284  *
0285  * @li An error occurred.
0286  *
0287  * This operation is implemented in terms of zero or more calls to the device's
0288  * write_some_at function.
0289  *
0290  * @param d The device to which the data is to be written. The type must support
0291  * the SyncRandomAccessWriteDevice concept.
0292  *
0293  * @param offset The offset at which the data will be written.
0294  *
0295  * @param b The basic_streambuf object from which data will be written.
0296  *
0297  * @param ec Set to indicate what error occurred, if any.
0298  *
0299  * @returns The number of bytes transferred.
0300  *
0301  * @note This overload is equivalent to calling:
0302  * @code boost::asio::write_at(
0303  *     d, 42, b,
0304  *     boost::asio::transfer_all(), ec); @endcode
0305  */
0306 template <typename SyncRandomAccessWriteDevice, typename Allocator>
0307 std::size_t write_at(SyncRandomAccessWriteDevice& d,
0308     uint64_t offset, basic_streambuf<Allocator>& b,
0309     boost::system::error_code& ec);
0310 
0311 /// Write a certain amount of data at a specified offset before returning.
0312 /**
0313  * This function is used to write a certain number of bytes of data to a random
0314  * access device at a specified offset. The call will block until one of the
0315  * following conditions is true:
0316  *
0317  * @li All of the data in the supplied basic_streambuf has been written.
0318  *
0319  * @li The completion_condition function object returns 0.
0320  *
0321  * This operation is implemented in terms of zero or more calls to the device's
0322  * write_some_at function.
0323  *
0324  * @param d The device to which the data is to be written. The type must support
0325  * the SyncRandomAccessWriteDevice concept.
0326  *
0327  * @param offset The offset at which the data will be written.
0328  *
0329  * @param b The basic_streambuf object from which data will be written.
0330  *
0331  * @param completion_condition The function object to be called to determine
0332  * whether the write operation is complete. The signature of the function object
0333  * must be:
0334  * @code std::size_t completion_condition(
0335  *   // Result of latest write_some_at operation.
0336  *   const boost::system::error_code& error,
0337  *
0338  *   // Number of bytes transferred so far.
0339  *   std::size_t bytes_transferred
0340  * ); @endcode
0341  * A return value of 0 indicates that the write operation is complete. A
0342  * non-zero return value indicates the maximum number of bytes to be written on
0343  * the next call to the device's write_some_at function.
0344  *
0345  * @returns The number of bytes transferred.
0346  *
0347  * @throws boost::system::system_error Thrown on failure.
0348  */
0349 template <typename SyncRandomAccessWriteDevice, typename Allocator,
0350     typename CompletionCondition>
0351 std::size_t write_at(SyncRandomAccessWriteDevice& d, uint64_t offset,
0352     basic_streambuf<Allocator>& b, CompletionCondition completion_condition);
0353 
0354 /// Write a certain amount of data at a specified offset before returning.
0355 /**
0356  * This function is used to write a certain number of bytes of data to a random
0357  * access device at a specified offset. The call will block until one of the
0358  * following conditions is true:
0359  *
0360  * @li All of the data in the supplied basic_streambuf has been written.
0361  *
0362  * @li The completion_condition function object returns 0.
0363  *
0364  * This operation is implemented in terms of zero or more calls to the device's
0365  * write_some_at function.
0366  *
0367  * @param d The device to which the data is to be written. The type must support
0368  * the SyncRandomAccessWriteDevice concept.
0369  *
0370  * @param offset The offset at which the data will be written.
0371  *
0372  * @param b The basic_streambuf object from which data will be written.
0373  *
0374  * @param completion_condition The function object to be called to determine
0375  * whether the write operation is complete. The signature of the function object
0376  * must be:
0377  * @code std::size_t completion_condition(
0378  *   // Result of latest write_some_at operation.
0379  *   const boost::system::error_code& error,
0380  *
0381  *   // Number of bytes transferred so far.
0382  *   std::size_t bytes_transferred
0383  * ); @endcode
0384  * A return value of 0 indicates that the write operation is complete. A
0385  * non-zero return value indicates the maximum number of bytes to be written on
0386  * the next call to the device's write_some_at function.
0387  *
0388  * @param ec Set to indicate what error occurred, if any.
0389  *
0390  * @returns The number of bytes written. If an error occurs, returns the total
0391  * number of bytes successfully transferred prior to the error.
0392  */
0393 template <typename SyncRandomAccessWriteDevice, typename Allocator,
0394     typename CompletionCondition>
0395 std::size_t write_at(SyncRandomAccessWriteDevice& d, uint64_t offset,
0396     basic_streambuf<Allocator>& b, CompletionCondition completion_condition,
0397     boost::system::error_code& ec);
0398 
0399 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
0400 #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
0401 
0402 /*@}*/
0403 /**
0404  * @defgroup async_write_at boost::asio::async_write_at
0405  *
0406  * @brief The @c async_write_at function is a composed asynchronous operation
0407  * that writes a certain amount of data at the specified offset before
0408  * completion.
0409  */
0410 /*@{*/
0411 
0412 /// Start an asynchronous operation to write all of the supplied data at the
0413 /// specified offset.
0414 /**
0415  * This function is used to asynchronously write a certain number of bytes of
0416  * data to a random access device at a specified offset. It is an initiating
0417  * function for an @ref asynchronous_operation, and always returns immediately.
0418  * The asynchronous operation will continue until one of the following
0419  * conditions is true:
0420  *
0421  * @li All of the data in the supplied buffers has been written. That is, the
0422  * bytes transferred is equal to the sum of the buffer sizes.
0423  *
0424  * @li An error occurred.
0425  *
0426  * This operation is implemented in terms of zero or more calls to the device's
0427  * async_write_some_at function, and is known as a <em>composed operation</em>.
0428  * The program must ensure that the device performs no <em>overlapping</em>
0429  * write operations (such as async_write_at, the device's async_write_some_at
0430  * function, or any other composed operations that perform writes) until this
0431  * operation completes. Operations are overlapping if the regions defined by
0432  * their offsets, and the numbers of bytes to write, intersect.
0433  *
0434  * @param d The device to which the data is to be written. The type must support
0435  * the AsyncRandomAccessWriteDevice concept.
0436  *
0437  * @param offset The offset at which the data will be written.
0438  *
0439  * @param buffers One or more buffers containing the data to be written.
0440  * Although the buffers object may be copied as necessary, ownership of the
0441  * underlying memory blocks is retained by the caller, which must guarantee
0442  * that they remain valid until the completion handler is called.
0443  *
0444  * @param token The @ref completion_token that will be used to produce a
0445  * completion handler, which will be called when the write completes.
0446  * Potential completion tokens include @ref use_future, @ref use_awaitable,
0447  * @ref yield_context, or a function object with the correct completion
0448  * signature. The function signature of the completion handler must be:
0449  * @code void handler(
0450  *   // Result of operation.
0451  *   const boost::system::error_code& error,
0452  *
0453  *   // Number of bytes written from the buffers. If an error
0454  *   // occurred, this will be less than the sum of the buffer sizes.
0455  *   std::size_t bytes_transferred
0456  * ); @endcode
0457  * Regardless of whether the asynchronous operation completes immediately or
0458  * not, the completion handler will not be invoked from within this function.
0459  * On immediate completion, invocation of the handler will be performed in a
0460  * manner equivalent to using boost::asio::post().
0461  *
0462  * @par Completion Signature
0463  * @code void(boost::system::error_code, std::size_t) @endcode
0464  *
0465  * @par Example
0466  * To write a single data buffer use the @ref buffer function as follows:
0467  * @code
0468  * boost::asio::async_write_at(d, 42, boost::asio::buffer(data, size), handler);
0469  * @endcode
0470  * See the @ref buffer documentation for information on writing multiple
0471  * buffers in one go, and how to use it with arrays, boost::array or
0472  * std::vector.
0473  *
0474  * @par Per-Operation Cancellation
0475  * This asynchronous operation supports cancellation for the following
0476  * boost::asio::cancellation_type values:
0477  *
0478  * @li @c cancellation_type::terminal
0479  *
0480  * @li @c cancellation_type::partial
0481  *
0482  * if they are also supported by the @c AsyncRandomAccessWriteDevice type's
0483  * async_write_some_at operation.
0484  */
0485 template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
0486     BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0487       std::size_t)) WriteToken = default_completion_token_t<
0488         typename AsyncRandomAccessWriteDevice::executor_type>>
0489 auto async_write_at(AsyncRandomAccessWriteDevice& d,
0490     uint64_t offset, const ConstBufferSequence& buffers,
0491     WriteToken&& token = default_completion_token_t<
0492       typename AsyncRandomAccessWriteDevice::executor_type>())
0493   -> decltype(
0494     async_initiate<WriteToken,
0495       void (boost::system::error_code, std::size_t)>(
0496         declval<detail::initiate_async_write_at<
0497           AsyncRandomAccessWriteDevice>>(),
0498         token, offset, buffers, transfer_all()));
0499 
0500 /// Start an asynchronous operation to write a certain amount of data at the
0501 /// specified offset.
0502 /**
0503  * This function is used to asynchronously write a certain number of bytes of
0504  * data to a random access device at a specified offset. It is an initiating
0505  * function for an @ref asynchronous_operation, and always returns immediately.
0506  * The asynchronous operation will continue until one of the following
0507  * conditions is true:
0508  *
0509  * @li All of the data in the supplied buffers has been written. That is, the
0510  * bytes transferred is equal to the sum of the buffer sizes.
0511  *
0512  * @li The completion_condition function object returns 0.
0513  *
0514  * This operation is implemented in terms of zero or more calls to the device's
0515  * async_write_some_at function, and is known as a <em>composed operation</em>.
0516  * The program must ensure that the device performs no <em>overlapping</em>
0517  * write operations (such as async_write_at, the device's async_write_some_at
0518  * function, or any other composed operations that perform writes) until this
0519  * operation completes. Operations are overlapping if the regions defined by
0520  * their offsets, and the numbers of bytes to write, intersect.
0521  *
0522  * @param d The device to which the data is to be written. The type must support
0523  * the AsyncRandomAccessWriteDevice concept.
0524  *
0525  * @param offset The offset at which the data will be written.
0526  *
0527  * @param buffers One or more buffers containing the data to be written.
0528  * Although the buffers object may be copied as necessary, ownership of the
0529  * underlying memory blocks is retained by the caller, which must guarantee
0530  * that they remain valid until the completion handler is called.
0531  *
0532  * @param completion_condition The function object to be called to determine
0533  * whether the write operation is complete. The signature of the function object
0534  * must be:
0535  * @code std::size_t completion_condition(
0536  *   // Result of latest async_write_some_at operation.
0537  *   const boost::system::error_code& error,
0538  *
0539  *   // Number of bytes transferred so far.
0540  *   std::size_t bytes_transferred
0541  * ); @endcode
0542  * A return value of 0 indicates that the write operation is complete. A
0543  * non-zero return value indicates the maximum number of bytes to be written on
0544  * the next call to the device's async_write_some_at function.
0545  *
0546  * @param token The @ref completion_token that will be used to produce a
0547  * completion handler, which will be called when the write completes.
0548  * Potential completion tokens include @ref use_future, @ref use_awaitable,
0549  * @ref yield_context, or a function object with the correct completion
0550  * signature. The function signature of the completion handler must be:
0551  * @code void handler(
0552  *   // Result of operation.
0553  *   const boost::system::error_code& error,
0554  *
0555  *   // Number of bytes written from the buffers. If an error
0556  *   // occurred, this will be less than the sum of the buffer sizes.
0557  *   std::size_t bytes_transferred
0558  * ); @endcode
0559  * Regardless of whether the asynchronous operation completes immediately or
0560  * not, the completion handler will not be invoked from within this function.
0561  * On immediate completion, invocation of the handler will be performed in a
0562  * manner equivalent to using boost::asio::post().
0563  *
0564  * @par Completion Signature
0565  * @code void(boost::system::error_code, std::size_t) @endcode
0566  *
0567  * @par Example
0568  * To write a single data buffer use the @ref buffer function as follows:
0569  * @code boost::asio::async_write_at(d, 42,
0570  *     boost::asio::buffer(data, size),
0571  *     boost::asio::transfer_at_least(32),
0572  *     handler); @endcode
0573  * See the @ref buffer documentation for information on writing multiple
0574  * buffers in one go, and how to use it with arrays, boost::array or
0575  * std::vector.
0576  *
0577  * @par Per-Operation Cancellation
0578  * This asynchronous operation supports cancellation for the following
0579  * boost::asio::cancellation_type values:
0580  *
0581  * @li @c cancellation_type::terminal
0582  *
0583  * @li @c cancellation_type::partial
0584  *
0585  * if they are also supported by the @c AsyncRandomAccessWriteDevice type's
0586  * async_write_some_at operation.
0587  */
0588 template <typename AsyncRandomAccessWriteDevice,
0589     typename ConstBufferSequence, typename CompletionCondition,
0590     BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0591       std::size_t)) WriteToken = default_completion_token_t<
0592         typename AsyncRandomAccessWriteDevice::executor_type>>
0593 auto async_write_at(AsyncRandomAccessWriteDevice& d,
0594     uint64_t offset, const ConstBufferSequence& buffers,
0595     CompletionCondition completion_condition,
0596     WriteToken&& token = default_completion_token_t<
0597       typename AsyncRandomAccessWriteDevice::executor_type>())
0598   -> decltype(
0599     async_initiate<WriteToken,
0600       void (boost::system::error_code, std::size_t)>(
0601         declval<detail::initiate_async_write_at<
0602           AsyncRandomAccessWriteDevice>>(),
0603         token, offset, buffers,
0604         static_cast<CompletionCondition&&>(completion_condition)));
0605 
0606 #if !defined(BOOST_ASIO_NO_EXTENSIONS)
0607 #if !defined(BOOST_ASIO_NO_IOSTREAM)
0608 
0609 /// Start an asynchronous operation to write all of the supplied data at the
0610 /// specified offset.
0611 /**
0612  * This function is used to asynchronously write a certain number of bytes of
0613  * data to a random access device at a specified offset. It is an initiating
0614  * function for an @ref asynchronous_operation, and always returns immediately.
0615  * The asynchronous operation will continue until one of the following
0616  * conditions is true:
0617  *
0618  * @li All of the data in the supplied basic_streambuf has been written.
0619  *
0620  * @li An error occurred.
0621  *
0622  * This operation is implemented in terms of zero or more calls to the device's
0623  * async_write_some_at function, and is known as a <em>composed operation</em>.
0624  * The program must ensure that the device performs no <em>overlapping</em>
0625  * write operations (such as async_write_at, the device's async_write_some_at
0626  * function, or any other composed operations that perform writes) until this
0627  * operation completes. Operations are overlapping if the regions defined by
0628  * their offsets, and the numbers of bytes to write, intersect.
0629  *
0630  * @param d The device to which the data is to be written. The type must support
0631  * the AsyncRandomAccessWriteDevice concept.
0632  *
0633  * @param offset The offset at which the data will be written.
0634  *
0635  * @param b A basic_streambuf object from which data will be written. Ownership
0636  * of the streambuf is retained by the caller, which must guarantee that it
0637  * remains valid until the completion handler is called.
0638  *
0639  * @param token The @ref completion_token that will be used to produce a
0640  * completion handler, which will be called when the write completes.
0641  * Potential completion tokens include @ref use_future, @ref use_awaitable,
0642  * @ref yield_context, or a function object with the correct completion
0643  * signature. The function signature of the completion handler must be:
0644  * @code void handler(
0645  *   // Result of operation.
0646  *   const boost::system::error_code& error,
0647  *
0648  *   // Number of bytes written from the buffers. If an error
0649  *   // occurred, this will be less than the sum of the buffer sizes.
0650  *   std::size_t bytes_transferred
0651  * ); @endcode
0652  * Regardless of whether the asynchronous operation completes immediately or
0653  * not, the completion handler will not be invoked from within this function.
0654  * On immediate completion, invocation of the handler will be performed in a
0655  * manner equivalent to using boost::asio::post().
0656  *
0657  * @par Completion Signature
0658  * @code void(boost::system::error_code, std::size_t) @endcode
0659  *
0660  * @par Per-Operation Cancellation
0661  * This asynchronous operation supports cancellation for the following
0662  * boost::asio::cancellation_type values:
0663  *
0664  * @li @c cancellation_type::terminal
0665  *
0666  * @li @c cancellation_type::partial
0667  *
0668  * if they are also supported by the @c AsyncRandomAccessWriteDevice type's
0669  * async_write_some_at operation.
0670  */
0671 template <typename AsyncRandomAccessWriteDevice, typename Allocator,
0672     BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0673       std::size_t)) WriteToken = default_completion_token_t<
0674         typename AsyncRandomAccessWriteDevice::executor_type>>
0675 auto async_write_at(AsyncRandomAccessWriteDevice& d,
0676     uint64_t offset, basic_streambuf<Allocator>& b,
0677     WriteToken&& token = default_completion_token_t<
0678       typename AsyncRandomAccessWriteDevice::executor_type>())
0679   -> decltype(
0680     async_initiate<WriteToken,
0681       void (boost::system::error_code, std::size_t)>(
0682         declval<detail::initiate_async_write_at_streambuf<
0683           AsyncRandomAccessWriteDevice>>(),
0684         token, offset, &b, transfer_all()));
0685 
0686 /// Start an asynchronous operation to write a certain amount of data at the
0687 /// specified offset.
0688 /**
0689  * This function is used to asynchronously write a certain number of bytes of
0690  * data to a random access device at a specified offset. It is an initiating
0691  * function for an @ref asynchronous_operation, and always returns immediately.
0692  * The asynchronous operation will continue until one of the following
0693  * conditions is true:
0694  *
0695  * @li All of the data in the supplied basic_streambuf has been written.
0696  *
0697  * @li The completion_condition function object returns 0.
0698  *
0699  * This operation is implemented in terms of zero or more calls to the device's
0700  * async_write_some_at function, and is known as a <em>composed operation</em>.
0701  * The program must ensure that the device performs no <em>overlapping</em>
0702  * write operations (such as async_write_at, the device's async_write_some_at
0703  * function, or any other composed operations that perform writes) until this
0704  * operation completes. Operations are overlapping if the regions defined by
0705  * their offsets, and the numbers of bytes to write, intersect.
0706  *
0707  * @param d The device to which the data is to be written. The type must support
0708  * the AsyncRandomAccessWriteDevice concept.
0709  *
0710  * @param offset The offset at which the data will be written.
0711  *
0712  * @param b A basic_streambuf object from which data will be written. Ownership
0713  * of the streambuf is retained by the caller, which must guarantee that it
0714  * remains valid until the completion handler is called.
0715  *
0716  * @param completion_condition The function object to be called to determine
0717  * whether the write operation is complete. The signature of the function object
0718  * must be:
0719  * @code std::size_t completion_condition(
0720  *   // Result of latest async_write_some_at operation.
0721  *   const boost::system::error_code& error,
0722  *
0723  *   // Number of bytes transferred so far.
0724  *   std::size_t bytes_transferred
0725  * ); @endcode
0726  * A return value of 0 indicates that the write operation is complete. A
0727  * non-zero return value indicates the maximum number of bytes to be written on
0728  * the next call to the device's async_write_some_at function.
0729  *
0730  * @param token The @ref completion_token that will be used to produce a
0731  * completion handler, which will be called when the write completes.
0732  * Potential completion tokens include @ref use_future, @ref use_awaitable,
0733  * @ref yield_context, or a function object with the correct completion
0734  * signature. The function signature of the completion handler must be:
0735  * @code void handler(
0736  *   // Result of operation.
0737  *   const boost::system::error_code& error,
0738  *
0739  *   // Number of bytes written from the buffers. If an error
0740  *   // occurred, this will be less than the sum of the buffer sizes.
0741  *   std::size_t bytes_transferred
0742  * ); @endcode
0743  * Regardless of whether the asynchronous operation completes immediately or
0744  * not, the completion handler will not be invoked from within this function.
0745  * On immediate completion, invocation of the handler will be performed in a
0746  * manner equivalent to using boost::asio::post().
0747  *
0748  * @par Completion Signature
0749  * @code void(boost::system::error_code, std::size_t) @endcode
0750  *
0751  * @par Per-Operation Cancellation
0752  * This asynchronous operation supports cancellation for the following
0753  * boost::asio::cancellation_type values:
0754  *
0755  * @li @c cancellation_type::terminal
0756  *
0757  * @li @c cancellation_type::partial
0758  *
0759  * if they are also supported by the @c AsyncRandomAccessWriteDevice type's
0760  * async_write_some_at operation.
0761  */
0762 template <typename AsyncRandomAccessWriteDevice,
0763     typename Allocator, typename CompletionCondition,
0764     BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0765       std::size_t)) WriteToken = default_completion_token_t<
0766         typename AsyncRandomAccessWriteDevice::executor_type>>
0767 auto async_write_at(AsyncRandomAccessWriteDevice& d, uint64_t offset,
0768     basic_streambuf<Allocator>& b, CompletionCondition completion_condition,
0769     WriteToken&& token = default_completion_token_t<
0770       typename AsyncRandomAccessWriteDevice::executor_type>())
0771   -> decltype(
0772     async_initiate<WriteToken,
0773       void (boost::system::error_code, std::size_t)>(
0774         declval<detail::initiate_async_write_at_streambuf<
0775           AsyncRandomAccessWriteDevice>>(),
0776         token, offset, &b,
0777         static_cast<CompletionCondition&&>(completion_condition)));
0778 
0779 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
0780 #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
0781 
0782 /*@}*/
0783 
0784 } // namespace asio
0785 } // namespace boost
0786 
0787 #include <boost/asio/detail/pop_options.hpp>
0788 
0789 #include <boost/asio/impl/write_at.hpp>
0790 
0791 #endif // BOOST_ASIO_WRITE_AT_HPP