Questions ad minimal server loop implementation ( Re: Howto setup/connect to a listening server [dbus_server_liste (...)] ?

Simon McVittie simon.mcvittie at
Tue Jul 26 02:35:35 PDT 2011

On Tue, 26 Jul 2011 at 11:13:14 +0200, rony wrote:
> What are the minimal requirements for implementing a DBus server loop?

The D-Bus mainloop stuff is rather "inside-out".
The API reference documentation for dbus_connection_set_watch_functions()
should hopefully explain it better - dbus_server_set_watch_functions() is
very similar.

> Would it be sufficient to employ a timeout function (set with
> "dbus_server_set_timeout_functions()")?

No, you need to implement watch functions too. DBusServer gives you a
socket to select() on (or equivalent, like poll() or epoll_wait()), and you
are expected to call back into DBusServer when the socket becomes ready.

>     If not, which function
>     is responsible for invoking the supplied new-connection function
>     supplying the DBusConnection?

The internal functions eventually called by dbus_watch_handle().

> If one is supposed to supply a watch function (set with
> "dbus_server_set_watch_functions()"):
>     How to learn what to watch?

Your DBusAddWatchFunction implementation will be called when a new socket
needs watching. Use dbus_watch_get_enabled(), dbus_watch_get_socket()
and dbus_watch_get_flags() to see what you're expected to do.

>     What is the handler supposed to do

Cal dbus_watch_handle() when an interesting event (where "interesting"
is as defined by dbus_watch_get_flags()) has happened on a socket whose watch
is enabled.


More information about the dbus mailing list