-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
os: add a function to construct *File with non-blocking file descriptor #22939
Comments
Perhaps a better approach would be to add a mechanism for the os package to use |
I figured out that the tun fd must be put into epoll after the Besides, the fd can also come from other syscalls like |
If the fd comes from Perhaps if |
To achieve the goal (make use of runtime poller from outside the stdlib), the
I think this is a better solution. |
We should fix this one way or another. Certainly returning EAGAIN from File.Read is not useful to clients, since they don't know when is again. |
Leaving for @ianlancetaylor to decide the exact fix. |
@ianlancetaylor, I am going to move this out of the "Proposal" milestone and into Go1.11 since it was accepted. Please feel free to revert. |
Change https://golang.org/cl/100077 mentions this issue: |
Submitted CL https://golang.org/cl/100077 for your consideration... |
Regarding CL 100077, I'm concerned that some users may set up their own nonblocking files, pass them to |
It now occurs to me that programs that want to use the os package with nonblocking files can still do so after CL 100077 by starting the files in blocking mode, calling |
Will calling |
No, but the case I'm concerned about with regard to Cl 100077 is people who want to use a non-blocking FD. Their code can work if they pass a blocking FD to |
if Stdin and Stdout is Linux FIFO/Pipe, can I use any method above to avoid blocking deadlock? |
@kirbyzhou No, sorry, this does not apply to stdin/stdout, and those not going to be in non-blocking mode anyhow. In any case everything will work with stdin/stdout, you just won't be able to call |
So if I want to do Graceful Exit with I/O blocked on Stdon/Stdout which is FIFO/PIPE, what can I do? For example, the program read plain text from Stdin, and write compressed data to Stdout. |
It's not clear to me what In Go it is always easy to start a goroutine to handle something else. You can always set a deadline by starting a new goroutine or by using |
Change
Add a new function to construct a
*File
with a file descriptor, set non blocking and put it into runtime poller. A naive but working diff:Benefit
With this, I can make use of the runtime poller and have
SetDeadline
method on custom network interfaces.An example (on Linux):
Related issue
#15021
It looks like the main motivations of #15021 are runtime poller and
SetDeadline
.Both of them can be solved by this very simple function.
The text was updated successfully, but these errors were encountered: