LINK and his friends
Closed this issue · 6 comments
@CarterLi mentioned that we can use a token to link entry together.
link(|link| {
let buf = fd.read(buf, link)?;
fd.write(buf, link)?;
Ok(())
}).await?;
Ergonomics and securing shared buffers are design challenges.
bad english ;)
Ok(())
why two left parentheses?
This is Result<(), _>
.
https://github.com/carterli/liburing4cpp#carefully-use-iosqe_io_link
Never use IOSQE_IO_LINK for RECV-SEND chain because you can't control the number of bytes to send (a short read for RECV is NOT considered an error. I don't know why).
Indeed, it makes things more complicated. :(
link(|link| {
let buf = fd.read(buf, link)?;
fd.write(buf, link)?;
Ok(())
}).await?;
This design may not be user-friendly.
A function named when_all
( or Promise.all in JavaScript ) returns an promise of array (Promise<int[]>
) which holds all results of all futures/promises that the function is awaited, because all results can be useful for the user.
For example:
when_all([
poll(fd, LINK),
read(fd, buf, bufsize, LINK),
write(fd, buf, bufsize),
]).await
Should return ( JS, don't know how to write it in rust )
[
poll_mask_on_success,
bytes_read_or_errno_on_error,
bytes_written_or_ecanceled_if_canceled,
]
Users may test if the last result equals -ECANCELED
to see if an short read is detected, and resubmit the write
operation.
// JS too
if (result[2] === -ECANCELED) {
await write(fd, buf, result[1]);
}
This is a bit complicated and has no obvious benefits. close it temporarily.