robur-coop / miou

A simple scheduler for OCaml 5
https://docs.osau.re/miou/index.html
MIT License
93 stars 7 forks source link

Add Miou_unix.really_read #20

Closed kit-ty-kate closed 7 months ago

kit-ty-kate commented 7 months ago

Similar to Stdlib.really_read

Sits on top of #18

dinosaure commented 7 months ago

We probably can use optional argument for Miou_unix.read and Miou_unix.write which infer the length of the buffer like:

let read fd ?(off= 0) ?len buf =
  let len = match len with
    | Some len -> len
    | None -> Bytes.length buf - off in
  blocking_read fd;
  Unix.read fd buf off len

It breaks the API but I already broke it with Miou.{set,sys}_signal.

EDIT: but yeah, really_read is still needed which fullfills the given buffer.

dinosaure commented 7 months ago

Remplaced by https://git.robur.coop/robur/miou/pulls/52, thanks!

kit-ty-kate commented 6 months ago

I'm not sure to understand the implementation that you chose. In particular:

  if len - len' <= 0 then
    really_read file_descr ~off:(off + len') ~len:(len - len') buf

it looks to me like you'd want the opposite:

if len - len' > 0 then

or simply:

if len - len' <> 0 then

like i did in this here PR

dinosaure commented 6 months ago

Yes, it was fixed by this commit