boost::capy::pull_from

Transfer data from a ReadStream to a BufferSink.

Synopsis

template<
    ReadStream Src,
    BufferSink Sink>
requires (!ReadSource<Src>)
io_task<std::size_t>
pull_from(
    Src& source,
    Sink& sink);

Description

This function reads data from the stream directly into the sink's internal buffers using the callee‐owns‐buffers model. The sink provides writable buffers via prepare(), the stream reads into them using read_some(), and the sink commits the data. When the stream signals EOF, commit_eof() is called on the sink to finalize the transfer.

This overload handles partial reads from the stream, committing data incrementally as it arrives. It loops until EOF is encountered or an error occurs.

Example

task<void> transfer_body(ReadStream auto& stream, BufferSink auto& sink)
{
    auto [ec, n] = co_await pull_from(stream, sink);
    if (ec)
    {
        // Handle error
    }
    // n bytes were transferred
}

Return Value

A task that yields (std::error_code, std::size_t). On success, ec is default‐constructed (no error) and n is the total number of bytes transferred. On error, ec contains the error code and n is the total number of bytes transferred before the error.

Template Parameters

Name Description

Src

The source type, must satisfy ReadStream.

Sink

The sink type, must satisfy BufferSink.

Parameters

Name Description

source

The stream to read data from.

sink

The sink to write data to.

See Also

ReadStream, BufferSink, push_to

Created with MrDocs