[libvirt-glib 1/3] glib: Don't create glib IO watch for disabled handles

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

 



It's possible to create a handle to watch for file events which do not
watch for any file event. Such a handle can be enabled later with
gvir_event_handle_update() by setting some conditions to watch for.

When a handle is disabled after it has been created,
gvir_event_handle_update() makes sure it removes the corresponding
gvir_event_handle::source IO watch if any was set.
gvir_event_handle_add() will always create a gvir_event_handle::source
IO watch even if the handle is not watching for any events.

This commit makes consistent by only creating a watch with g_io_add_watch()
when the caller asked to watch for some events.
---
 libvirt-glib/libvirt-glib-event.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libvirt-glib/libvirt-glib-event.c b/libvirt-glib/libvirt-glib-event.c
index 1e1ffec..67144fa 100644
--- a/libvirt-glib/libvirt-glib-event.c
+++ b/libvirt-glib/libvirt-glib-event.c
@@ -177,10 +177,12 @@ gvir_event_handle_add(int fd,
 
     g_debug("Add handle %p %d %d %d %p\n", data, data->watch, data->fd, events, data->opaque);
 
-    data->source = g_io_add_watch(data->channel,
-                                  cond,
-                                  gvir_event_handle_dispatch,
-                                  data);
+    if (events != 0) {
+        data->source = g_io_add_watch(data->channel,
+                                      cond,
+                                      gvir_event_handle_dispatch,
+                                      data);
+    }
 
     g_ptr_array_add(handles, data);
 
-- 
1.8.5.3

--
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]