Read from stdin without blocking
Adam D. Ruppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jan 13 06:27:05 PST 2015
The operating system does line buffering, so you'll need to turn
that off. The function is tcssetattr() on Posix and
SetConsoleMode on Windows.
My terminal.d does this in struct ctors and dtors:
https://github.com/adamdruppe/arsd/blob/master/terminal.d
example usage:
http://arsdnet.net/dcode/book/chapter_12/07/input.d
The RealTimeConsoleInput struct turns off buffering and has
functions like getch() and kbhit() to fetch individual characters
from it.
That's not quite the same as getting everything that's available,
but might be useful to you.
Most efficient way I think though is to turn off buffering with
the OS calls, then you can set stdin to be nonblocking and read
chunks off it with ordinary read() or ReadFile calls.
More information about the Digitalmars-d-learn
mailing list