--- plugins/ocaml/NBDKit.mli | 7 +++++++ plugins/ocaml/NBDKit.ml | 4 ++++ plugins/ocaml/bindings.c | 24 ++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/plugins/ocaml/NBDKit.mli b/plugins/ocaml/NBDKit.mli index ececd5fd..8abfeb49 100644 --- a/plugins/ocaml/NBDKit.mli +++ b/plugins/ocaml/NBDKit.mli @@ -162,3 +162,10 @@ val shutdown : unit -> unit (** Print a debug message when nbdkit is in verbose mode. *) val debug : ('a, unit, string, unit) format4 -> 'a + +(** Binding for [nbdkit_peer_pid]. *) +val peer_pid : unit -> int +(** Binding for [nbdkit_peer_uid]. *) +val peer_uid : unit -> int +(** Binding for [nbdkit_peer_gid]. *) +val peer_gid : unit -> int diff --git a/plugins/ocaml/NBDKit.ml b/plugins/ocaml/NBDKit.ml index 739210fa..76fa3a77 100644 --- a/plugins/ocaml/NBDKit.ml +++ b/plugins/ocaml/NBDKit.ml @@ -257,3 +257,7 @@ external _debug : string -> unit = "ocaml_nbdkit_debug" "noalloc" let debug fs = ksprintf _debug fs + +external peer_pid : unit -> int = "ocaml_nbdkit_peer_pid" +external peer_uid : unit -> int = "ocaml_nbdkit_peer_uid" +external peer_gid : unit -> int = "ocaml_nbdkit_peer_gid" diff --git a/plugins/ocaml/bindings.c b/plugins/ocaml/bindings.c index 6c92cd3e..d231ec89 100644 --- a/plugins/ocaml/bindings.c +++ b/plugins/ocaml/bindings.c @@ -190,3 +190,27 @@ ocaml_nbdkit_debug (value strv) return Val_unit; } + +value +ocaml_nbdkit_peer_pid (value unitv) +{ + int id = nbdkit_peer_pid (); + if (id == -1) caml_failwith ("nbdkit_peer_pid"); + return Val_int (id); +} + +value +ocaml_nbdkit_peer_uid (value unitv) +{ + int id = nbdkit_peer_uid (); + if (id == -1) caml_failwith ("nbdkit_peer_uid"); + return Val_int (id); +} + +value +ocaml_nbdkit_peer_gid (value unitv) +{ + int id = nbdkit_peer_gid (); + if (id == -1) caml_failwith ("nbdkit_peer_gid"); + return Val_int (id); +} -- 2.27.0