summaryrefslogtreecommitdiff
path: root/src/vyconf_client.ml
diff options
context:
space:
mode:
Diffstat (limited to 'src/vyconf_client.ml')
-rw-r--r--src/vyconf_client.ml41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/vyconf_client.ml b/src/vyconf_client.ml
new file mode 100644
index 0000000..7db59ff
--- /dev/null
+++ b/src/vyconf_client.ml
@@ -0,0 +1,41 @@
+include Vyconf_pb
+
+type t = {
+ sock: Lwt_unix.file_descr;
+ ic: Lwt_io.input Lwt_io.channel;
+ oc: Lwt_io.output Lwt_io.channel;
+ enc: Pbrt.Encoder.t;
+ session: string option;
+ conf_mode: bool;
+ closed: bool
+}
+
+let create sockfile =
+ let open Lwt_unix in
+ let sock = socket PF_UNIX SOCK_STREAM 0 in
+ let%lwt () = connect sock (ADDR_UNIX sockfile) in
+ let ic = Lwt_io.of_fd Lwt_io.Input sock in
+ let oc = Lwt_io.of_fd Lwt_io.Output sock in
+ Lwt.return {
+ sock=sock; ic=ic; oc=oc;
+ enc=(Pbrt.Encoder.create ()); closed=false;
+ session=None; conf_mode=false
+ }
+
+let shutdown client =
+ let%lwt () = Lwt_unix.close client.sock in
+ Lwt.return {client with closed=true}
+
+let do_request client req =
+ let enc = Pbrt.Encoder.create () in
+ let () = encode_request req enc in
+ let msg = Pbrt.Encoder.to_bytes enc in
+ let%lwt () = Message.write client.oc msg in
+ let%lwt resp = Message.read client.ic in
+ decode_response (Pbrt.Decoder.of_bytes resp) |> Lwt.return
+
+
+let get_status client =
+ let req = Status in
+ let%lwt resp = do_request client req in
+ Lwt.return resp