17 Buffer-oriented streams [buffer.stream]

17.8 Asynchronous write operations [buffer.async.write]

template<class AsyncWriteStream, class ConstBufferSequence, class CompletionToken> DEDUCED async_write(AsyncWriteStream& stream, const ConstBufferSequence& buffers, CompletionToken&& token); template<class AsyncWriteStream, class ConstBufferSequence, class CompletionCondition, class CompletionToken> DEDUCED async_write(AsyncWriteStream& stream, const ConstBufferSequence& buffers, CompletionCondition completion_condition, CompletionToken&& token);

A composed asynchronous write operation ([async.reqmts.async.composed], [buffer.reqmts.read.write]).

Completion signature: void(error_code ec, size_t n).

Effects: Initiates an asynchronous operation to write data to the buffer-oriented asynchronous write stream ([buffer.stream.reqmts.asyncwritestream]) object stream by performing zero or more asynchronous operations on the stream using the stream's async_write_some member function (henceforth referred to as asynchronous write_some operations).

The completion_condition parameter specifies a completion condition to be called prior to each asynchronous write_some operation. The completion condition is passed the error_code value from the most recent asynchronous write_some operation, and the total number of bytes transferred in the asynchronous write operation so far. The completion condition return value specifies the maximum number of bytes to be written on the subsequent asynchronous write_some operation. Overloads where a completion condition is not specified behave as if called with an object of class transfer_all.

The asynchronous write operation continues until:

  • the total number of bytes transferred is equal to buffer_size(buffers); or

  • the completion condition returns 0.

The program shall ensure the AsyncWriteStream object stream is valid until the completion handler for the asynchronous operation is invoked.

On completion of the asynchronous operation, ec is the error_code value from the most recent asynchronous write_some operation, and n is the total number of bytes transferred.

Remarks: This function shall not participate in overload resolution unless is_const_buffer_sequence<ConstBufferSequence>::value is true.

template<class AsyncWriteStream, class DynamicBuffer, class CompletionToken> DEDUCED async_write(AsyncWriteStream& stream, DynamicBuffer&& b, CompletionToken&& token); template<class AsyncWriteStream, class DynamicBuffer, class CompletionCondition, class CompletionToken> DEDUCED async_write(AsyncWriteStream& stream, DynamicBuffer&& b, CompletionCondition completion_condition, CompletionToken&& token);

Completion signature: void(error_code ec, size_t n).

Effects: Initiates an asynchronous operation to write data to the buffer-oriented asynchronous write stream ([buffer.stream.reqmts.asyncwritestream]) object stream by performing zero or more asynchronous write_some operations on the stream.

Data is written from the dynamic buffer ([buffer.reqmts.dynamicbuffer]) object b. A constant buffer sequence ([buffer.reqmts.constbuffersequence]) is obtained using b.data(). After the data has been written to the stream, the implementation performs b.consume(n), where n is the number of bytes successfully written.

The completion_condition parameter specifies a completion condition to be called prior to each asynchronous write_some operation. The completion condition is passed the error_code value from the most recent asynchronous write_some operation, and the total number of bytes transferred in the asynchronous write operation so far. The completion condition return value specifies the maximum number of bytes to be written on the subsequent asynchronous write_some operation. Overloads where a completion condition is not specified behave as if called with an object of class transfer_all.

The asynchronous write operation continues until:

  • b.size() == 0; or

  • the completion condition returns 0.

The program shall ensure both the AsyncWriteStream object stream and the memory associated with the dynamic buffer b are valid until the completion handler for the asynchronous operation is invoked.

On completion of the asynchronous operation, ec is the error_code value from the most recent asynchronous write_some operation, and n is the total number of bytes transferred.

Remarks: This function shall not participate in overload resolution unless is_dynamic_buffer_v<DynamicBuffer> is true.