dbus_g_connection_close() ?

Colin Walters walters at verbum.org
Tue Sep 6 12:25:28 PDT 2005

On Tue, 2005-09-06 at 17:58 +0100, Mark McLoughlin wrote:
> Hey,
> 	Since you currently have to close a connection before unrefing it for
> the last time, it seems like dbus_g_connection_close() would be a
> sensible addition to the glib bindings?
> 	Patch below, okay to commit?

It looks fine to me.  But - the larger issue here is whether developers
are allowed to unref/close connections at all, and if so when.

This came up before.  libdbus wants a module writer to close the
connection before the last unref.  Now, say you are writing a library
which uses libdbus internally (e.g. gnome-vfs); how do you know whether
you have to close the connection before you unref in
gnome_vfs_shutdown() or whatever?  Even if there was a way to get the
refcount of the connection, module writers would end up doing:

if (dbus_connection_get_refcount (connection) == 1) 
  dbus_connection_close (connection)
dbus_connection_unref (connection)

Which is first of all ugly, and second of all obviously racy, so we'd
need to export dbus_connection_lock or something...  

Havoc said if I remember correctly in that discussion that module
writers should just never unref the connection.  I think that's true for
shared connections (which is what most modules use).  

Now, we probably do need to keep the
dbus_connection_ref/dbus_connection_unref for the
dbus_connection_open_private use case. 

So when you commit the patch, could you add a bit of documentation to
dbus_g_connection_close/dbus_g_connection_unref that they should simply
not be used at the moment (since the GLib bindings don't provide a way
to get non-shared connections)?

We should probably also fix libdbus to get rid of the idea of refcounts
for shared connections; e.g. the docs for dbus_connection_open shouldn't
mention the refcount, and dbus_connection_{ref,unref} should have
_dbus_return_val_if_fail (!connection->shared, NULL) or whatever.

-------------- 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/20050906/a81f07cd/attachment.pgp

More information about the dbus mailing list