Skip to content
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

Closed

Conversation

GuillaumeGomez
Copy link
Member

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?

@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 14, 2020
@rust-highfive
Copy link
Collaborator

The job mingw-check of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
##[section]Starting: Linux mingw-check
##[section]Starting: Initialize job
Agent name: 'Azure Pipelines 8'
Agent machine name: 'fv-az578'
Current agent version: '2.170.1'
##[group]Operating System
16.04.6
LTS
LTS
##[endgroup]
##[group]Virtual Environment
Environment: ubuntu-16.04
Version: 20200604.1
Included Software: https://github.com/actions/virtual-environments/blob/ubuntu16/20200604.1/images/linux/Ubuntu1604-README.md
##[endgroup]
Agent running as: 'vsts'
Prepare build directory.
Set build variables.
Download all required tasks.
Download all required tasks.
Downloading task: Bash (3.163.3)
Checking job knob settings.
   Knob: AgentToolsDirectory = /opt/hostedtoolcache Source: ${AGENT_TOOLSDIRECTORY} 
   Knob: AgentPerflog = /home/vsts/perflog Source: ${VSTS_AGENT_PERFLOG} 
Start tracking orphan processes.
##[section]Finishing: Initialize job
##[section]Starting: Configure Job Name
==============================================================================
---
========================== Starting Command Output ===========================
[command]/bin/bash --noprofile --norc /home/vsts/work/_temp/a3c31a08-1579-43c4-bd56-6b70bb5d22e4.sh

##[section]Finishing: Disable git automatic line ending conversion
##[section]Starting: Checkout rust-lang/rust@refs/pull/73343/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
---
##[command]git remote add origin https://github.com/rust-lang/rust
##[command]git config gc.auto 0
##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
##[command]git config --get-all http.proxy
##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/73343/merge:refs/remotes/pull/73343/merge
---
 ---> f883e675ad62
Step 6/7 : ENV RUN_CHECK_WITH_PARALLEL_QUERIES 1
 ---> Using cache
 ---> c0b156eb069c
Step 7/7 : ENV SCRIPT python3 ../x.py test src/tools/expand-yaml-anchors &&            python3 ../x.py check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu &&            python3 ../x.py build --stage 0 src/tools/build-manifest &&            python3 ../x.py test --stage 0 src/tools/compiletest &&            python3 ../x.py test src/tools/tidy &&            python3 ../x.py doc --stage 0 src/libstd &&            /scripts/validate-toolstate.sh
 ---> 8541bab6b38c
Successfully built 8541bab6b38c
Successfully tagged rust-ci:latest
Built container sha256:8541bab6b38c07f1b7eb787539b9cbe93daa6ac4458d3d7bd8a8921622a14ba1
---
    Checking rustc_parse_format v0.0.0 (/checkout/src/librustc_parse_format)
    Checking chalk-rust-ir v0.10.0
    Checking rustc_ast_pretty v0.0.0 (/checkout/src/librustc_ast_pretty)
    Checking rustc_hir v0.0.0 (/checkout/src/librustc_hir)
    Checking rustc_query_system v0.0.0 (/checkout/src/librustc_query_system)
    Checking chalk-solve v0.10.0
    Checking rustc_parse v0.0.0 (/checkout/src/librustc_parse)
    Checking rustc_hir_pretty v0.0.0 (/checkout/src/librustc_hir_pretty)
    Checking rustc_ast_lowering v0.0.0 (/checkout/src/librustc_ast_lowering)
---
configure: rust.debug-assertions := True
configure: dist.missing-tools   := True
configure: llvm.ccache          := sccache
configure: rust.channel         := nightly
configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
configure: writing `config.toml` in current directory
configure: 
configure: run `python /checkout/x.py --help`
configure: 
---
Hugepagesize:       2048 kB
DirectMap4k:      133056 kB
DirectMap2M:     4061184 kB
DirectMap1G:     5242880 kB
+ python3 ../x.py test src/tools/expand-yaml-anchors
Ensuring the YAML anchors in the GitHub Actions config were expanded
Ensuring the YAML anchors in the GitHub Actions config were expanded
Building stage0 tool expand-yaml-anchors (x86_64-unknown-linux-gnu)
   Compiling unicode-xid v0.2.0
   Compiling syn v1.0.11
   Compiling linked-hash-map v0.5.2
   Compiling lazy_static v1.4.0
   Compiling lazy_static v1.4.0
   Compiling yaml-rust v0.4.3
   Compiling quote v1.0.2
   Compiling thiserror-impl v1.0.5
   Compiling thiserror v1.0.5
   Compiling yaml-merge-keys v0.4.0
   Compiling expand-yaml-anchors v0.1.0 (/checkout/src/tools/expand-yaml-anchors)
Build completed successfully in 0:00:32
+ python3 ../x.py check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu
    Finished dev [unoptimized] target(s) in 0.20s
Checking rustdoc artifacts (x86_64-unknown-linux-gnu -> i686-pc-windows-gnu)
---
    Checking panic_unwind v0.0.0 (/checkout/src/libpanic_unwind)
error[E0425]: cannot find value `ENABLE_LINE_INPUT` in module `c`
   --> src/libstd/sys/windows/stdio.rs:147:24
    |
147 |             mode ^= c::ENABLE_LINE_INPUT;
    |                        ^^^^^^^^^^^^^^^^^ not found in `c`
error[E0425]: cannot find value `ENABLE_LINE_INPUT` in module `c`
   --> src/libstd/sys/windows/stdio.rs:149:24
    |
    |
149 |             mode |= c::ENABLE_LINE_INPUT;
    |                        ^^^^^^^^^^^^^^^^^ not found in `c`
error[E0425]: cannot find function, tuple struct or tuple variant `SetConsoleMode` in module `c`
   --> src/libstd/sys/windows/stdio.rs:151:16
    |
    |
151 |           if !c::SetConsoleMode(handle, mode) {
    |                  ^^^^^^^^^^^^^^ help: a function with a similar name exists: `GetConsoleMode`
   ::: src/libstd/sys/windows/c.rs:689:9
    |
    |
689 | /         pub fn GetConsoleMode(hConsoleHandle: HANDLE,
690 | |                               lpMode: LPDWORD) -> BOOL;
    | |_______________________________________________________- similarly named function `GetConsoleMode` defined here
error[E0308]: mismatched types
   --> src/libstd/sys/windows/stdio.rs:140:12
    |
    |
140 |         if !c::GetConsoleMode(handle, &mut mode) {
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `i32`
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0308, E0425.
For more information about an error, try `rustc --explain E0308`.
---
  local time: Sun Jun 14 14:51:49 UTC 2020
  network time: Sun, 14 Jun 2020 14:51:49 GMT
== end clock drift check ==

##[error]Bash exited with code '1'.
##[section]Finishing: Run build
##[section]Starting: Checkout rust-lang/rust@refs/pull/73343/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
Author       : Microsoft
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
==============================================================================
Cleaning any cached credential from repository: rust-lang/rust (GitHub)
##[section]Finishing: Checkout rust-lang/rust@refs/pull/73343/merge to s
Cleaning up task key
Start cleaning up orphan processes.
Terminate orphan process: pid (4087) (python)
##[section]Finishing: Finalize Job

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 @rust-lang/infra. (Feature Requests)

@GuillaumeGomez GuillaumeGomez force-pushed the stdin-set-nonblocking branch 2 times, most recently from 347549e to da17392 Compare June 25, 2020 12:54
@GuillaumeGomez GuillaumeGomez force-pushed the stdin-set-nonblocking branch from 1a58bac to 2c3c10b Compare June 25, 2020 14:23
@retep998
Copy link
Member

How exactly does O_NONBLOCK behave for terminals on unixy platforms? On Windows when ENABLE_LINE_INPUT is disabled it will still block until some input is received, but it will not wait for a whole line to be entered but rather return immediately as soon as there is any input. Do unixy platforms behave the same or can they return immediately if there is no input? If the latter, then this difference needs to be spelled out big and loud in the documentation.

@GuillaumeGomez
Copy link
Member Author

@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;
}

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-8 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
##[section]Starting: Linux x86_64-gnu-llvm-8
##[section]Starting: Initialize job
Agent name: 'Hosted Agent'
Agent machine name: 'fv-az578'
Current agent version: '2.170.1'
##[group]Operating System
16.04.6
LTS
LTS
##[endgroup]
##[group]Virtual Environment
Environment: ubuntu-16.04
Version: 20200621.1
Included Software: https://github.com/actions/virtual-environments/blob/ubuntu16/20200621.1/images/linux/Ubuntu1604-README.md
##[endgroup]
Agent running as: 'vsts'
Prepare build directory.
Set build variables.
Download all required tasks.
Download all required tasks.
Downloading task: Bash (3.171.1)
Checking job knob settings.
   Knob: AgentToolsDirectory = /opt/hostedtoolcache Source: ${AGENT_TOOLSDIRECTORY} 
   Knob: AgentPerflog = /home/vsts/perflog Source: ${VSTS_AGENT_PERFLOG} 
Start tracking orphan processes.
##[section]Finishing: Initialize job
##[section]Starting: Configure Job Name
==============================================================================
---
========================== Starting Command Output ===========================
[command]/bin/bash --noprofile --norc /home/vsts/work/_temp/9d5cf8e6-5bc4-4aeb-a6ef-ce83de8e403b.sh

##[section]Finishing: Disable git automatic line ending conversion
##[section]Starting: Checkout rust-lang/rust@refs/pull/73343/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
---
##[command]git remote add origin https://github.com/rust-lang/rust
##[command]git config gc.auto 0
##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
##[command]git config --get-all http.proxy
##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/73343/merge:refs/remotes/pull/73343/merge
---
 ---> 31fea614d2f3
Step 5/8 : ENV RUST_CONFIGURE_ARGS       --build=x86_64-unknown-linux-gnu       --llvm-root=/usr/lib/llvm-8       --enable-llvm-link-shared       --set rust.thin-lto-import-instr-limit=10
 ---> Using cache
 ---> 4195cadf126d
Step 6/8 : ENV SCRIPT python2.7 ../x.py test --exclude src/tools/tidy &&            python2.7 ../x.py test src/test/mir-opt --pass=build                                   --target=armv5te-unknown-linux-gnueabi &&            python2.7 ../x.py test src/tools/tidy
 ---> 4e90f6b48f05
Step 7/8 : ENV NO_DEBUG_ASSERTIONS=1
 ---> Using cache
 ---> dfa0a356d899
---
Set({"src/librustc_parse_format"}) not skipped for "bootstrap::test::CrateLibrustc" -- not in ["src/tools/tidy"]
Set({"src/librustc_passes"}) not skipped for "bootstrap::test::CrateLibrustc" -- not in ["src/tools/tidy"]
Set({"src/librustc_plugin_impl"}) not skipped for "bootstrap::test::CrateLibrustc" -- not in ["src/tools/tidy"]
Set({"src/librustc_privacy"}) not skipped for "bootstrap::test::CrateLibrustc" -- not in ["src/tools/tidy"]
Set({"src/librustc_query_system"}) not skipped for "bootstrap::test::CrateLibrustc" -- not in ["src/tools/tidy"]
Set({"src/librustc_save_analysis"}) not skipped for "bootstrap::test::CrateLibrustc" -- not in ["src/tools/tidy"]
Set({"src/librustc_serialize"}) not skipped for "bootstrap::test::CrateLibrustc" -- not in ["src/tools/tidy"]
Set({"src/librustc_session"}) not skipped for "bootstrap::test::CrateLibrustc" -- not in ["src/tools/tidy"]
Set({"src/librustc_span"}) not skipped for "bootstrap::test::CrateLibrustc" -- not in ["src/tools/tidy"]
---
Set({"src/librustc_parse_format"}) not skipped for "bootstrap::doc::Rustc" -- not in ["src/tools/tidy"]
Set({"src/librustc_passes"}) not skipped for "bootstrap::doc::Rustc" -- not in ["src/tools/tidy"]
Set({"src/librustc_plugin_impl"}) not skipped for "bootstrap::doc::Rustc" -- not in ["src/tools/tidy"]
Set({"src/librustc_privacy"}) not skipped for "bootstrap::doc::Rustc" -- not in ["src/tools/tidy"]
Set({"src/librustc_query_system"}) not skipped for "bootstrap::doc::Rustc" -- not in ["src/tools/tidy"]
Set({"src/librustc_save_analysis"}) not skipped for "bootstrap::doc::Rustc" -- not in ["src/tools/tidy"]
Set({"src/librustc_serialize"}) not skipped for "bootstrap::doc::Rustc" -- not in ["src/tools/tidy"]
Set({"src/librustc_session"}) not skipped for "bootstrap::doc::Rustc" -- not in ["src/tools/tidy"]
Set({"src/librustc_span"}) not skipped for "bootstrap::doc::Rustc" -- not in ["src/tools/tidy"]
---
   Compiling rustc_parse_format v0.0.0 (/checkout/src/librustc_parse_format)
   Compiling chalk-engine v0.11.0
   Compiling rustc_ast_pretty v0.0.0 (/checkout/src/librustc_ast_pretty)
   Compiling rustc_hir v0.0.0 (/checkout/src/librustc_hir)
   Compiling rustc_query_system v0.0.0 (/checkout/src/librustc_query_system)
   Compiling chalk-solve v0.11.0
   Compiling rustc_hir_pretty v0.0.0 (/checkout/src/librustc_hir_pretty)
   Compiling rustc_parse v0.0.0 (/checkout/src/librustc_parse)
   Compiling rustc_ast_lowering v0.0.0 (/checkout/src/librustc_ast_lowering)
---
   Compiling rustc_parse_format v0.0.0 (/checkout/src/librustc_parse_format)
   Compiling chalk-ir v0.11.0
   Compiling rustc_ast_pretty v0.0.0 (/checkout/src/librustc_ast_pretty)
   Compiling rustc_hir v0.0.0 (/checkout/src/librustc_hir)
   Compiling rustc_query_system v0.0.0 (/checkout/src/librustc_query_system)
   Compiling chalk-engine v0.11.0
   Compiling rustc_hir_pretty v0.0.0 (/checkout/src/librustc_hir_pretty)
   Compiling chalk-solve v0.11.0
   Compiling rustc_parse v0.0.0 (/checkout/src/librustc_parse)
---
......................i............................................................................. 1900/10396
.................................................................................................... 2000/10396
.................................................i..i............................................... 2100/10396
.................................................................................................... 2200/10396
.......................................iiiii........................................................ 2300/10396
.................................................................................................... 2500/10396
.................................................................................................... 2600/10396
.................................................................................................... 2700/10396
.................................................................................................... 2800/10396
---
.................................................................................................... 5300/10396
.................................................................................................... 5400/10396
..............................i..................................................................... 5500/10396
........................i........................................................................... 5600/10396
............................................ii.ii........i...i...................................... 5700/10396
.............i...................................................................................... 5900/10396
.........i.......................................................................................... 6000/10396
.................................................................ii................................. 6100/10396
....i............................................................................................... 6200/10396
....i............................................................................................... 6200/10396
.................................................................................................... 6300/10396
.................................................................................................... 6400/10396
............................ii...i..ii...........i.................................................. 6500/10396
.................................................................................................... 6700/10396
.................................................................................................... 6800/10396
.................................................................................................... 6800/10396
...............................................................i..ii................................ 6900/10396
.................................................................................................... 7100/10396
.................................................................................................... 7200/10396
...................i................................................................................ 7300/10396
.................................................................................................... 7400/10396
---
.................................................................................................... 8300/10396
.................................................................................................... 8400/10396
....................................................................i............................... 8500/10396
.................................................................................................... 8600/10396
......................iiiiii..iiiiii.i.............................................................. 8700/10396
.................................................................................................... 8900/10396
.................................................................................................... 9000/10396
.................................................................................................... 9100/10396
.................................................................................................... 9200/10396
---
Suite("src/test/codegen") not skipped for "bootstrap::test::Codegen" -- not in ["src/tools/tidy"]
Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)

running 197 tests
iiii......i................ii.i..........i......................i...........i..i........i........i.. 100/197
..i.............i.i.i...iii..iiii....................................iii.................ii......

 finished in 6.835
Suite("src/test/codegen-units") not skipped for "bootstrap::test::CodegenUnits" -- not in ["src/tools/tidy"]
Check compiletest suite=codegen-units mode=codegen-units (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
---
Suite("src/test/assembly") not skipped for "bootstrap::test::Assembly" -- not in ["src/tools/tidy"]
Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)

running 22 tests
iiiiiiiiiiiiiiiiiiiiii

 finished in 0.154
Suite("src/test/incremental") not skipped for "bootstrap::test::Incremental" -- not in ["src/tools/tidy"]
Check compiletest suite=incremental mode=incremental (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
---
Suite("src/test/debuginfo") not skipped for "bootstrap::test::Debuginfo" -- not in ["src/tools/tidy"]
Check compiletest suite=debuginfo mode=debuginfo (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)

running 116 tests
iiiii..i.....i..i...i..i.i.i..i..i..ii....i.i....ii..........iiii.........i.....i...i.......ii.i.ii. 100/116
....iiii.....ii.

 finished in 14.689
Suite("src/test/ui-fulldeps") not skipped for "bootstrap::test::UiFullDeps" -- not in ["src/tools/tidy"]
Uplifting stage1 rustc (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
---

   Doc-tests core

running 2589 tests
......iiiii......................................................................................... 100/2589
.................................................................................................ii. 200/2589
.......................................i............................................................ 400/2589
...............................................................................................i..i. 500/2589
...............................................................................................i..i. 500/2589
.................iiii............................................................................... 600/2589
.................................................................................................... 800/2589
.................................................................................................... 900/2589
.................................................................................................... 1000/2589
.................................................................................................... 1100/2589
---

running 1029 tests
i................................................................................................... 100/1029
.................................................................................................... 200/1029
...................iii......i......i...i.........i.................................................. 300/1029
.......................................FF...................i....i.................................. 500/1029
.....ii............................................................................................. 600/1029
.................................................................................................... 700/1029
.................................................................................................... 700/1029
.....................................................iiii........................................... 800/1029
.................................................................................................... 900/1029
............................................................................iiii.................... 1000/1029
failures:

---- io/stdio.rs - io::stdio::Stdin::set_nonblocking (line 382) stdout ----
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
  --> io/stdio.rs:390:5
   |
10 |     handle.set_nonblocking(true)?;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
   = note: consult the function's documentation for information on how to avoid undefined behavior

error: aborting due to previous error


For more information about this error, try `rustc --explain E0133`.
Couldn't compile the test.
---- io/stdio.rs - io::stdio::StdinLock::set_nonblocking (line 482) stdout ----
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
  --> io/stdio.rs:490:5
   |
10 |     handle.set_nonblocking(true)?;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
   = note: consult the function's documentation for information on how to avoid undefined behavior

error: aborting due to previous error

---
  local time: Thu Jun 25 15:52:45 UTC 2020
  network time: Thu, 25 Jun 2020 15:52:46 GMT
== end clock drift check ==

##[error]Bash exited with code '1'.
##[section]Finishing: Run build
##[section]Starting: Checkout rust-lang/rust@refs/pull/73343/merge to s
Task         : Get sources
Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version      : 1.0.0
Author       : Microsoft
Author       : Microsoft
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
==============================================================================
Cleaning any cached credential from repository: rust-lang/rust (GitHub)
##[section]Finishing: Checkout rust-lang/rust@refs/pull/73343/merge to s
Cleaning up task key
Start cleaning up orphan processes.
Terminate orphan process: pid (3787) (python)
##[section]Finishing: Finalize Job

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 @rust-lang/infra. (Feature Requests)

@retep998
Copy link
Member

retep998 commented Jun 25, 2020

You can test it with this code:

I could if I had a unixy environment handy but I don't which is why I asked.

According to MSDN:

If this mode is disabled, the functions return when one or more characters are available.

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'm actually surprised that windows still blocks...

I don't know why you'd be surprised that it still blocks when ENABLE_LINE_INPUT does not mention blocking anywhere in its name nor its description.

@Mark-Simulacrum
Copy link
Member

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.

@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 25, 2020
@GuillaumeGomez
Copy link
Member Author

@retep998 What do you suggest then for the naming?

@bors
Copy link
Contributor

bors commented Jun 28, 2020

☔ The latest upstream changes (presumably #72705) made this pull request unmergeable. Please resolve the merge conflicts.

@Muirrum Muirrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 16, 2020
@retep998
Copy link
Member

According to MSDN

A process can specify a console input buffer handle in one of the wait functions to determine when there is unread console input. When the input buffer is not empty, the state of a console input buffer handle is signaled.

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 ReadConsoleInput, including mouse input which would not be read using normal ReadConsoleW calls, so the handle might be signaled but ReadConsoleW would still block. Also if the console is in line input mode, ReadConsoleW will block until the user presses enter which you have no way of knowing in advance.

If stdin is a pipe, you can set the state of the pipe to PIPE_NOWAIT which causes reads to be non-blocking, so if there is no input available it will return immediately. If stdin is a file, there is no non-blocking read, instead there is only overlapped reads where you start a read, it returns immediately, and then you get the result later somehow.

@Muirrum Muirrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 6, 2020
@crlf0710 crlf0710 marked this pull request as draft August 28, 2020 18:36
@crlf0710 crlf0710 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 28, 2020
@Mark-Simulacrum
Copy link
Member

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.

@GuillaumeGomez GuillaumeGomez deleted the stdin-set-nonblocking branch August 19, 2024 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants