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}.
It will be convenient to have a
read_at_leastalgorithm that is a straightforward extension ofread. Whilereadreads exactlybuffer_size(buffers)bytes,read_at_leastwould take the minimum amount of bytes as a parameter, and the only change would be in the loop condition. Instead ofwhile(bytes_read < buffer_size(buffers)), it would bewhile(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
nbytes requested by the user, and to fill its buffer, with a single invocation. Whilenis a required amount and must be met or exceeded, the subsequentNbytes 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}.