win32 patch dbus_watch_get_handle patch

Peter Kümmel syntheticpp at gmx.net
Sat Jun 16 00:44:21 PDT 2007


Ralf Habacker wrote:
> Hi,
> 
> the appended patch is required for win32. This patch was initiated by
> Havoc Pennington and was initial developed by Peter Kümmel.
> 
> Some informations about the background of this patch could be found at
> http://lists.freedesktop.org/archives/dbus/2006-December/006737.html
> 
> Any problems with this patch ?
> 
> Ralf
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> Index: dbus/dbus-connection.h
> ===================================================================
> RCS file: /cvs/dbus/dbus/dbus/dbus-connection.h,v
> retrieving revision 1.49
> diff -u -r1.49 dbus-connection.h
> --- dbus/dbus-connection.h	15 Nov 2006 03:07:59 -0000	1.49
> +++ dbus/dbus-connection.h	8 Mar 2007 20:25:40 -0000
> @@ -330,6 +330,9 @@
>   */
>  
>  int          dbus_watch_get_fd      (DBusWatch        *watch);
> +#if defined (DBUS_COMPILATION)
> +int          dbus_watch_get_handle  (DBusWatch        *watch);
> +#endif
>  unsigned int dbus_watch_get_flags   (DBusWatch        *watch);
>  void*        dbus_watch_get_data    (DBusWatch        *watch);
>  void         dbus_watch_set_data    (DBusWatch        *watch,
> Index: dbus/dbus-mainloop.c
> ===================================================================
> RCS file: /cvs/dbus/dbus/dbus/dbus-mainloop.c,v
> retrieving revision 1.19
> diff -u -r1.19 dbus-mainloop.c
> --- dbus/dbus-mainloop.c	20 Oct 2006 03:04:59 -0000	1.19
> +++ dbus/dbus-mainloop.c	8 Mar 2007 20:25:40 -0000
> @@ -598,7 +598,7 @@
>  
>  #if MAINLOOP_SPEW
>                _dbus_verbose ("  skipping watch on fd %d as it was out of memory last time\n",
> -                             dbus_watch_get_fd (wcb->watch));
> +                             dbus_watch_get_handle (wcb->watch));
>  #endif
>              }
>            else if (dbus_watch_get_enabled (wcb->watch))
> @@ -609,7 +609,7 @@
>                    
>                flags = dbus_watch_get_flags (wcb->watch);
>                    
> -              fds[n_fds].fd = dbus_watch_get_fd (wcb->watch);
> +              fds[n_fds].fd = dbus_watch_get_handle (wcb->watch);
>                fds[n_fds].revents = 0;
>                fds[n_fds].events = 0;
>                if (flags & DBUS_WATCH_READABLE)
> @@ -628,7 +628,7 @@
>              {
>  #if MAINLOOP_SPEW
>                _dbus_verbose ("  skipping disabled watch on fd %d  %s\n",
> -                             dbus_watch_get_fd (wcb->watch),
> +                             dbus_watch_get_handle (wcb->watch),
>                               watch_flags_to_string (dbus_watch_get_flags (wcb->watch)));
>  #endif
>              }
> Index: dbus/dbus-server-socket.c
> ===================================================================
> RCS file: /cvs/dbus/dbus/dbus/dbus-server-socket.c,v
> retrieving revision 1.3
> diff -u -r1.3 dbus-server-socket.c
> --- dbus/dbus-server-socket.c	1 Oct 2006 15:36:18 -0000	1.3
> +++ dbus/dbus-server-socket.c	8 Mar 2007 20:25:40 -0000
> @@ -161,7 +161,7 @@
>        int client_fd;
>        int listen_fd;
>        
> -      listen_fd = dbus_watch_get_fd (watch);
> +      listen_fd = dbus_watch_get_handle (watch);
>  
>        client_fd = _dbus_accept (listen_fd);
>        
> Index: dbus/dbus-spawn.c
> ===================================================================
> RCS file: /cvs/dbus/dbus/dbus/dbus-spawn.c,v
> retrieving revision 1.25
> diff -u -r1.25 dbus-spawn.c
> --- dbus/dbus-spawn.c	4 Mar 2007 19:14:03 -0000	1.25
> +++ dbus/dbus-spawn.c	8 Mar 2007 20:25:40 -0000
> @@ -720,7 +720,7 @@
>    if (condition & DBUS_WATCH_HANGUP)
>      revents |= _DBUS_POLLHUP;
>  
> -  fd = dbus_watch_get_fd (watch);
> +  fd = dbus_watch_get_handle (watch);
>  
>    if (fd == sitter->error_pipe_from_child)
>      handle_error_pipe (sitter, revents);
> Index: dbus/dbus-transport.c
> ===================================================================
> RCS file: /cvs/dbus/dbus/dbus/dbus-transport.c,v
> retrieving revision 1.54
> diff -u -r1.54 dbus-transport.c
> --- dbus/dbus-transport.c	17 Oct 2006 20:52:13 -0000	1.54
> +++ dbus/dbus-transport.c	8 Mar 2007 20:25:42 -0000
> @@ -674,7 +676,7 @@
>    if (transport->disconnected)
>      return TRUE;
>  
> -  if (dbus_watch_get_fd (watch) < 0)
> +  if (dbus_watch_get_handle (watch) < 0)
>      {
>        _dbus_warn_check_failed ("Tried to handle an invalidated watch; this watch should have been removed\n");
>        return TRUE;
> Index: dbus/dbus-watch.c
> ===================================================================
> RCS file: /cvs/dbus/dbus/dbus/dbus-watch.c,v
> retrieving revision 1.22
> diff -u -r1.22 dbus-watch.c
> --- dbus/dbus-watch.c	21 Oct 2006 21:57:31 -0000	1.22
> +++ dbus/dbus-watch.c	8 Mar 2007 20:25:42 -0000
> @@ -286,7 +286,7 @@
>              
>              _dbus_verbose ("Adding a %s watch on fd %d using newly-set add watch function\n",
>                             watch_type,
> -                           dbus_watch_get_fd (link->data));
> +                           dbus_watch_get_handle (link->data));
>            }
>  #endif /* DBUS_ENABLE_VERBOSE_MODE */
>            
> @@ -302,7 +302,7 @@
>                                                               link2);
>                    
>                    _dbus_verbose ("Removing watch on fd %d using newly-set remove function because initial add failed\n",
> -                                 dbus_watch_get_fd (link2->data));
> +                                 dbus_watch_get_handle (link2->data));
>                    
>                    (* remove_function) (link2->data, data);
>                    
> @@ -359,7 +359,7 @@
>    if (watch_list->add_watch_function != NULL)
>      {
>        _dbus_verbose ("Adding watch on fd %d\n",
> -                     dbus_watch_get_fd (watch));
> +                     dbus_watch_get_handle (watch));
>        
>        if (!(* watch_list->add_watch_function) (watch,
>                                                 watch_list->watch_data))
> @@ -390,7 +390,7 @@
>    if (watch_list->remove_watch_function != NULL)
>      {
>        _dbus_verbose ("Removing watch on fd %d\n",
> -                     dbus_watch_get_fd (watch));
> +                     dbus_watch_get_handle (watch));
>        
>        (* watch_list->remove_watch_function) (watch,
>                                               watch_list->watch_data);
> @@ -422,7 +422,7 @@
>    if (watch_list->watch_toggled_function != NULL)
>      {
>        _dbus_verbose ("Toggling watch %p on fd %d to %d\n",
> -                     watch, dbus_watch_get_fd (watch), watch->enabled);
> +                     watch, dbus_watch_get_handle (watch), watch->enabled);
>        
>        (* watch_list->watch_toggled_function) (watch,
>                                                watch_list->watch_data);
> @@ -490,10 +490,32 @@
>   * @returns the file descriptor to watch.
>   */
>  int
> +dbus_watch_get_handle (DBusWatch *watch)
> +{
> +  return watch->fd;
> +}
> +
> +#if defined(DBUS_WIN)
> +// never used by the dbus code
> +#include "dbus-sysdeps-win.h"
> +int 
> +dbus_watch_get_fd (DBusWatch *watch)
> +{
> +	DBusSocket *p;
> +	if (watch->fd != -1) {
> +	    _dbus_handle_to_socket(watch->fd,&p);
> +	    return p->fd;
> +	}
> +	else
> +		return -1;
> +}
> +#else
> +int
>  dbus_watch_get_fd (DBusWatch *watch)
>  {
>    return watch->fd;
>  }
> +#endif
>  
>  /**
>   * Gets flags from DBusWatchFlags indicating
> @@ -546,7 +568,7 @@
>                       DBusFreeFunction  free_data_function)
>  {
>    _dbus_verbose ("Setting watch fd %d data to data = %p function = %p from data = %p function = %p\n",
> -                 dbus_watch_get_fd (watch),
> +                 dbus_watch_get_handle (watch),
>                   data, free_data_function, watch->data, watch->free_data_function);
>    
>    if (watch->free_data_function != NULL)
> 

Isn't is better to move the dbus_watch_get_fd function into
sysdeps-win/unix.c?

And there is already a bugzilla entry:
https://bugs.freedesktop.org/show_bug.cgi?id=9334

Therefore I think we should first clean up our socket stuff.
We also plan to replace the sockets by shared memory, so the
current naming isn't generic enough.

Does this mean we have to extent struct DBusWatch and to always
return fd=-1 on Windows?

In dbus-sysdeps-win.c we will have then:

int
dbus_watch_get_fd (DBusWatch *watch)
{
  return -1;
}

and we will have to change dbus-watch.c much more than with the
above patch, maybe a job for Havoc? ;)


Peter


More information about the dbus mailing list