ocaml-multicore / eio

Effects-based direct-style IO for multicore OCaml
Other
540 stars 66 forks source link

Add Flow.single_write #598

Closed talex5 closed 1 year ago

talex5 commented 1 year ago

Flow.write keeps writing until all the data is sent or an error occurs, but sometimes it's useful to perform only a single write operation. For example, if Buf_write asks to write 5 bytes and only 4 get written, we would previously do another 1-byte write. However, there may have been more data available by then.

This is also useful for error recovery, if you need to know exactly how many bytes were successfully written before the error.

Since we're making everyone update their custom sinks anyway, we might as well fix this at the same time.

Note that the Buf_write tests for Read_source_buffer were supposed to test that the target flow read the buffers directly, but since we started using write instead of copy it doesn't matter.