Re: Simple way to get a fd polled in glib?

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

 



Steven Brown wrote:

I've been going through the glib docs trying to find a simple way to get
my fd polled by glib's main loop and call me back, but I've not found
anything near simple.  Is there such a way?  E.g., something like
gdk_input_add (which says it's deprecated but doesn't say by what).

I see that it could be implemented by a custom g_source_new and such,
but doing so is a pretty huge amount of code for what should be a
one-liner.  I must be missing something obvious.

Well its not a one-liner... but something close to a one-liner:

==================================
GIOChannel *channel    = g_io_channel_unix_new (fd_to_poll);
guint source_id = g_io_add_watch (channel, /* args of add_watch... */);

/* For convenience... pass ownership of the channel to the attached GIOWatchSource */
g_object_unref (channel);

/* .... */

At this point your callback will be called under the conditions you specified...
when you are finished with the polling... you should call

   g_source_remove(source_id);

and this will get rid of the io channel object as well as your poll function.
==================================

Cheers,
                                  -Tristan

_______________________________________________

gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux