Re: [PATCH glib] Fix event loop implementation on win32

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jan 24, 2014 at 05:04:31PM +0000, Daniel P. Berrange wrote:
> Libvirt uses gnulib for making winsock look like POSIX
> sockets. This means that in the libvirt event handle
> callbacks the application will be given a file descriptor
> rather than a winsock HANDLE object. The g_io_channel_unix_new
> method will detect that it is an FD and delegate to the
> g_io_channel_win32_new_fd method. Unfortunately the glib Win32
> event loop impl is not very good at dealing with FD objects,
> simulating poll() by doing a read() on the FD :-(
> 
> The API docs for g_io_channel_win32_new_fd say
> 
>  "All reads from the file descriptor should be done by
>   this internal GLib thread. Your code should call only
>   g_io_channel_read()."
> 
> This isn't going to fly for libvirt, since it has zero
> knowledge of glib at all, so is just doing normal read().
> 
> Fortunately we can work around this problem by turning
> the FD we get from libvirt back into a HANDLE using the
> _get_osfhandle() method.
> 
> Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
> ---
>  libvirt-glib/libvirt-glib-event.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/libvirt-glib/libvirt-glib-event.c b/libvirt-glib/libvirt-glib-event.c
> index 87019b5..826db2d 100644
> --- a/libvirt-glib/libvirt-glib-event.c
> +++ b/libvirt-glib/libvirt-glib-event.c
> @@ -31,6 +31,10 @@
>  
>  #include "libvirt-glib/libvirt-glib.h"
>  
> +#ifdef G_OS_WIN32
> +#include <io.h>
> +#endif
> +
>  /**
>   * SECTION:libvirt-glib-event
>   * @short_description: Integrate libvirt with the GMain event framework
> @@ -164,7 +168,7 @@ gvir_event_handle_add(int fd,
>      data->events = events;
>      data->cb = cb;
>      data->opaque = opaque;
> -    data->channel = g_io_channel_unix_new(fd);
> +    data->channel = g_io_channel_unix_new(_get_osfhandle(fd));

Doesn't this need to be #ifdef G_OS_WIN32 ?

Christophe

Attachment: pgpEgYXQyjf6C.pgp
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]