-
Notifications
You must be signed in to change notification settings - Fork 12
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
Added support for using a fifo on windows with a Named Pipe. #3
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution. I haven't touched this code in a long time, but I'm happy to merge support for Windows :-)
I've left some inline comments, but overall I wonder about the selectors approach you've used. Am I understanding correctly that you've used the selectors
package to get a consistent API between Windows and Linux, but on Windows you are essentially just busy-waiting by polling the pipe and serial port for their output? That seems inefficient (and without some sleep/delay to throttle, would also max out CPU usage?). Does that mean that Windows does not have a way to actually use select or something similar to wait for input and a closed output pipe in a blocking way?
Co-authored-by: Matthijs Kooijman <[email protected]>
So actually, in your original code, the script doesn't even work at all on Windows. Windows doesn't have a way to really do From the I've looked into the WSAPoll() call as part of the Winsock api, but that only supports sockets. I've looked at this version of a simple poll abstraction for Windows, but it really just appears to do what It seems like the only way to get the "poll" functionality that you're looking for on Windows would be to rewrite this with What do you think is the best way forward on this? It's clear that's there may be another way to do what I've done. My goal was to do this with as little of change to the original code as possible. |
I attempted to write this patch with as little change to your written code as possible.
Implemented a simple wrapper for the pipe and serial objects as well as implementing a windows-based, non-file, select.select() method.
Usage on windows will look like:
This differs from the linux fifio because you are not declaring a "file" in a directory. You're just declaring a name. This is due to how Named Pipes work and how they have to be in the Named Pipe directory.
This will produce a pipe in the named pipe directory,
\\.\pipe\
that can be used in the Windows version of pipe just like the Linux fifo. So, you would put into the "pipe" section\\.\pipe\mypipename
.The ability to use
select()
with a fifo on windows comes from the fact that the I have switched to aselectors
-based I/O Multiplexor instead of the previously usedselect
-based.I've done some quick tests to make sure that this works on both linux and windows, and it seems too still function as it did previously.