non-blocking read of stdin on windows



David Byron writes:
 > I'm new to glib and curious about non-blocking read of stdin on windows.

What is stdin connected to in your case? Do you always mean the
console window a console executable is attached to? Or do you want
this to work in general, even if stdin has bee connected to whatever
file or device, either through redirection on the command line,
redirection in the the STARTUPINFO parameter to the CreateProcess()
call, freopen(), or whatever? (D'oh, I assume you mean consoles always.)

What you want to do typically would require Windows-specific ifdefs in
your code to set the console to nonblocking mode. Sorry. Windows just
isn't Unix.

You might also be interested to know that in trunk GLib there is
separate code to handle GIOChannels connected to consoles. (See bug
#359202)

 > but I looked at the code in 2.13.2 and it looks like it can do what I want
 > (although I guess I need to ignore errors from g_io_channel_set_flags).  I'm
 > curious about a few things:
 > 
 > - Am I right that non-blocking read of stdin is supported in 2.13.2?

I don't think so. The patch from bug #359202 only affected the polling
of console file descriptors, not non-blocking mode as such. You still
will have to use non-Glib platform-specific code to turn on
non-blocking mode, I think. But I don't have personal experience from
programming for console I/O on Windows... Experiment!

 > Do 2.13.2 equivalents for [the prebuilt 2.12 Win32 GLib binaries
 > exist] ?

Nope. If you want to use the development branch, you will have to
compile it yourself. I guess I *could* be persuaded to upload to some
non-public place prebuilt binaries of 2.13.2, though, hmm...

--tml



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]