Closed kit-ty-kate closed 1 year ago
I'm a bit reluctant to make such a change as I've already had quite a few ownerships problems due to the use of bytes
(this brings back bad memories of mirage-tcpip).
I'd be more in favour of proposing unsafe_write
with good documentation explaining that the buffer should not be modified until the system call is complete. An bad example will be:
let buf = Bytes.create 0x100 in
let prm0 = Miou.call ~give:[ Miou_unix.owner fd ] (fun () -> Miou_unix.read fd buf ~off:0 ~len:(Bytes.length buf)) in
let prm1 = Miou.call ~give:[ Miou_unix.owner fd ] (fun () -> Miou_unix.write fd buf ~off:0 ~len:(Bytes.length buf)) in
Miou.await_all [ prm0; prm1 ]
It should be noted that with the use of Miou.call_cc
(concurrency), this code could work as long as a certain order is expected in the execution of the tasks (which should never be the case). The example may seem dumb, but we've already found ourselves in this type of situation when:
1) we generally want to have just one buffer (and avoid allocations) throughout the process
2) when you forget about the notion of ownership on other parts (deep in the stack), which is not explained anywhere
I'd definitely prefer an unsafe_write
:+1:.
ok that's fair. I'll close this then. Thanks!
Both
Lwt_unix.write
andUnix
takebytes
as input instead of string. I think keeping it this way would make it easier to miou-ify existing projects.Also, as a side note: one of the example makes it clear that people usually already have a
bytes
type and not astring
type when using this function.