-
Notifications
You must be signed in to change notification settings - Fork 9
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
Windows support #14
Comments
I don't really have any experience writing software on Windows and don't really have a use-case for this on Windows (because I haven't actively used a Windows system in a decade or so). That said, I am open to PRs that add support for Windows to this crate. I am not specifically tied to the |
Yeah, I don't actually need it either, it's just that this crate is the only thing that makes my crate not support Windows at the moment, and I'm sure others are in the same boat. I wouldn't normally care, it's just that since this is a relatively low-level crate, its lack of support for Windows is likely to affect many higher-level crates. In theory, with the approach I gave above, the Linux and Windows solutions should be practically identical, just with different syscalls to set/reset the timeout. |
If you have any way of testing this, I wired up something in #15 that at least builds and doesn't crash when I run through my basic (very basic) tests. I don't really have a good test environment for Windows... |
I've actually been fairly happy with Azure Pipelines, and that also gives Windows testing. Since I maintain the template for it, I'd be happy to help you get set up! I think the first-time setup notes should still be accurate, but if you run into any issues, let me know and I'll see what I can do! |
Ohh, I see, you meant in terms of actually writing tests! |
So, blocking on reading from |
Oh, then, how about you start a The "doesn't work for stdio on windows" caveat seems pretty important to at least document. Especially because I think for some that'll be a big use-case for this. I wonder why... |
There's some discussion over at https://stackoverflow.com/questions/19955617/win32-read-from-stdin-with-timeout for how to make it work on |
The more I am digging into this, the messier it gets. So, on unix-like systems, I can use So, on Windows, there are a minimum of three different APIs that I can find. WaitForSingleObject looks to be what has to be used for "the console" (meaning stdin, I suppose). SetCommTimeouts is used for "communications resources" meaning:
Then, there is the socket API in winsock2 that is used for setting the timeouts on a SOCKET. Unfortunately, a I am not entirely sure the mechanism that Windows uses (really, |
Ugh, yeah, it does look like a mess. I think there's a decent argument here for leaving the crate as UNIX-only, and then maybe someone writing a specialized crate just for timing out stdin on Windows. That is probably what people are using this crate for anyway (since, as you say, |
Yeah, I think that is going to be what I do. I just don't have the experience with the Windows APIs to even know what the right thing is in this cases. |
I agree with you! Thanks for looking into it :) |
I know this is probably low priority, but it'd be nice to have, and I figured having a tracking issue might be useful.
The implementation I think would go like this:
std::os::raw::c_int
where relevantcfg(windows)
, usestd::os::windows::AsRawHandle
instead ofstd::os::unix::AsRawFd
winapi::um::commapi::SetCommTimeouts
to set a timeout for the user's handle for an operation. It is documented here.My guess is that you could do away with the current
Poll
-based implementation, and instead just implement the read/write operations as "set timeout on fd/handle, call read/write, unset timeout". If you specifically want it to be poll-based, mio would probably be the way to do that (#3), though that'd be a larger rewrite I think.The text was updated successfully, but these errors were encountered: