Cancel dbus_connection_read_write_dispatch cleanly

Thiago Macieira thiago at kde.org
Tue Jul 1 04:37:35 PDT 2008


Fritz Code wrote:
>Maybe there is a better way to cancel the loop manually?
>
>while(flag){
>if ( dbus_connection_read_write_dispatch(conn, 500) != TRUE) )
> break;
>}

Yes, there's a better way: don't use read_write_dispatch, but instead 
write a proper main-loop around select(2) or poll(2). You'll have to 
handle the timers and file descriptors yourself. You'll avoid a 
500-millisecond timeout and you'll save battery resources more. And you 
won't have a 500-millisecond reaction time to cancelling the loop.

>A general question:
>In general  the concept of setting up a connection by dbus_bus_get,
> doing some stuff, sending and receiving messages.
>When Im done I call dbus_connection_unref to close the connection.
>
>After that I can just restart the process, right (setting up connection
> with dbus_bus_get ...) ?

Yes, that's supposed to work.

Note that the unref() does not lead to a disconnect.

-- 
  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
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.freedesktop.org/archives/dbus/attachments/20080701/083a4ca6/attachment.pgp 


More information about the dbus mailing list