Raw libdbus dispatching
thiago at kde.org
Tue Oct 24 14:31:04 PDT 2006
Peter Clifton wrote:
>The glib bindings use a custom GSource to dispatch at most one message
>per mainloop iteration if there are messages pending. Lesstif doesn't
>have a comparible source mechanism. It has Idle work functions (which I
>don't want to use, as it will spin CPU time). It has a "block_hook",
>which looks useful.. it can call your callback before it blocks in the
>mainloop's poll or select function. I could also add a timeout to fire
>periodically, but that doesn't seem like a clean solution.
>Does dispatching a single message before the mainloop blocks ensure that
>we won't get locked up waiting for IO?
>Are there any other ways to alleviate the need for a dispatch call in
>the mainloop? I don't want to block in the DBus code either though!
In Qt, I have a similar problem: there is no equivalent to a raw source
like in glib. So I have to use either timers, events or I/O.
What I use is a form of event/timer that is scheduled for immediate
execution at the next event loop and disables itself after the first run
(it's what we call a "single-shot timer"). It gets enabled in one of
these three cases:
1) the connection has just been created
2) the connection has received Input I/O (the Read watch handler has been
3) dbus_connection_send_with_reply_and_block has been called and, after it
returned, dispatch_status == DATA_REMAINS
The difference here is that this function dispatches all messages until no
data remains. Therefore, it's necessary to have I/O for more data to be
available, so we are sure of catching all cases. In the QtDBus binding,
there is no other way for the connection to receive data (no other
blocking function is ever called).
If you want to do like glib and dispatch only one message, you should
verify at the end of the function if there's still data to be processed
and, if so, keep the timer enabled.
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/dbus/attachments/20061024/886e7cd9/attachment.pgp
More information about the dbus