Question: TCSAFLUSH equivalent for Windows console host? #6892

Open
opened 2026-01-31 00:49:50 +00:00 by claunia · 3 comments
Owner

Originally created by @alexrp on GitHub (Mar 15, 2020).

Hello,

On Unix systems, when setting up a terminal for 'raw' processing, you have the option of passing TCSAFLUSH to tcsetattr(). The description of it is as follows:

the change occurs after all output written to the object referred by fd has been transmitted, and all input that has been received but not read will be discarded before the change is made.

This is quite convenient for certain types of applications since it means you won't get unexpected data back from reading stdin after you've made changes to terminal settings.

I'm wondering if there is an equivalent to this for the Windows console host when using SetConsoleMode()?

Originally created by @alexrp on GitHub (Mar 15, 2020). Hello, On Unix systems, when setting up a terminal for 'raw' processing, you have the option of passing `TCSAFLUSH` to `tcsetattr()`. The description of it is as follows: > the change occurs after all output written to the object referred by fd has been transmitted, and all input that has been received but not read will be discarded before the change is made. This is quite convenient for certain types of applications since it means you won't get unexpected data back from reading `stdin` after you've made changes to terminal settings. I'm wondering if there is an equivalent to this for the Windows console host when using `SetConsoleMode()`?
claunia added the Issue-FeatureProduct-ConhostArea-Server labels 2026-01-31 00:49:50 +00:00
Author
Owner

@DHowett-MSFT commented on GitHub (Mar 19, 2020):

I don't believe there is an equivalent. Perhaps there should be!
I'm tagging this one up as a feature request for the console host. Our bar for features there is pretty high (since getting APIs through API review can take some time), but it's still worth tracking them

@DHowett-MSFT commented on GitHub (Mar 19, 2020): I don't believe there is an equivalent. Perhaps there should be! I'm tagging this one up as a feature request for the console host. Our bar for features there is pretty high (since getting APIs through API review can take some time), but it's still worth tracking them
Author
Owner

@eryksun commented on GitHub (Mar 21, 2020):

This is quite convenient for certain types of applications since it means you won't get unexpected data back from reading stdin after you've made changes to terminal settings.

Doesn't FlushConsoleInputBuffer suffice for this?

@eryksun commented on GitHub (Mar 21, 2020): > This is quite convenient for certain types of applications since it means you won't get unexpected data back from reading stdin after you've made changes to terminal settings. Doesn't [`FlushConsoleInputBuffer`](https://docs.microsoft.com/en-us/windows/console/flushconsoleinputbuffer) suffice for this?
Author
Owner

@alexrp commented on GitHub (Mar 21, 2020):

Oh, I think that'll actually suffice for my case, yes.

Strictly speaking, I believe SetConsoleMode() + FlushConsoleInputBuffer() doesn't have exactly the same semantics as tcsetattr(..., TCSAFLUSH, ...). AFAIK the latter is supposed to be a single atomic operation. Off the top of my head, though, I can't think of any situations where the difference would matter.

@alexrp commented on GitHub (Mar 21, 2020): Oh, I think that'll actually suffice for my case, yes. Strictly speaking, I believe `SetConsoleMode()` + `FlushConsoleInputBuffer()` doesn't have exactly the same semantics as `tcsetattr(..., TCSAFLUSH, ...)`. AFAIK the latter is supposed to be a single atomic operation. Off the top of my head, though, I can't think of any situations where the difference would matter.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#6892