-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
[WIP] Add set_nonblocking method on Stdin #73343
[WIP] Add set_nonblocking method on Stdin #73343
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
347549e
to
da17392
Compare
1a58bac
to
2c3c10b
Compare
How exactly does |
@retep998 I'm actually surprised that windows still blocks... When you set stdin as non blocking, it doesn't block on it, even if there is no input available. You can test it with this code: #include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
int main() {
int flags = fcntl(0, F_GETFL, 0);
fcntl(0, F_SETFL, flags | O_NONBLOCK);
char c[5] = {0, 0, 0, 0, 0};
char *msg = "Enter characters: ";
write(1, msg, strlen(msg));
while (1) {
int r = read(0, &c, 5);
if (r > 0) {
printf("Read %d characters\n", r);
write(1, msg, strlen(msg));
}
}
return 0;
} |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
I could if I had a unixy environment handy but I don't which is why I asked. According to MSDN:
It will block if there is no input. It might be better to split this into two platform specific functions due to the significant difference in behavior.
I don't know why you'd be surprised that it still blocks when |
It looks like this isn't yet ready for review -- I don't have the bandwidth to figure out details here, so marking as S-waiting-on-author for the time being. |
@retep998 What do you suggest then for the naming? |
☔ The latest upstream changes (presumably #72705) made this pull request unmergeable. Please resolve the merge conflicts. |
According to MSDN
When stdin is a console input buffer (not a pipe or anything else), you can check whether there is input to be read, allowing for you to create a read wrapper that does not block. However, note that this specifically applies to any event that can be read using If stdin is a pipe, you can set the state of the pipe to |
I am going to go ahead and close this PR as it doesn't seem to be making progress, and it might be better to hash out viability elsewhere (e.g., internals) since it seems like there's some unexpected trouble with platform compatibility. |
We have
set_nonblocking
method on sockets, but not on stdin, which is very useful. So I guess it might makes sense to have it in the stdlib as well. What do you think?