GIOChannels, yet again



Greetings developers,

I'm having trouble with GIOChannels (again).  At some point in my code
the channel gets open:

/* code */
void channel_open (...)
{
  mIOch = g_io_channel_unix_new (filedes);
  g_io_channel_set_encoding (mIOch, NULL, NULL);
  g_io_channel_set_buffered (mIOch, FALSE);
  g_io_channel_set_close_on_unref (mIOch, TRUE);

  g_io_add_watch (mIOch,
                  G_IO_IN|G_IO_PRI,
                  modem_GIOHandler,
                  <user_data>);
}
/* */

Later, the same channel is closed:

/* code */
void
channel_close (...)
{
  g_io_channel_shutdown (mIOch, FALSE, NULL);
  g_io_channel_unref (mIOch);
  mIOch = NULL;
}
/* */

Everything works O.K. for the first time channel gets open.  But after
closing it, at some point I need to reopen the channel, do some more
work, then close it again.  When I open the channel and try to read some
bytes, I get the following error

/* stderr */
GLib-CRITICAL **: file giochannel.c: line 1748
(g_io_channel_read_chars): assertion `channel->is_readable' failed
/* */

what's baffling me is the fact that just one line above the offending
g_io_channel_read_chars() I add a g_io_channel_get_flags() to refresh
the cache and then check if it's readable (it is), but the reading
function keeps screaming about channel not being readable.  What could
be the cause of this?

(I read from a character special device which is nicely opened and
closed when channel gets open and closed, respectively.)

Best
Zoran





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