non-blocking read of stdin on windows



I'm new to glib and curious about non-blocking read of stdin on windows.
I'm trying to do it with code like this:

    GIOChannel *channel;
    GError      *error;
    int         event_id;
    GIOStatus   status;

    channel = g_io_channel_win32_new_fd(STDIN_FILENO);
    status = g_io_channel_set_encoding(channel, NULL, NULL);
    g_io_channel_set_buffered(channel, FALSE);
    error = NULL;
    status = g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, &error);
    if (status != G_IO_STATUS_NORMAL)
    {
        printf("g_io_channel_set_flags failed
%d(%s)\n",error->code,error->message);
    }
    g_io_channel_set_close_on_unref(channel, TRUE);

    event_id = g_io_add_watch_full(channel,  G_PRIORITY_HIGH,
                                  (G_IO_IN | G_IO_HUP | G_IO_ERR |
G_IO_PRI),
                                   my_input_callback, NULL, NULL);
    g_io_channel_unref(channel);

and as you probably know, in glib 2.12.1 g_io_set_channel_flags fails with
this message:

Not implemented on Win32

When I ignore the return value and continue I'm able to read from stdin, but
my_input_callback only gets called after pressing return (big surprise).

This message made me hesitant that things have changed since 2.12.1:

http://mail.gnome.org/archives/gtk-devel-list/2006-September/msg00065.html

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?

- Is the call sequence above correct for at least the setup part of
non-blocking read of stdin on both windows and non-windows platforms (mod
the issue of checking errors from g_io_channel_set_flags)?  Is there some
example code around?

- Do 2.13.2 equivalents for
http://ftp.gnome.org/pub/gnome/binaries/win32/glib/2.12/glib-2.12.11.zip and
http://ftp.gnome.org/pub/gnome/binaries/win32/glib/2.12/glib-dev-2.12.11.zip
?  I'm building an app with MSVC and those have been a big help so far.

Thanks much for your help.

-DB





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