How to watch file descriptor activity via GMainLoop?



I'm trying to integrate a raw socket based communication link into a main loop using GMainLoop - on the server-side, i.e. the process that listens for connections on the sockets. Does anyone have any good examples on how this might be done? I suppose I want a callback, doing accept() on the socket, every time there is activity on the main file descriptor for the socket, and subsequently when data arrives on the filedescriptor(s) from accept() - but how exactly do I set this up?

Maybe GPollFd and g_source_add_poll() are the keys here, but the documentation is not very clear on how to use these. Also, a normal GSourceFunc type callback does not quite seem suitable for this, in that no reference to the file descriptor will be passed (is there an alternative?) Also, the following note got me wondering [From the g_source_add_poll() doc]:

   The event source's check function will typically test the
   /|revents|/ field in the GPollFD
   <http://library.gnome.org/devel/glib/stable/glib-The-Main-Event-Loop.html#GPollFD>
   struct and return |TRUE|
   <http://library.gnome.org/devel/glib/stable/glib-Standard-Macros.html#TRUE--CAPS>
   if events need to be processed.

Shouldn't the function do the actual event handling, and return true or false based on whether or not the GMainLoop should keep watching for activity?

I'm confused... Help, anyone?

- Toralf



This email and any files contained therein is confidential and may contain privileged information.  If you are not the named addressee(s) or you have otherwise received this in error, you should not distribute or copy this e-mail or use any of its content for any purpose. Please notify the sender immediately by e-mail if you have received this e-mail in error and delete it from your system


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