Replacing evil looping code
Alexander Larsson
alexl at redhat.com
Mon Nov 6 08:25:16 PST 2006
On Mon, 2006-11-06 at 11:03 -0500, Havoc Pennington wrote:
> To get out of this code you either need some more generic
> block_for_message() feature that blocks (without reentering the main
> loop) for messages matching some criteria, or you need some way to tell
> the bus "I'm expecting something to own bus name XYZ, please block all
> method calls to it as if you had launched something to own XYZ yourself
> based on a .service file"
Gnome-vfs has some code that just does:
if (!dbus_connection_send_with_reply (connection->connection,
message, &pending_call, timeout)) {
dbus_message_unref (message);
*result = GNOME_VFS_ERROR_INTERNAL;
return NULL;
}
dbus_message_unref (message);
while (!dbus_pending_call_get_completed (pending_call) &&
dbus_connection_read_write_dispatch (connection->connection, -1))
;
reply = dbus_pending_call_steal_reply (pending_call);
This is with a non-mainloop private connection, but the approach might
work for you too.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Alexander Larsson Red Hat, Inc
alexl at redhat.com alla at lysator.liu.se
He's a war-weary drug-addicted senator fleeing from a secret government
programme. She's a cold-hearted streetsmart journalist looking for love in all
the wrong places. They fight crime!
More information about the dbus
mailing list