Porting Reactor to 0.16.x std.io - move to Proactor?

moving my project from 0.15.2 to 0.16.x.

old code uses a reactor pattern:

  • dedicated i/o thread.
  • non-blocking sockets.
  • big poll loop.
  • linux only.

I want to support linux (epoll/io_uring), windows (iocp), and macos (kqueue).
my current flow is one io thread with a number of “client” threads.

Questions:

  1. does the new std.io allow implementing a reactor-style loop?
  2. is it possible to run a single-threaded proactor in 0.16.x?
  3. does 0.16.x force moving the whole architecture to proactor?
  4. what is the idiomatic way to implement this?

This sounds exactly like my zio project.

1 Like

i am talking about tofu

if std.io does not support single threaded proactor, it’s great idea

is it ok with you to discuss tofu implementation on zio tofu implementation on zio

std.Io is just an interface, it depends on threads or coroutines, so you need to have one of these, but what is behind them it doesn’t care. The terminology is a bit muddy, but I guess by “reactor” you mean readiness based event loop and by “proactor” you mean completion based event loop. In that case, it doesn’t really matter, because the final API has to be blocking, which is “proactor” by default, so it doesn’t matter if you want for readiness via epoll and then do recv() or if you send the full recv request to io_uring.

1 Like
  • yes

just to be sure

does new io support single-threaded readiness/completion based event loop and hides os staff (epoll/iocp/kqueue) ?

There are two things, the interface and the implementations.

The interface was designed to support single-threaded event-loop based operation, backed by stackful coroutines. So yes, it does support that. Nothing from the OS APIs is exposed directly here.

The std.Io.Evented implementation of the interface doesn’t exist yet, or it does exist, but it’s still not complete. The Linux version is probably the most complete, but still far from done.

That’s where zio comes, it’s basically another implementation of the interface, still not complete, because the interface keeps growing, but it’s already usable on all major operating systems. And yes, you can use zio’s implementatoin of std.Io with a single-threaded event loop.

1 Like