-
Notifications
You must be signed in to change notification settings - Fork 744
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
Officially support stdin #321
Comments
It is possible to handle stdin in mio, just in case that's a problem. I have a project that does just that: https://github.com/dpc/colerr/blob/master/src/iomuxer.rs#L26 But I guess some wrappers to support Windows etc. would be nice, yes. Obviously stderr and stdout should be supported too. |
This is going to require more research into how STDIN & co works w/ IOCP. I will tentatively assign this to the 1.0 milestone, but will potentially have to punt if it is tricky. |
It would be nice if mio added both stdin and file operations. It's justifiable since mio is already a good interface to kqueue/epoll/iocp. Pipes and files are treatable by kqueue and epoll similar to network operations. And files (and named pipes) work with iocp just fine. Unfortunately standard handles are the exception, and require extra treatment. For some horrible Windows reason, "console" handles and anonymous pipes don't work with IOCP. For console input, there is |
I'll put in a vote for this. I'm currently using a thread-heavy design in xi-editor, which is the source of more overhead than I'd like. Now that futures-rs is out, basing my RPC mechanism on that is very appealing, but I also very much don't want to have separate code paths on Windows. A small amount of discussion in this reddit thread. |
stdin probably has to be treated separately, because the Windows implementation must be different for stdin. But it is possible to read stdin non-blocking on Windows. I believe it must be polled with |
Decided to look into this and take a look at how a few other projects have proceeded. Ended up with a 1,700 word blog post on IOCP and stdio. @alexchandel I didn't encounter much use of |
Your tldr was about my conclusion as well. The main problem is that keys don't arrive to the "console stdin" of a process as a byte stream, like they do on normal OSs. Instead, when you type into a "console window" on Windows, they arrive in some Win32 input event queue of the process, along with mouse events, menu events, context-change events, and other garbage. This queue receives them in the form of key-up and key-down events, and even receives them for backspace and the arrow-keys. When you call Note that This horrible, atrocious design is why What you can do with In cases where you can't poll, or where filtering key events is a pain or too costly to do on your thread, creating another thread that reads stdin blockingly and posts it in on a named pipe/tcp port/IOCP-compatible thing seems like the only way. The Twisted solution in your blog post doesn't work in the general case, since you need to change your parent/input source as well, which is generally impossible (e.g. for |
With regard to mio/tokio, the best approach is probably for mio to create a "stdin thread" on Windows if the input is a console input handle or an anonymous pipe, and feed that input into an IOCP, since mio already uses IOCP internally on Windows. The issue is that environments with line discipline (e.g. the default state of a terminal emulator, and I believe of Win32 when reading a console handle) correspond to calling |
Thanks all! The answer is going to be "out of scope for mio". Mio provides all the necessary hooks to add stdin support out of crate. This lets others make decisions that work for them and Mio doesn't have to take a stance. |
Looks like this post is now found here: https://tim.mcnamara.nz/post/176613307022/iocp-and-stdio |
Opening an issue as per your request: It would be nice if mio could support
stdin
The text was updated successfully, but these errors were encountered: