io_uring works fundamentally differently from polling loops and closer to Windows' IOCP (which is awesome and better than everything that existed on Linux for many years). With a polling loop you wait for data to be available in buffers, and then once you get the ready event, you copy it from the kernel's buffer to yours. With IOCP or io_uring, you submit a long-running read or write event directly into your buffer. You get the event after the read or write call, instead of before. Because of this, it's not possible to make it a drop-in replacement for poll/epoll.
From an abstract API perspective it doesn't matter: it's just fire-and-forget where you call a function that will start some I/O and you associate some sort of event completion notice. The details matter only regarding performance.
void *rwtask(param_t v) {
...
a = v->int_ptr;
...
free(a);
It seems architecturally unwise to have a callback responsible for freeing its parameters. At the very least this fossilizes dependency on the stdlib heap.
I think it makes sense to leave freeing up to the callback, because then management of the object (whatever it is) is up to the caller rather than the library. It might make sense to reuse it for a subsequent request (one way or another), or have it as part of some larger object, or some other thing - etc.
As for using the stdlib heap rather than some other thing: sure. But the routine allocating the buffer in this case used malloc to allocate it, and therefore freeing it with free seems at least not the worst option. If you want to do some other thing, you should do that instead.
I was super interested in the non-assembly coroutine approach, as I'm working on a similar project for Zig, but it turns out it just embeds x86_64 binary. Why is that better than having assembly there?
My go-to small event loop library is https://github.com/any1/aml
Why not io_uring? That's the biggest game changer.
I guess because it's not possible to abstract away as much.
io_uring works fundamentally differently from polling loops and closer to Windows' IOCP (which is awesome and better than everything that existed on Linux for many years). With a polling loop you wait for data to be available in buffers, and then once you get the ready event, you copy it from the kernel's buffer to yours. With IOCP or io_uring, you submit a long-running read or write event directly into your buffer. You get the event after the read or write call, instead of before. Because of this, it's not possible to make it a drop-in replacement for poll/epoll.
From an abstract API perspective it doesn't matter: it's just fire-and-forget where you call a function that will start some I/O and you associate some sort of event completion notice. The details matter only regarding performance.
2 replies →
didn't prevent libuv from adding support for it when available:
https://github.com/libuv/libuv/issues/1947
1 reply →
Is this a Windows lib? The tradeoffs are probably completely different than what we're used to then.
> c-events provides function wrappers to some Linux like functionality, exp. mkfifo for Windows.
It seems architecturally unwise to have a callback responsible for freeing its parameters. At the very least this fossilizes dependency on the stdlib heap.
I think it makes sense to leave freeing up to the callback, because then management of the object (whatever it is) is up to the caller rather than the library. It might make sense to reuse it for a subsequent request (one way or another), or have it as part of some larger object, or some other thing - etc.
As for using the stdlib heap rather than some other thing: sure. But the routine allocating the buffer in this case used malloc to allocate it, and therefore freeing it with free seems at least not the worst option. If you want to do some other thing, you should do that instead.
I was super interested in the non-assembly coroutine approach, as I'm working on a similar project for Zig, but it turns out it just embeds x86_64 binary. Why is that better than having assembly there?
See also: Nim's std/selectors API - https://nim-lang.org/docs/selectors.html, it supports: "Supported features: files, sockets, pipes, timers, processes, signals and user events." - here's a HTTP server event loop using it: https://github.com/guzba/mummy/blob/master/src/mummy.nim#L11...
Nice! I could use this :) (for open source work).
Though I would prefer to have something not based on coroutines.