-
Notifications
You must be signed in to change notification settings - Fork 19
Type-safe wait functions #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Steal two bits in the sqe data to allow the C stub to return the appropriate encoding directly.
|
I'm a big plus for this! Having ocaml-uring return well-typed Unix.file_descrs is a perfect place to put the abstraction boundary, I feel. It is still useful to be able to convert this to a raw integer for other uses though (like passing it to programs that want an fd number) |
|
Does that fit in with this related thought? Would it be the case that you must pass the fd to a program with its current number, or could you pick one (and have |
|
File descriptors are very much integers on *nix' they're just not on Windows! It's not exactly common, but programs do occasionally just need the fd integer for their own purposes, especially fd passing. |
|
When’s the situation where you need to pass a specific fd as that fd, though? That was the point I was coming around to - if the file descriptor were abstract in C as well, when precisely would that hurt. Process invocation is one, but solvable with a map. Are there concrete cases where it actually can’t be done? |
|
The distinction I was trying to draw is that obviously there are times in C where you need to get at the C representation of the file descriptor - but are there situations other than process spawning where you have to be able to get at it in OCaml? |
Because the hair-splitting is relevant here: OCaml file descriptors are not integers on Windows - the C ones very much are, the OS ones are pointers (where on Unix, the OS and C descriptors share the same thing) |
Note: that is very similar to what Eio already does: |
|
@dra27 wrote:
Ah I understand your point now. Right now we have:
Where fd (Unix.file_descr) can be either an int or a struct. However, this io_uring library will only ever be run on Linux, and so imposing an overhead of allocating a mapping tuple on Linux-only code seems unnecessary -- the two contents of the tuple will be identical in their representation! We could instead expose a |
|
Yes, indeed, a I've only just started looking at it, but given the remarkable similarities between liburing and |
|
I'm not sure where to plumb it into Eio (which might overuse Unix.file_descr in the Linux backend because it's convenient). But that shouldn't stop us from doing it right in this library, and putting the conversion into Eio (which could eventually have a bigger refactor to make it more amenable to the backend-specific fd tracking) |
|
@dra27 wrote:
I think they are very similar on the surface (https://windows-internals.com/ioring-vs-io_uring-a-comparison-of-windows-and-linux-implementations/ is helpful), but there are lots of differences as the more advanced pieces of kernel plumbing get involved (like fixed buffer handling). I'd probably create a separate Windows only ioring library, and then do the integration in Eio in the first instance. |
This is a more invasive alternative to #129 (which also "fixes" #117). I've pontificated about it on my blog.
With this idea, even in a thin wrapping around io_uring, an
intin OCaml is only used to represent an actual (positive-or-zero, as it happens)int, not an encoding of something else. For the fast-path (i.e. where an error is not being returned) there is no difference in allocations, and unlike #129, no cost to retrieving theUnix.file_descrvalue from syscalls which return descriptors.I didn't try plumbing it all the way back to Eio, but if moving the API in this general direction is an agreeable idea, I'd be quite happy to (it might finally tempt me to get my dirty Windows paws on eio backends as well...).
Heap, and simplify'a job?