Re: Simple way to get a fd polled in glib?
- From: Tristan Van Berkom <tristan van berkom gmail com>
- To: Steven Brown <swbrown variadic org>
- Cc: gtk-list gnome org
- Subject: Re: Simple way to get a fd polled in glib?
- Date: Sun, 04 Jun 2006 20:38:02 -0400
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]