ringbahn / ringbahn

safe bindings to io-uring

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request: Support reading and writing at specific offset.

twissel opened this issue · comments

Currently read and write events always pass '0' offset to io_uring. It would be useful to support custom offsets. Btw, i think read event should have io field declared as shared ref: pub io: &'a T, same in write event probably, but I'm not sure.

In the long term the crate should definitely support these! For now, I'm just working on making sure the internal mechanics are soundly implemented, so it will be on the backburner for the time being.

I think I'd probably add a new ReadOffset and WriteOffset Event, rather than making Read and Write have an offset field.

So when I wrote the last comment I didn't realize that read and write on io_uring don't modify any internal cursor, but that the user has to manage the offset themselves.

I think Read and Write should be changed to have an offset field users can set and also that they should just have a RawFd field instead of a reference to an AsRawFd. I would make these changes later this week, but I thought I'd post this now in case you or anyone else wants to implement it.

@withoutboats, FYI: io_uring actually can manage offsets, see: axboe/liburing#32, and man page entries for IORING_FEAT_RW_CUR_POS.

@withoutboats , I have a proposal, we can leave current read and write events as they are, passing -1 to uring sys, and add ReadOffsetEvent and WriteOffsetEvent as you wanted. If you don't mind I can implement this.

@twissel I would like that if it works, but I have some concerns:

  1. It only works if the ring was set up with IORING_FEAT_RW_CUR_POS, which isn't on by default. How do we handle that?
  2. What happens if you apply these to an fd that's not a file, like a socket? I think it might error.. As I understand, sockets require that you pass an offset of 0.

I thnk it might be better to do what you're proposing but with the names flipped: Read takes an offset, ReadCursor (or something) passes -1. Then ReadCursor can document these caveats, and I feel okay with that because its not the default.

@twissel I would like that if it works, but I have some concerns:

  1. It only works if the ring was set up with IORING_FEAT_RW_CUR_POS, which isn't on by default. How do we handle that?
  2. What happens if you apply these to an fd that's not a file, like a socket? I think it might error.. As I understand, sockets require that you pass an offset of 0.
  1. I can be wrong, but IORING_FEAT_RW_CUR_POS should be supported by default starting with 5.6.7 kernel .
  2. Thats a good question, don't ever tried to do so.
    Anyways, I think you are right about flipping names.