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

[libvirt] [PATCH 1/3] Add binding for virConnectSetKeepAlive



This one is a 'one-off' but it ought to be possible to use the generator
to create the function (it has signature 'conn, int, int : int')

Signed-off-by: David Scott <dave scott eu citrix com>
---
 config.h.in                 |    3 +++
 configure.ac                |    1 +
 libvirt/.depend             |   12 ++++++------
 libvirt/libvirt.ml          |    2 ++
 libvirt/libvirt.mli         |    8 ++++++++
 libvirt/libvirt_c_oneoffs.c |   28 ++++++++++++++++++++++++++++
 6 files changed, 48 insertions(+), 6 deletions(-)

diff --git a/config.h.in b/config.h.in
index fccbbe7..72bda13 100644
--- a/config.h.in
+++ b/config.h.in
@@ -30,6 +30,9 @@
 /* Define to 1 if you have the <unistd.h> header file. */
 #undef HAVE_UNISTD_H
 
+/* Define to 1 if you have the 'virConnectSetKeepAlive' function. */
+#undef HAVE_VIRCONNECTSETKEEPALIVE
+
 /* Define to 1 if you have the `virConnectGetHostname' function. */
 #undef HAVE_VIRCONNECTGETHOSTNAME
 
diff --git a/configure.ac b/configure.ac
index 63635b6..9812bf4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -126,6 +126,7 @@ AC_CHECK_FUNCS([virConnectGetHostname \
 		virDomainBlockPeek \
 		virDomainMemoryPeek \
                 virDomainGetCPUStats \
+                virConnectSetKeepAlive \
 ])
 
 dnl Check for optional types added since 0.2.1.
diff --git a/libvirt/.depend b/libvirt/.depend
index 7d32e13..3f2297e 100644
--- a/libvirt/.depend
+++ b/libvirt/.depend
@@ -1,6 +1,6 @@
-libvirt_version.cmi :
-libvirt.cmi :
-libvirt_version.cmo : libvirt_version.cmi
-libvirt_version.cmx : libvirt_version.cmi
-libvirt.cmo : libvirt.cmi
-libvirt.cmx : libvirt.cmi
+libvirt.cmi:
+libvirt_version.cmi:
+libvirt.cmo: libvirt.cmi
+libvirt.cmx: libvirt.cmi
+libvirt_version.cmo: libvirt_version.cmi
+libvirt_version.cmx: libvirt_version.cmi
diff --git a/libvirt/libvirt.ml b/libvirt/libvirt.ml
index 1fbb8ca..784a2b5 100644
--- a/libvirt/libvirt.ml
+++ b/libvirt/libvirt.ml
@@ -100,6 +100,8 @@ struct
   let cpu_usable cpumaps maplen vcpu cpu =
     Char.code cpumaps.[vcpu*maplen + cpu/8] land (1 lsl (cpu mod 8)) <> 0
 
+  external set_keep_alive : [>`R] t -> int -> int -> unit = "ocaml_libvirt_connect_set_keep_alive"
+
   external const : [>`R] t -> ro t = "%identity"
 end
 
diff --git a/libvirt/libvirt.mli b/libvirt/libvirt.mli
index bf95fa2..a106a64 100644
--- a/libvirt/libvirt.mli
+++ b/libvirt/libvirt.mli
@@ -391,6 +391,14 @@ sig
     (** [cpu_usable cpumaps maplen vcpu cpu] checks returns true iff the
 	[cpu] is usable by [vcpu]. *)
 
+  val set_keep_alive : [>`R] t -> int -> int -> unit
+    (** [set_keep_alive conn interval count] starts sending keepalive
+        messages after [interval] seconds of inactivity and consider the
+        connection to be broken when no response is received after [count]
+        keepalive messages.
+        Note: the client has to implement and run an event loop to
+        be able to use keep-alive messages. *)
+
   external const : [>`R] t -> ro t = "%identity"
     (** [const conn] turns a read/write connection into a read-only
 	connection.  Note that the opposite operation is impossible.
diff --git a/libvirt/libvirt_c_oneoffs.c b/libvirt/libvirt_c_oneoffs.c
index 70cf96f..7506ab0 100644
--- a/libvirt/libvirt_c_oneoffs.c
+++ b/libvirt/libvirt_c_oneoffs.c
@@ -194,6 +194,34 @@ ocaml_libvirt_connect_node_get_cells_free_memory (value connv,
 #endif
 }
 
+#ifdef HAVE_WEAK_SYMBOLS
+#ifdef HAVE_VIRCONNECTSETKEEPALIVE
+extern int virConnectSetKeepAlive (virConnectPtr conn, int interval, unsigned int count)
+  __attribute__((weak));
+#endif
+#endif
+
+CAMLprim value
+ocaml_libvirt_connect_set_keep_alive(value connv,
+				     value intervalv, value countv)
+{
+#ifdef HAVE_VIRCONNECTSETKEEPALIVE
+  CAMLparam3 (connv, intervalv, countv);
+  virConnectPtr conn = Connect_val(connv);
+  int interval = Int_val(intervalv);
+  unsigned int count = Int_val(countv);
+  int r;
+
+  NONBLOCKING(r = virConnectSetKeepAlive(conn, interval, count));
+  CHECK_ERROR (r == -1, conn, "virConnectSetKeepAlive");
+
+  CAMLreturn(Val_unit);
+#else
+  not_supported ("virConnectSetKeepAlive");
+#endif
+}
+
+
 CAMLprim value
 ocaml_libvirt_domain_get_id (value domv)
 {
-- 
1.7.10.4


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