Skip to content

read_at_least, write_at_least #260

@pdimov

Description

@pdimov

It will be convenient to have a read_at_least algorithm that is a straightforward extension of read. While read reads exactly buffer_size(buffers) bytes, read_at_least would take the minimum amount of bytes as a parameter, and the only change would be in the loop condition. Instead of while(bytes_read < buffer_size(buffers)), it would be while(bytes_read < bytes_requested).

One motivating example can be found here:

https://github.com/pdimov/corosio_protocol_bench/blob/ea373f3f9e3c1945627c85f24fb9c256128bb11a/buffered_socket_source.hpp#L62

The "buffered source" implementation needs to read the n bytes requested by the user, and to fill its buffer, with a single invocation. While n is a required amount and must be met or exceeded, the subsequent N bytes filling the buffer are optional and there's no need to block or loop for them.

I don't have a motivating example for write_at_least, but we should provide it for consistency and symmetry.

The one subtlety here is that it's possible for the user to pass parameters that are impossible to satisfy (if the requested minimum amount of bytes exceeds buffer_size(buffers). In this case, I believe that the function should fail immediately, with {EINVAL, 0}.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions