GIOChannel Watch



How do I keep the g_io_watch from being called when there is no new data,
I know it's not suppose to get called when there is no data, but my app
runs at 99% cpu as the io_watch func gets called.

I am just tailing a log file... code is below... any help is much
appriciated.

file = g_io_channel_new_file (argv[1], "r", &error);
g_io_add_watch (file, G_IO_IN, get_data, NULL);

gboolean get_data (GIOChannel *source, GIOCondition condition,
                                                            gpointer data)
{
  gchar *buffer;
  gsize length;
  GError *error = NULL;

  while(g_io_channel_read_line (source, &buffer, &length, NULL, &error) ==
                                                        G_IO_STATUS_NORMAL)
  {
     g_print(buffer);
  }

  g_free(buffer);
  return TRUE;
}




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