[PATCH v3 11/13] Add keepalive support into domain-events examples

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

 



---
Notes:
    Version 3:
    - update to client API changes (virConnectAllowKeepAlive dropped
      and virConnectStartKeepAlive renamed as virConnectSetKeepAlive)
    
    Version 2:
    - automatically exit when a connection is closed because of
      keepalive timeout

 examples/domain-events/events-c/event-test.c       |    9 ++++++++-
 examples/domain-events/events-python/event-test.py |    4 +++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/examples/domain-events/events-c/event-test.c b/examples/domain-events/events-c/event-test.c
index 6a3ed26..bd9f8c2 100644
--- a/examples/domain-events/events-c/event-test.c
+++ b/examples/domain-events/events-c/event-test.c
@@ -390,7 +390,14 @@ int main(int argc, char **argv)
         (callback5ret != -1) &&
         (callback6ret != -1) &&
         (callback7ret != -1)) {
-        while (run) {
+        if (virConnectSetKeepAlive(dconn, 5, 3) < 0) {
+            virErrorPtr err = virGetLastError();
+            fprintf(stderr, "Failed to start keepalive protocol: %s\n",
+                    err && err->message ? err->message : "Unknown error");
+            run = 0;
+        }
+
+        while (run && virConnectIsAlive(dconn) == 1) {
             if (virEventRunDefaultImpl() < 0) {
                 virErrorPtr err = virGetLastError();
                 fprintf(stderr, "Failed to run event loop: %s\n",
diff --git a/examples/domain-events/events-python/event-test.py b/examples/domain-events/events-python/event-test.py
index 76fda2b..8d218f9 100644
--- a/examples/domain-events/events-python/event-test.py
+++ b/examples/domain-events/events-python/event-test.py
@@ -518,11 +518,13 @@ def main():
     vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_WATCHDOG, myDomainEventWatchdogCallback, None)
     vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_GRAPHICS, myDomainEventGraphicsCallback, None)
 
+    vc.setKeepAlive(5, 3)
+
     # The rest of your app would go here normally, but for sake
     # of demo we'll just go to sleep. The other option is to
     # run the event loop in your main thread if your app is
     # totally event based.
-    while 1:
+    while vc.isAlive() == 1:
         time.sleep(1)
 
 
-- 
1.7.7

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