boost::corosio::io_stream::write_some

Asynchronously write data to the stream.

Synopsis

template<capy::ConstBufferSequence CB>
auto
write_some(CB const& buffers);

Description

This operation suspends the calling coroutine and initiates a kernel‐level write. The coroutine resumes when the operation completes.

  • The operation completes when:

  • At least one byte has been written from the buffer sequence

  • An error occurs (including connection reset by peer)

  • The operation is cancelled via stop token or `cancel()`

Concurrency

At most one read operation may be in flight concurrently with this write. No other write operations may be in flight until this operation completes. Note that concurrent in‐flight operations does not imply the initiating calls may be made concurrently; all calls must be serialized.

Cancellation

Supports cancellation via std::stop_token propagated through the IoAwaitable protocol, or via the I/O object's cancel() member. When cancelled, the operation completes with an error that compares equal to capy::cond::canceled.

Preconditions

The stream must be open and connected.

  • `capy::cond::canceled` ‐ Operation was cancelled

  • `std::errc::broken_pipe` ‐ Peer closed connection

Example

// Write all data
std::string_view data = "Hello, World!";
std::size_t written = 0;
while( written < data.size() )
{
    auto [ec, n] = co_await stream.write_some(
        capy::buffer( data.data() + written,
                      data.size() - written ) );
    if( ec.failed() )
        capy::detail::throw_system_error( ec );
    written += n;
}

This operation may write fewer bytes than the buffer contains. Use a loop or capy::async_write to write all data.

Return Value

An awaitable yielding (error_code, std::size_t). On success, bytes_transferred contains the number of bytes written. Compare error codes to conditions, not specific values:

Parameters

Name Description

buffers

The buffer sequence containing data to write. The caller retains ownership and must ensure validity until the operation completes.

See Also

read_some, capy::async_write

Created with MrDocs