Something went wrong. Try again.
Shells in OCaml
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768(* Some random utils for debugging *)open Eio.Std
let traced_sink tag (Eio.Resource.T (t, handler) : Eio_unix.sink_ty Eio.Flow.sink) : Eio_unix.sink_ty r = let module Sink = (val Eio.Resource.get handler Eio.Flow.Pi.Sink) in let close = Eio.Resource.get handler Eio.Resource.Close in let buf = Cstruct.create 4096 in let copy () ~src = try while true do match Eio.Flow.single_read src buf with | i -> Eio.traceln ">>>>> %s Single read: %s" tag (Cstruct.to_string buf); let bufs = [ Cstruct.sub buf 0 i ] in Sink.copy ~src:(Eio.Flow.cstruct_source bufs) t done with End_of_file -> Eio.traceln ">>>>>> EOF" in let single_write () x = Eio.traceln ">>>>> single write: %s" (Cstruct.concat x |> Cstruct.to_string); Sink.single_write t x in let module T = struct type t = unit
let single_write = single_write let copy = copy end in let t = Eio.Resource.handler [ H (Eio.Flow.Pi.Sink, (module T)); H (Eio.Resource.Close, fun () -> close t); ] in Eio.Resource.T ((), t)
let traced_sink_flow tag (Eio.Resource.T (t, handler) : Eio.Flow.sink_ty Eio.Flow.sink) : Eio.Flow.sink_ty r = let module Sink = (val Eio.Resource.get handler Eio.Flow.Pi.Sink) in let buf = Cstruct.create 4096 in let copy () ~src = try while true do match Eio.Flow.single_read src buf with | i -> Eio.traceln ">>>>> %s Single read: %s" tag (Cstruct.to_string buf); let bufs = [ Cstruct.sub buf 0 i ] in Sink.copy ~src:(Eio.Flow.cstruct_source bufs) t done with End_of_file -> Eio.traceln ">>>>>> EOF" in let single_write () x = Eio.traceln ">>>>> single write: %s" (Cstruct.concat x |> Cstruct.to_string); Sink.single_write t x in let module T = struct type t = unit
let single_write = single_write let copy = copy end in let t = Eio.Resource.handler [ H (Eio.Flow.Pi.Sink, (module T)) ] in Eio.Resource.T ((), t)