boost::capy::write
Asynchronously write the entire buffer sequence.
Synopsis
Declared in <boost/capy/write.hpp>
io_task<std::size_t>
write(
auto& stream,
auto const& buffers);
Description
Writes data to the stream by calling write_some repeatedly until the entire buffer sequence is written or an error occurs.
-
The operation completes when:
-
The entire buffer sequence has been written
-
An error occurs
-
The operation is cancelled
Cancellation
Supports cancellation via stop_token propagated through the IoAwaitable protocol. When cancelled, returns with cond::canceled.
-
`cond::canceled` ‐ Operation was cancelled
-
`std::errc::broken_pipe` ‐ Peer closed connection
Example
task<> send_response( WriteStream auto& stream, std::string_view body )
{
auto [ec, n] = co_await write( stream, make_buffer( body ) );
if( ec )
detail::throw_system_error( ec );
// All bytes written successfully
}
Return Value
An awaitable yielding (error_code, std::size_t). On success, n equals buffer_size(buffers). On error, n is the number of bytes written before the error. Compare error codes to conditions:
Parameters
| Name | Description |
|---|---|
stream |
The stream to write to. The caller retains ownership. |
buffers |
The buffer sequence to write. The caller retains ownership and must ensure validity until the operation completes. |
See Also
write_some, WriteStream, ConstBufferSequence
Created with MrDocs