Chris@16: // Chris@16: // write_at.hpp Chris@16: // ~~~~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_WRITE_AT_HPP Chris@16: #define BOOST_ASIO_WRITE_AT_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: Chris@16: /** Chris@16: * @defgroup write_at boost::asio::write_at Chris@16: * Chris@16: * @brief Write a certain amount of data at a specified offset before returning. Chris@16: */ Chris@16: /*@{*/ Chris@16: Chris@16: /// Write all of the supplied data at the specified offset before returning. Chris@16: /** Chris@16: * This function is used to write a certain number of bytes of data to a random Chris@16: * access device at a specified offset. The call will block until one of the Chris@16: * following conditions is true: Chris@16: * Chris@16: * @li All of the data in the supplied buffers has been written. That is, the Chris@16: * bytes transferred is equal to the sum of the buffer sizes. Chris@16: * Chris@16: * @li An error occurred. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the device's Chris@16: * write_some_at function. Chris@16: * Chris@16: * @param d The device to which the data is to be written. The type must support Chris@16: * the SyncRandomAccessWriteDevice concept. Chris@16: * Chris@16: * @param offset The offset at which the data will be written. Chris@16: * Chris@16: * @param buffers One or more buffers containing the data to be written. The sum Chris@16: * of the buffer sizes indicates the maximum number of bytes to write to the Chris@16: * device. Chris@16: * Chris@16: * @returns The number of bytes transferred. Chris@16: * Chris@16: * @throws boost::system::system_error Thrown on failure. Chris@16: * Chris@16: * @par Example Chris@16: * To write a single data buffer use the @ref buffer function as follows: Chris@16: * @code boost::asio::write_at(d, 42, boost::asio::buffer(data, size)); @endcode Chris@16: * See the @ref buffer documentation for information on writing multiple Chris@16: * buffers in one go, and how to use it with arrays, boost::array or Chris@16: * std::vector. Chris@16: * Chris@16: * @note This overload is equivalent to calling: Chris@16: * @code boost::asio::write_at( Chris@16: * d, offset, buffers, Chris@16: * boost::asio::transfer_all()); @endcode Chris@16: */ Chris@16: template Chris@16: std::size_t write_at(SyncRandomAccessWriteDevice& d, Chris@16: uint64_t offset, const ConstBufferSequence& buffers); Chris@16: Chris@16: /// Write all of the supplied data at the specified offset before returning. Chris@16: /** Chris@16: * This function is used to write a certain number of bytes of data to a random Chris@16: * access device at a specified offset. The call will block until one of the Chris@16: * following conditions is true: Chris@16: * Chris@16: * @li All of the data in the supplied buffers has been written. That is, the Chris@16: * bytes transferred is equal to the sum of the buffer sizes. Chris@16: * Chris@16: * @li An error occurred. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the device's Chris@16: * write_some_at function. Chris@16: * Chris@16: * @param d The device to which the data is to be written. The type must support Chris@16: * the SyncRandomAccessWriteDevice concept. Chris@16: * Chris@16: * @param offset The offset at which the data will be written. Chris@16: * Chris@16: * @param buffers One or more buffers containing the data to be written. The sum Chris@16: * of the buffer sizes indicates the maximum number of bytes to write to the Chris@16: * device. Chris@16: * Chris@16: * @param ec Set to indicate what error occurred, if any. Chris@16: * Chris@16: * @returns The number of bytes transferred. Chris@16: * Chris@16: * @par Example Chris@16: * To write a single data buffer use the @ref buffer function as follows: Chris@16: * @code boost::asio::write_at(d, 42, Chris@16: * boost::asio::buffer(data, size), ec); @endcode Chris@16: * See the @ref buffer documentation for information on writing multiple Chris@16: * buffers in one go, and how to use it with arrays, boost::array or Chris@16: * std::vector. Chris@16: * Chris@16: * @note This overload is equivalent to calling: Chris@16: * @code boost::asio::write_at( Chris@16: * d, offset, buffers, Chris@16: * boost::asio::transfer_all(), ec); @endcode Chris@16: */ Chris@16: template Chris@16: std::size_t write_at(SyncRandomAccessWriteDevice& d, Chris@16: uint64_t offset, const ConstBufferSequence& buffers, Chris@16: boost::system::error_code& ec); Chris@16: Chris@16: /// Write a certain amount of data at a specified offset before returning. Chris@16: /** Chris@16: * This function is used to write a certain number of bytes of data to a random Chris@16: * access device at a specified offset. The call will block until one of the Chris@16: * following conditions is true: Chris@16: * Chris@16: * @li All of the data in the supplied buffers has been written. That is, the Chris@16: * bytes transferred is equal to the sum of the buffer sizes. Chris@16: * Chris@16: * @li The completion_condition function object returns 0. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the device's Chris@16: * write_some_at function. Chris@16: * Chris@16: * @param d The device to which the data is to be written. The type must support Chris@16: * the SyncRandomAccessWriteDevice concept. Chris@16: * Chris@16: * @param offset The offset at which the data will be written. Chris@16: * Chris@16: * @param buffers One or more buffers containing the data to be written. The sum Chris@16: * of the buffer sizes indicates the maximum number of bytes to write to the Chris@16: * device. Chris@16: * Chris@16: * @param completion_condition The function object to be called to determine Chris@16: * whether the write operation is complete. The signature of the function object Chris@16: * must be: Chris@16: * @code std::size_t completion_condition( Chris@16: * // Result of latest write_some_at operation. Chris@16: * const boost::system::error_code& error, Chris@16: * Chris@16: * // Number of bytes transferred so far. Chris@16: * std::size_t bytes_transferred Chris@16: * ); @endcode Chris@16: * A return value of 0 indicates that the write operation is complete. A Chris@16: * non-zero return value indicates the maximum number of bytes to be written on Chris@16: * the next call to the device's write_some_at function. Chris@16: * Chris@16: * @returns The number of bytes transferred. Chris@16: * Chris@16: * @throws boost::system::system_error Thrown on failure. Chris@16: * Chris@16: * @par Example Chris@16: * To write a single data buffer use the @ref buffer function as follows: Chris@16: * @code boost::asio::write_at(d, 42, boost::asio::buffer(data, size), Chris@16: * boost::asio::transfer_at_least(32)); @endcode Chris@16: * See the @ref buffer documentation for information on writing multiple Chris@16: * buffers in one go, and how to use it with arrays, boost::array or Chris@16: * std::vector. Chris@16: */ Chris@16: template Chris@16: std::size_t write_at(SyncRandomAccessWriteDevice& d, Chris@16: uint64_t offset, const ConstBufferSequence& buffers, Chris@16: CompletionCondition completion_condition); Chris@16: Chris@16: /// Write a certain amount of data at a specified offset before returning. Chris@16: /** Chris@16: * This function is used to write a certain number of bytes of data to a random Chris@16: * access device at a specified offset. The call will block until one of the Chris@16: * following conditions is true: Chris@16: * Chris@16: * @li All of the data in the supplied buffers has been written. That is, the Chris@16: * bytes transferred is equal to the sum of the buffer sizes. Chris@16: * Chris@16: * @li The completion_condition function object returns 0. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the device's Chris@16: * write_some_at function. Chris@16: * Chris@16: * @param d The device to which the data is to be written. The type must support Chris@16: * the SyncRandomAccessWriteDevice concept. Chris@16: * Chris@16: * @param offset The offset at which the data will be written. Chris@16: * Chris@16: * @param buffers One or more buffers containing the data to be written. The sum Chris@16: * of the buffer sizes indicates the maximum number of bytes to write to the Chris@16: * device. Chris@16: * Chris@16: * @param completion_condition The function object to be called to determine Chris@16: * whether the write operation is complete. The signature of the function object Chris@16: * must be: Chris@16: * @code std::size_t completion_condition( Chris@16: * // Result of latest write_some_at operation. Chris@16: * const boost::system::error_code& error, Chris@16: * Chris@16: * // Number of bytes transferred so far. Chris@16: * std::size_t bytes_transferred Chris@16: * ); @endcode Chris@16: * A return value of 0 indicates that the write operation is complete. A Chris@16: * non-zero return value indicates the maximum number of bytes to be written on Chris@16: * the next call to the device's write_some_at function. Chris@16: * Chris@16: * @param ec Set to indicate what error occurred, if any. Chris@16: * Chris@16: * @returns The number of bytes written. If an error occurs, returns the total Chris@16: * number of bytes successfully transferred prior to the error. Chris@16: */ Chris@16: template Chris@16: std::size_t write_at(SyncRandomAccessWriteDevice& d, Chris@16: uint64_t offset, const ConstBufferSequence& buffers, Chris@16: CompletionCondition completion_condition, boost::system::error_code& ec); Chris@16: Chris@16: #if !defined(BOOST_ASIO_NO_IOSTREAM) Chris@16: Chris@16: /// Write all of the supplied data at the specified offset before returning. Chris@16: /** Chris@16: * This function is used to write a certain number of bytes of data to a random Chris@16: * access device at a specified offset. The call will block until one of the Chris@16: * following conditions is true: Chris@16: * Chris@16: * @li All of the data in the supplied basic_streambuf has been written. Chris@16: * Chris@16: * @li An error occurred. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the device's Chris@16: * write_some_at function. Chris@16: * Chris@16: * @param d The device to which the data is to be written. The type must support Chris@16: * the SyncRandomAccessWriteDevice concept. Chris@16: * Chris@16: * @param offset The offset at which the data will be written. Chris@16: * Chris@16: * @param b The basic_streambuf object from which data will be written. Chris@16: * Chris@16: * @returns The number of bytes transferred. Chris@16: * Chris@16: * @throws boost::system::system_error Thrown on failure. Chris@16: * Chris@16: * @note This overload is equivalent to calling: Chris@16: * @code boost::asio::write_at( Chris@16: * d, 42, b, Chris@16: * boost::asio::transfer_all()); @endcode Chris@16: */ Chris@16: template Chris@16: std::size_t write_at(SyncRandomAccessWriteDevice& d, Chris@16: uint64_t offset, basic_streambuf& b); Chris@16: Chris@16: /// Write all of the supplied data at the specified offset before returning. Chris@16: /** Chris@16: * This function is used to write a certain number of bytes of data to a random Chris@16: * access device at a specified offset. The call will block until one of the Chris@16: * following conditions is true: Chris@16: * Chris@16: * @li All of the data in the supplied basic_streambuf has been written. Chris@16: * Chris@16: * @li An error occurred. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the device's Chris@16: * write_some_at function. Chris@16: * Chris@16: * @param d The device to which the data is to be written. The type must support Chris@16: * the SyncRandomAccessWriteDevice concept. Chris@16: * Chris@16: * @param offset The offset at which the data will be written. Chris@16: * Chris@16: * @param b The basic_streambuf object from which data will be written. Chris@16: * Chris@16: * @param ec Set to indicate what error occurred, if any. Chris@16: * Chris@16: * @returns The number of bytes transferred. Chris@16: * Chris@16: * @note This overload is equivalent to calling: Chris@16: * @code boost::asio::write_at( Chris@16: * d, 42, b, Chris@16: * boost::asio::transfer_all(), ec); @endcode Chris@16: */ Chris@16: template Chris@16: std::size_t write_at(SyncRandomAccessWriteDevice& d, Chris@16: uint64_t offset, basic_streambuf& b, Chris@16: boost::system::error_code& ec); Chris@16: Chris@16: /// Write a certain amount of data at a specified offset before returning. Chris@16: /** Chris@16: * This function is used to write a certain number of bytes of data to a random Chris@16: * access device at a specified offset. The call will block until one of the Chris@16: * following conditions is true: Chris@16: * Chris@16: * @li All of the data in the supplied basic_streambuf has been written. Chris@16: * Chris@16: * @li The completion_condition function object returns 0. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the device's Chris@16: * write_some_at function. Chris@16: * Chris@16: * @param d The device to which the data is to be written. The type must support Chris@16: * the SyncRandomAccessWriteDevice concept. Chris@16: * Chris@16: * @param offset The offset at which the data will be written. Chris@16: * Chris@16: * @param b The basic_streambuf object from which data will be written. Chris@16: * Chris@16: * @param completion_condition The function object to be called to determine Chris@16: * whether the write operation is complete. The signature of the function object Chris@16: * must be: Chris@16: * @code std::size_t completion_condition( Chris@16: * // Result of latest write_some_at operation. Chris@16: * const boost::system::error_code& error, Chris@16: * Chris@16: * // Number of bytes transferred so far. Chris@16: * std::size_t bytes_transferred Chris@16: * ); @endcode Chris@16: * A return value of 0 indicates that the write operation is complete. A Chris@16: * non-zero return value indicates the maximum number of bytes to be written on Chris@16: * the next call to the device's write_some_at function. Chris@16: * Chris@16: * @returns The number of bytes transferred. Chris@16: * Chris@16: * @throws boost::system::system_error Thrown on failure. Chris@16: */ Chris@16: template Chris@16: std::size_t write_at(SyncRandomAccessWriteDevice& d, uint64_t offset, Chris@16: basic_streambuf& b, CompletionCondition completion_condition); Chris@16: Chris@16: /// Write a certain amount of data at a specified offset before returning. Chris@16: /** Chris@16: * This function is used to write a certain number of bytes of data to a random Chris@16: * access device at a specified offset. The call will block until one of the Chris@16: * following conditions is true: Chris@16: * Chris@16: * @li All of the data in the supplied basic_streambuf has been written. Chris@16: * Chris@16: * @li The completion_condition function object returns 0. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the device's Chris@16: * write_some_at function. Chris@16: * Chris@16: * @param d The device to which the data is to be written. The type must support Chris@16: * the SyncRandomAccessWriteDevice concept. Chris@16: * Chris@16: * @param offset The offset at which the data will be written. Chris@16: * Chris@16: * @param b The basic_streambuf object from which data will be written. Chris@16: * Chris@16: * @param completion_condition The function object to be called to determine Chris@16: * whether the write operation is complete. The signature of the function object Chris@16: * must be: Chris@16: * @code std::size_t completion_condition( Chris@16: * // Result of latest write_some_at operation. Chris@16: * const boost::system::error_code& error, Chris@16: * Chris@16: * // Number of bytes transferred so far. Chris@16: * std::size_t bytes_transferred Chris@16: * ); @endcode Chris@16: * A return value of 0 indicates that the write operation is complete. A Chris@16: * non-zero return value indicates the maximum number of bytes to be written on Chris@16: * the next call to the device's write_some_at function. Chris@16: * Chris@16: * @param ec Set to indicate what error occurred, if any. Chris@16: * Chris@16: * @returns The number of bytes written. If an error occurs, returns the total Chris@16: * number of bytes successfully transferred prior to the error. Chris@16: */ Chris@16: template Chris@16: std::size_t write_at(SyncRandomAccessWriteDevice& d, uint64_t offset, Chris@16: basic_streambuf& b, CompletionCondition completion_condition, Chris@16: boost::system::error_code& ec); Chris@16: Chris@16: #endif // !defined(BOOST_ASIO_NO_IOSTREAM) Chris@16: Chris@16: /*@}*/ Chris@16: /** Chris@16: * @defgroup async_write_at boost::asio::async_write_at Chris@16: * Chris@16: * @brief Start an asynchronous operation to write a certain amount of data at Chris@16: * the specified offset. Chris@16: */ Chris@16: /*@{*/ Chris@16: Chris@16: /// Start an asynchronous operation to write all of the supplied data at the Chris@16: /// specified offset. Chris@16: /** Chris@16: * This function is used to asynchronously write a certain number of bytes of Chris@16: * data to a random access device at a specified offset. The function call Chris@16: * always returns immediately. The asynchronous operation will continue until Chris@16: * one of the following conditions is true: Chris@16: * Chris@16: * @li All of the data in the supplied buffers has been written. That is, the Chris@16: * bytes transferred is equal to the sum of the buffer sizes. Chris@16: * Chris@16: * @li An error occurred. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the device's Chris@16: * async_write_some_at function, and is known as a composed operation. Chris@16: * The program must ensure that the device performs no overlapping Chris@16: * write operations (such as async_write_at, the device's async_write_some_at Chris@16: * function, or any other composed operations that perform writes) until this Chris@16: * operation completes. Operations are overlapping if the regions defined by Chris@16: * their offsets, and the numbers of bytes to write, intersect. Chris@16: * Chris@16: * @param d The device to which the data is to be written. The type must support Chris@16: * the AsyncRandomAccessWriteDevice concept. Chris@16: * Chris@16: * @param offset The offset at which the data will be written. Chris@16: * Chris@16: * @param buffers One or more buffers containing the data to be written. Chris@16: * Although the buffers object may be copied as necessary, ownership of the Chris@16: * underlying memory blocks is retained by the caller, which must guarantee Chris@16: * that they remain valid until the handler is called. Chris@16: * Chris@16: * @param handler The handler to be called when the write operation completes. Chris@16: * Copies will be made of the handler as required. The function signature of Chris@16: * the handler must be: Chris@16: * @code void handler( Chris@16: * // Result of operation. Chris@16: * const boost::system::error_code& error, Chris@16: * Chris@16: * // Number of bytes written from the buffers. If an error Chris@16: * // occurred, this will be less than the sum of the buffer sizes. Chris@16: * std::size_t bytes_transferred Chris@16: * ); @endcode Chris@16: * Regardless of whether the asynchronous operation completes immediately or Chris@16: * not, the handler will not be invoked from within this function. Invocation of Chris@16: * the handler will be performed in a manner equivalent to using Chris@16: * boost::asio::io_service::post(). Chris@16: * Chris@16: * @par Example Chris@16: * To write a single data buffer use the @ref buffer function as follows: Chris@16: * @code Chris@16: * boost::asio::async_write_at(d, 42, boost::asio::buffer(data, size), handler); Chris@16: * @endcode Chris@16: * See the @ref buffer documentation for information on writing multiple Chris@16: * buffers in one go, and how to use it with arrays, boost::array or Chris@16: * std::vector. Chris@16: */ Chris@16: template Chris@16: BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, Chris@16: void (boost::system::error_code, std::size_t)) Chris@16: async_write_at(AsyncRandomAccessWriteDevice& d, uint64_t offset, Chris@16: const ConstBufferSequence& buffers, Chris@16: BOOST_ASIO_MOVE_ARG(WriteHandler) handler); Chris@16: Chris@16: /// Start an asynchronous operation to write a certain amount of data at the Chris@16: /// specified offset. Chris@16: /** Chris@16: * This function is used to asynchronously write a certain number of bytes of Chris@16: * data to a random access device at a specified offset. The function call Chris@16: * always returns immediately. The asynchronous operation will continue until Chris@16: * one of the following conditions is true: Chris@16: * Chris@16: * @li All of the data in the supplied buffers has been written. That is, the Chris@16: * bytes transferred is equal to the sum of the buffer sizes. Chris@16: * Chris@16: * @li The completion_condition function object returns 0. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the device's Chris@16: * async_write_some_at function, and is known as a composed operation. Chris@16: * The program must ensure that the device performs no overlapping Chris@16: * write operations (such as async_write_at, the device's async_write_some_at Chris@16: * function, or any other composed operations that perform writes) until this Chris@16: * operation completes. Operations are overlapping if the regions defined by Chris@16: * their offsets, and the numbers of bytes to write, intersect. Chris@16: * Chris@16: * @param d The device to which the data is to be written. The type must support Chris@16: * the AsyncRandomAccessWriteDevice concept. Chris@16: * Chris@16: * @param offset The offset at which the data will be written. Chris@16: * Chris@16: * @param buffers One or more buffers containing the data to be written. Chris@16: * Although the buffers object may be copied as necessary, ownership of the Chris@16: * underlying memory blocks is retained by the caller, which must guarantee Chris@16: * that they remain valid until the handler is called. Chris@16: * Chris@16: * @param completion_condition The function object to be called to determine Chris@16: * whether the write operation is complete. The signature of the function object Chris@16: * must be: Chris@16: * @code std::size_t completion_condition( Chris@16: * // Result of latest async_write_some_at operation. Chris@16: * const boost::system::error_code& error, Chris@16: * Chris@16: * // Number of bytes transferred so far. Chris@16: * std::size_t bytes_transferred Chris@16: * ); @endcode Chris@16: * A return value of 0 indicates that the write operation is complete. A Chris@16: * non-zero return value indicates the maximum number of bytes to be written on Chris@16: * the next call to the device's async_write_some_at function. Chris@16: * Chris@16: * @param handler The handler to be called when the write operation completes. Chris@16: * Copies will be made of the handler as required. The function signature of the Chris@16: * handler must be: Chris@16: * @code void handler( Chris@16: * // Result of operation. Chris@16: * const boost::system::error_code& error, Chris@16: * Chris@16: * // Number of bytes written from the buffers. If an error Chris@16: * // occurred, this will be less than the sum of the buffer sizes. Chris@16: * std::size_t bytes_transferred Chris@16: * ); @endcode Chris@16: * Regardless of whether the asynchronous operation completes immediately or Chris@16: * not, the handler will not be invoked from within this function. Invocation of Chris@16: * the handler will be performed in a manner equivalent to using Chris@16: * boost::asio::io_service::post(). Chris@16: * Chris@16: * @par Example Chris@16: * To write a single data buffer use the @ref buffer function as follows: Chris@16: * @code boost::asio::async_write_at(d, 42, Chris@16: * boost::asio::buffer(data, size), Chris@16: * boost::asio::transfer_at_least(32), Chris@16: * handler); @endcode Chris@16: * See the @ref buffer documentation for information on writing multiple Chris@16: * buffers in one go, and how to use it with arrays, boost::array or Chris@16: * std::vector. Chris@16: */ Chris@16: template Chris@16: BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, Chris@16: void (boost::system::error_code, std::size_t)) Chris@16: async_write_at(AsyncRandomAccessWriteDevice& d, Chris@16: uint64_t offset, const ConstBufferSequence& buffers, Chris@16: CompletionCondition completion_condition, Chris@16: BOOST_ASIO_MOVE_ARG(WriteHandler) handler); Chris@16: Chris@16: #if !defined(BOOST_ASIO_NO_IOSTREAM) Chris@16: Chris@16: /// Start an asynchronous operation to write all of the supplied data at the Chris@16: /// specified offset. Chris@16: /** Chris@16: * This function is used to asynchronously write a certain number of bytes of Chris@16: * data to a random access device at a specified offset. The function call Chris@16: * always returns immediately. The asynchronous operation will continue until Chris@16: * one of the following conditions is true: Chris@16: * Chris@16: * @li All of the data in the supplied basic_streambuf has been written. Chris@16: * Chris@16: * @li An error occurred. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the device's Chris@16: * async_write_some_at function, and is known as a composed operation. Chris@16: * The program must ensure that the device performs no overlapping Chris@16: * write operations (such as async_write_at, the device's async_write_some_at Chris@16: * function, or any other composed operations that perform writes) until this Chris@16: * operation completes. Operations are overlapping if the regions defined by Chris@16: * their offsets, and the numbers of bytes to write, intersect. Chris@16: * Chris@16: * @param d The device to which the data is to be written. The type must support Chris@16: * the AsyncRandomAccessWriteDevice concept. Chris@16: * Chris@16: * @param offset The offset at which the data will be written. Chris@16: * Chris@16: * @param b A basic_streambuf object from which data will be written. Ownership Chris@16: * of the streambuf is retained by the caller, which must guarantee that it Chris@16: * remains valid until the handler is called. Chris@16: * Chris@16: * @param handler The handler to be called when the write operation completes. Chris@16: * Copies will be made of the handler as required. The function signature of the Chris@16: * handler must be: Chris@16: * @code void handler( Chris@16: * // Result of operation. Chris@16: * const boost::system::error_code& error, Chris@16: * Chris@16: * // Number of bytes written from the buffers. If an error Chris@16: * // occurred, this will be less than the sum of the buffer sizes. Chris@16: * std::size_t bytes_transferred Chris@16: * ); @endcode Chris@16: * Regardless of whether the asynchronous operation completes immediately or Chris@16: * not, the handler will not be invoked from within this function. Invocation of Chris@16: * the handler will be performed in a manner equivalent to using Chris@16: * boost::asio::io_service::post(). Chris@16: */ Chris@16: template Chris@16: BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, Chris@16: void (boost::system::error_code, std::size_t)) Chris@16: async_write_at(AsyncRandomAccessWriteDevice& d, uint64_t offset, Chris@16: basic_streambuf& b, BOOST_ASIO_MOVE_ARG(WriteHandler) handler); Chris@16: Chris@16: /// Start an asynchronous operation to write a certain amount of data at the Chris@16: /// specified offset. Chris@16: /** Chris@16: * This function is used to asynchronously write a certain number of bytes of Chris@16: * data to a random access device at a specified offset. The function call Chris@16: * always returns immediately. The asynchronous operation will continue until Chris@16: * one of the following conditions is true: Chris@16: * Chris@16: * @li All of the data in the supplied basic_streambuf has been written. Chris@16: * Chris@16: * @li The completion_condition function object returns 0. Chris@16: * Chris@16: * This operation is implemented in terms of zero or more calls to the device's Chris@16: * async_write_some_at function, and is known as a composed operation. Chris@16: * The program must ensure that the device performs no overlapping Chris@16: * write operations (such as async_write_at, the device's async_write_some_at Chris@16: * function, or any other composed operations that perform writes) until this Chris@16: * operation completes. Operations are overlapping if the regions defined by Chris@16: * their offsets, and the numbers of bytes to write, intersect. Chris@16: * Chris@16: * @param d The device to which the data is to be written. The type must support Chris@16: * the AsyncRandomAccessWriteDevice concept. Chris@16: * Chris@16: * @param offset The offset at which the data will be written. Chris@16: * Chris@16: * @param b A basic_streambuf object from which data will be written. Ownership Chris@16: * of the streambuf is retained by the caller, which must guarantee that it Chris@16: * remains valid until the handler is called. Chris@16: * Chris@16: * @param completion_condition The function object to be called to determine Chris@16: * whether the write operation is complete. The signature of the function object Chris@16: * must be: Chris@16: * @code std::size_t completion_condition( Chris@16: * // Result of latest async_write_some_at operation. Chris@16: * const boost::system::error_code& error, Chris@16: * Chris@16: * // Number of bytes transferred so far. Chris@16: * std::size_t bytes_transferred Chris@16: * ); @endcode Chris@16: * A return value of 0 indicates that the write operation is complete. A Chris@16: * non-zero return value indicates the maximum number of bytes to be written on Chris@16: * the next call to the device's async_write_some_at function. Chris@16: * Chris@16: * @param handler The handler to be called when the write operation completes. Chris@16: * Copies will be made of the handler as required. The function signature of the Chris@16: * handler must be: Chris@16: * @code void handler( Chris@16: * // Result of operation. Chris@16: * const boost::system::error_code& error, Chris@16: * Chris@16: * // Number of bytes written from the buffers. If an error Chris@16: * // occurred, this will be less than the sum of the buffer sizes. Chris@16: * std::size_t bytes_transferred Chris@16: * ); @endcode Chris@16: * Regardless of whether the asynchronous operation completes immediately or Chris@16: * not, the handler will not be invoked from within this function. Invocation of Chris@16: * the handler will be performed in a manner equivalent to using Chris@16: * boost::asio::io_service::post(). Chris@16: */ Chris@16: template Chris@16: BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, Chris@16: void (boost::system::error_code, std::size_t)) Chris@16: async_write_at(AsyncRandomAccessWriteDevice& d, uint64_t offset, Chris@16: basic_streambuf& b, CompletionCondition completion_condition, Chris@16: BOOST_ASIO_MOVE_ARG(WriteHandler) handler); Chris@16: Chris@16: #endif // !defined(BOOST_ASIO_NO_IOSTREAM) Chris@16: Chris@16: /*@}*/ Chris@16: Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_ASIO_WRITE_AT_HPP