]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Add keepalive support into domain-events examples
authorJiri Denemark <jdenemar@redhat.com>
Fri, 16 Sep 2011 09:04:22 +0000 (11:04 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Thu, 24 Nov 2011 11:00:10 +0000 (12:00 +0100)
examples/domain-events/events-c/event-test.c
examples/domain-events/events-python/event-test.py

index 7c9922265a29b55dcc29b2adc08242ec7e14fdd2..af1f47d09ae0a1ea386b072a835a42267572e8ef 100644 (file)
@@ -416,7 +416,14 @@ int main(int argc, char **argv)
         (callback6ret != -1) &&
         (callback7ret != -1) &&
         (callback9ret != -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",
index 9628f6e4ad8639bb8799baf0659a3ee03999d469..60a9c34b5e7f9eda6ca160c2b4623c630158d233 100644 (file)
@@ -531,11 +531,13 @@ def main():
     vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_GRAPHICS, myDomainEventGraphicsCallback, None)
     vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_DISK_CHANGE, myDomainEventDiskChangeCallback, 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)