From cbc0ad960d2f0b1411382f939ece6f5fec3499c5 Mon Sep 17 00:00:00 2001 From: Calascibetta Romain Date: Sun, 19 Jan 2025 17:54:47 +0100 Subject: [PATCH] Fix main.ml --- main.ml | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/main.ml b/main.ml index 6043d44..cbcb39d 100644 --- a/main.ml +++ b/main.ml @@ -1,18 +1,16 @@ -#require "miou.unix" - -#require "mirage-crypto-rng-miou-unix" - -#require "vif" - -#require "digestif.c" - -#require "base64" +#require "miou.unix" ;; +#require "mirage-crypto-rng-miou-unix" ;; +#require "vif" ;; +#require "digestif.c" ;; +#require "base64" ;; let index server _req () = Vif.Response.with_string server `OK "Hello from an OCaml script!" +;; let test arg server _req () = Vif.Response.with_string server `OK (Fmt.str "%02x\n%!" arg) +;; let digest server req () = let ic = Vif.Request.to_stream req in @@ -24,6 +22,7 @@ let digest server req () = let hash = go Digestif.SHA1.empty in let hash = Digestif.SHA1.to_hex hash in Vif.Response.with_string server `OK hash +;; let random len server req () = let buf = Bytes.create 0x7ff in @@ -40,24 +39,30 @@ let random len server req () = end in go len +;; let routes = let open Vif.U in let open Vif.R in [ - (rel /?? nil) --> index; (rel / "random" /% Tyre.int /?? nil) --> random + (rel /?? nil) --> index + ; (rel / "random" /% Tyre.int /?? nil) --> random ; (rel / "test" /% Tyre.int /?? nil) --> test ; (rel / "digest" /?? nil) --> digest ] +;; let default target server req () = Vif.Response.with_string server `Not_found (Fmt.str "%S not found\n%!" target) +;; let my_device_as_arg, my_device = Vif.D.device ~name:"my-device" ~finally:ignore [] () +;; let () = Miou_unix.run @@ fun () -> let sockaddr = Unix.(ADDR_INET (inet_addr_loopback, 8080)) in let cfg = Vif.config sockaddr in Vif.run ~cfg ~default ~devices:Vif.[ D.rng; my_device_as_arg ] routes () +;;