Problem with GSource and polling



Hi folks,

I have a question about using GSource in combinaton with GPollFD.

In a simple application I wrote today, I am creating a simple GSource,
add GPollFD to it with g_source_add_poll() and then I attach the source
to the default main context using g_source_attach().

The prepare function of my custom GSource always returns FALSE, and it
sets the timeout to -1, as is suggested for file descriptor sources in
the GLib API docs. The check function checks events against revents (I
am using a G_IO_IN event condition) and returns TRUE iff revents
includes G_IO_IN. Then I have a dispatch function which is not really
interesting at the moment.

Now I have a file descriptor for which poll() returns 0 for the
first five seconds, and POLLIN from then on. 

What I experienced in my GTK+ app is that there are a few poll() calls
at the beginning, so prepare and check are called. G_IO_IN is not set,
so no dispatching takes place. But after those initial polls, new ones
are only triggered by generating X events (like when moving the mouse
around in the application window). As soon as no X events are generated
anymore (e.g. I move the mouse cursor out of the window), no polls (and
no calls to the prepare and check functions) are happening. If I set the
timeout to something like 1000ms in the prepare function, polling will
happen at least every 1000ms.

Can anyone tell me if this is normal? Is there a way to poll for
G_IO_IN and have prepare/checked/dispatch called without having to
generate X events by means of user interaction? Somehow I was assuming
that GLib would call poll() and go to sleep until there either is an X
event causing the main loop to wake up or until poll() returns because
the requested condition is met. But somehow polling is stopped and GLib
doesn't react on poll events after that.

(I know I could use an idle source or force a timeout, but I really
 want my app to do *nothing* if there is nothing to do; which in this
 case means to block until there are X or poll events.)

Any help would be greatly appreciated. Anyone got an idea?

Cheers,
Jannis


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