Bug 9334 - rename dbus_watch_get_fd
Summary: rename dbus_watch_get_fd
Status: RESOLVED FIXED
Alias: None
Product: dbus
Classification: Unclassified
Component: core (show other bugs)
Version: unspecified
Hardware: All All
: high normal
Assignee: Havoc Pennington
QA Contact: John (J5) Palmieri
URL:
Whiteboard:
Keywords:
: 9492 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-12-13 13:35 UTC by Peter Kümmel
Modified: 2007-10-09 05:08 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
patch file (6.60 KB, patch)
2006-12-13 13:37 UTC, Peter Kümmel
Details | Splinter Review

Description Peter Kümmel 2006-12-13 13:35:14 UTC
Qt uses dbus_watch_get_fd but on Windows
it doesn't get the fd but a handle, so we
must introduce a function which exports the fd.

On Windows dbus_watch_get_fd acts more
like get_handle.

Attached a patch which renames dbus_watch_get_fd 
into dbus_watch_get_handle and which introduces
a new functions which exports the fd.
Comment 1 Peter Kümmel 2006-12-13 13:37:29 UTC
Created attachment 8094 [details] [review]
patch file
Comment 2 John (J5) Palmieri 2006-12-13 13:51:07 UTC
This patch renames public API which we can't do regaurdless if there are
applications using it or not.
Comment 3 Havoc Pennington 2006-12-13 13:54:07 UTC
what's a "handle" in this context? I thought you were using sockets on Windows?

This patch results in a bunch of things like:

 fd = dbus_watch_get_handle

which doesn't make sense. 

Remember we have no cross-platform idea of a file handle. We have a cross-
platform idea of a socket, which is either a UNIX socket or winsock socket. 
API for this should be named get_socket, etc. get_socket would not return a 
non-socket even on UNIX, it would e.g. return -1 for a UNIX file handle.

API that is unix-specific and returns any file descriptor, not just a socket, 
should be called get_unix_fd and should not work on Windows at all (always 
return -1). See dbus_connection_get_unix_fd() (I think)

dbus_watch_get_fd is really mis-named, which was known when we went to 1.0 but 
we didn't want to impose breakage. I think it should really be documented 
as "this should be considered to be dbus_watch_get_unix_fd() and always 
returns -1 on Windows"

I would then add a dbus_watch_get_socket() and use that when possible.

If Windows ever has non-socket transports, we might need to add 
dbus_watch_get_whatever() to return whatever the non-socket transport uses.

If you really are using Windows handles and not sockets, then I would add a 
dbus_watch_get_windows_handle() that always returns -1 on unix. Be sure the 
data type it returns is guaranteed >= sizeof(HANDLE) though.

Comment 4 Peter Kümmel 2006-12-13 14:51:30 UTC
(In reply to comment #2)
> This patch renames public API which we can't do regaurdless if there are
> applications using it or not.

The patch 1. renames get_fd to get_handle 
and 2. then adds get_fd again, with the same
functionality on the Unix side.
get_handle is only used internally.

Effectively the API doesn't change on the Unix side.
Comment 5 Peter Kümmel 2006-12-13 15:03:26 UTC
(In reply to comment #3)
> what's a "handle" in this context? I thought you were using sockets on Windows?
> 
> This patch results in a bunch of things like:
> 
>  fd = dbus_watch_get_handle

Yes, this looks really inconsistent.

> which doesn't make sense. 
> 
> Remember we have no cross-platform idea of a file handle. We have a cross-
> platform idea of a socket, which is either a UNIX socket or winsock socket. 
> API for this should be named get_socket, etc. get_socket would not return a 
> non-socket even on UNIX, it would e.g. return -1 for a UNIX file handle.

get_handle is not mentioned to be part of the public API, anly get_fd, as before.

> API that is unix-specific and returns any file descriptor, not just a socket, 
> should be called get_unix_fd and should not work on Windows at all (always 
> return -1). See dbus_connection_get_unix_fd() (I think)

Currently it is also possible to get a file descriptor on windows,
so it is not necessary to introduce _unix_.

> dbus_watch_get_fd is really mis-named, which was known when we went to 1.0 but 
> we didn't want to impose breakage. I think it should really be documented 
> as "this should be considered to be dbus_watch_get_unix_fd() and always 
> returns -1 on Windows"
> 

The cleanest way is to have no fd/HANDLE in any public function,
only DBusSockets, DBusFiles,...

> I would then add a dbus_watch_get_socket() and use that when possible.
> 
> If Windows ever has non-socket transports, we might need to add 
> dbus_watch_get_whatever() to return whatever the non-socket transport uses.
> 
> If you really are using Windows handles and not sockets, then I would add a 

the handle is not a 'Windows HANDLE' it is our encrypted fd.

> dbus_watch_get_windows_handle() that always returns -1 on unix. Be sure the 
> data type it returns is guaranteed >= sizeof(HANDLE) though.

A other way to fix the problem with QtDBus is to introduce a new function 
and to patch Qt.


Comment 6 Peter Kümmel 2006-12-13 15:10:26 UTC
> Effectively the API doesn't change on the Unix side.

Better:
The public API doesn't change at all.

The patch fixes a bug on Windows, because get_fd 
currently doesn't return a fd but a *-win.cpp internal 
handle value, totally useless for the client.

Because of this the declaration of get_handle is guarded:

 int          dbus_watch_get_fd      (DBusWatch        *watch);
+#if defined (DBUS_COMPILATION)
+int          dbus_watch_get_handle  (DBusWatch        *watch);
+#endif
Comment 7 Havoc Pennington 2006-12-14 06:38:37 UTC
Internal API should start with an underscore and be in an -internal.h header. 
Internal DBusWatch API should not be used in the bus daemon or outside of the 
dbus/dbus/ directory, though. If you want to use this API in the bus daemon it 
will need to be public.

I don't like the name get_handle() ... if we use the word handle it should 
mean a Windows native handle. I thought we killed off the need for "fake" file 
descriptors when we made the change to have sockets cross-platform? When would 
the watch be on anything other than a socket?

> Currently it is also possible to get a file descriptor on windows,
> so it is not necessary to introduce _unix_.

The Windows public API imo should have a) sockets and b) Windows native HANDLE 
only, and always be clear about which one is returned.
Comment 8 Ralf Habacker 2006-12-31 04:05:30 UTC
*** Bug 9492 has been marked as a duplicate of this bug. ***
Comment 9 Simon McVittie 2007-10-09 05:08:09 UTC
2007-06-18  Havoc Pennington  <hp@redhat.com>

        * dbus/dbus-watch.c (dbus_watch_get_socket)
        (dbus_watch_get_unix_fd): new API to match DBusConnection
        (dbus_watch_get_fd): deprecate this

        Throughout: just s/dbus_watch_get_fd/dbus_watch_get_socket/g for
        now since all the transports use sockets anyway


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.