compio-rs / compio

A thread-per-core Rust runtime with IOCP/io_uring/polling.
MIT License
420 stars 37 forks source link

Lazy-attach/re-attach the handles. #39

Closed Berrysoft closed 1 year ago

Berrysoft commented 1 year ago

Currently the file handles are attached immediately after created. That makes it impossible to write a multi-threading web server: listen in one thread, and spawn the accepted socket to other threads. The solution is:

Berrysoft commented 1 year ago

/cc @bdbai

bdbai commented 1 year ago

Without incurring runtime cost, I think we can mark all Sockets/FDs !Send. Users may manually detach an object, obtaining a Send, type-stamped wrapper to send to another thread. To get back the original wrapped object, users will have to call attach on the wrapper. Does it make sense?

Berrysoft commented 1 year ago

Well, although the driver attached is thread local, the handle itself is technically thread safe...

Berrysoft commented 1 year ago

I've also decided to not use undocumented APIs, which means I cannot detach a handle from the driver. A little painful.