-
Notifications
You must be signed in to change notification settings - Fork 258
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
support non-blocking files #1500
Comments
a quick summary of what's required to make this works. In theory, we can easily enable SetNonblock() for regular files, but effectively it would only work on *NIX. In fact, the Now, even if we did support that only on *NIX, we should still fix poll_oneoff; because as much as it would still work without it (read() returns EAGAIN and you could just retry after a little), existing code may still assume that so:
now the good news about So in short:
EDIT: on a second thought. Apparently regular files always return immediately from poll_oneoff. So technically our implementation is correct also on Windows 😅 Now I am tempted to take a look at sockets 🤔 |
as for PR #1502, this only enables non-blocking I/O for files on *NIX. Interesting notes, really on regular files poll always returns OK, except that then read() may still return EAGAIN l https://www.remlab.net/op/nonblock.shtml. (In the tests we are using pipes). On Windows Pipes do exist but they require quite a bit of boilerplate to initialize, to the point there are literally go libraries that only do that https://github.com/gesellix/go-npipe https://github.com/natefinch/npipe Summary for further work on Windows.
Long story short, it should be feasible to provide select, and thus poll_oneoff for sockets on Windows too, but it will require some rework of the current |
Thanks for the update. Really good info! Aside: I think one thing we need before closing this also, is a gotip version of the zig non-blocking test, as it isn't intuitive how to set it up. the question came up on slack by @tegk. |
some further work in #1517 on unix. This should address most issues on this platform (with some love probably still needed for poll_oneoff), while work on Windows needs the most attention |
Related: #1538 |
Improve tetratelabs#1500 with a simple observation, i.e. we really need non-blocking I/O only for pipes and sockets. Now, for sockets we can use WinSock select, as for pipes, select_windows.go already imports PeekNamedPipe. We combine PeekNamedPipe with a blocking Read only for those cases when PeekNamedPipe returns n > 0, which means a Read of n bytes won't block. We special case n == 0 to return EAGAIN and ERROR_BROKEN_PIPE as a non-failure (EOF reached). We also introduce `isNonblock(f)` function, specialized on Windows to also check if the file is ModeNamedPipe; otherwise we would default to blocking anyway. Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
#1570 improved support to pipes on Windows. I think that if we fix sockets (just use WinSock select) and we tie everything together in poll_oneoff, we are getting closer to resolving this! |
Is your feature request related to a problem? Please describe.
Currently, we support non-blocking stdio and sockets, but not files. This leads to an awkward and unnecessary skip in go's tests.
Describe the solution you'd like
Go supports non-blocking access and we support native access to files, so we should be able to implement this. If there are any caveats about windows, support can begin with a limited set of platforms.
Describe alternatives you've considered
continue to not do this
Additional context
our file type already has a SetNonblock setting, so that's a start. We also have a separate file implementation for raw os-backed files. So, we should be able to figure out why we aren't implementing non-blocking access for os files, then figure out how to implement it.
The text was updated successfully, but these errors were encountered: