···13 val select : ('a, 'b) Either.t t -> ('a -> 'b) t -> 'b t
14end
1516-17module T (A : Applicative) = struct
18-19 let do_thing (a : _ A.t) (v : _ A.t) =
20- let v1 = A.mbind (fun i -> if Random.int i < 5 then A.mbind (fun v -> A.return @@ v ^ "hello") v else A.return "world") a in
21- let v2 = A.fmap (fun i -> if Random.int i < 5 then "hello" else "world") a in
22- v1, v2
0000000023end
2425module Make (S : Selective) = struct
···84 | Singleton v -> [ v ]
85 | Cons (x, xs) -> x :: to_list xs
8687- let stdout _ = ""
8889 let build steps =
90 Select.apply
···13 val select : ('a, 'b) Either.t t -> ('a -> 'b) t -> 'b t
14end
15016module T (A : Applicative) = struct
017 let do_thing (a : _ A.t) (v : _ A.t) =
18+ let v1 =
19+ A.mbind
20+ (fun i ->
21+ if Random.int i < 5 then A.mbind (fun v -> A.return @@ v ^ "hello") v
22+ else A.return "world")
23+ a
24+ in
25+ let v2 =
26+ A.fmap (fun i -> if Random.int i < 5 then "hello" else "world") a
27+ in
28+ (v1, v2)
29end
3031module Make (S : Selective) = struct
···90 | Singleton v -> [ v ]
91 | Cons (x, xs) -> x :: to_list xs
9293+ let stdout _ = ""
9495 let build steps =
96 Select.apply
+12-6
src/lib/shelter/runc.ml
···151 ( "process",
152 `Assoc
153 [
154- ("terminal", `Bool false);
155 ("user", user);
156 ("args", strings argv);
157 ("env", strings env);
···274let to_other_sink_as_well ~other
275 (Eio.Resource.T (t, handler) : Eio.Flow.sink_ty Eio.Flow.sink) =
276 let module Sink = (val Eio.Resource.get handler Eio.Flow.Pi.Sink) in
277- let copy_buf = Buffer.create 128 in
278 let copy () ~src =
279- Eio.Flow.copy src (Eio.Flow.buffer_sink copy_buf);
280- Eio.Flow.copy_string (Buffer.contents copy_buf) other;
281- Sink.copy t ~src:(Buffer.contents copy_buf |> Eio.Flow.string_source);
282- Buffer.clear copy_buf
000000283 in
284 let single_write () x =
285 let _ : int = Eio.Flow.single_write other x in
···151 ( "process",
152 `Assoc
153 [
154+ ("terminal", `Bool true);
155 ("user", user);
156 ("args", strings argv);
157 ("env", strings env);
···274let to_other_sink_as_well ~other
275 (Eio.Resource.T (t, handler) : Eio.Flow.sink_ty Eio.Flow.sink) =
276 let module Sink = (val Eio.Resource.get handler Eio.Flow.Pi.Sink) in
277+ let buf = Cstruct.create 4096 in
278 let copy () ~src =
279+ try
280+ while true do
281+ match Eio.Flow.single_read src buf with
282+ | i ->
283+ let bufs = [ Cstruct.sub buf 0 i ] in
284+ Eio.Fiber.both
285+ (fun () -> Eio.Flow.write other bufs)
286+ (fun () -> Sink.copy ~src:(Eio.Flow.cstruct_source bufs) t)
287+ done
288+ with End_of_file -> ()
289 in
290 let single_write () x =
291 let _ : int = Eio.Flow.single_write other x in
+34
src/lib/shelter/shelter_main.ml
···321 in
322 `Runc (Runc.spawn ~sw log env config rootfs)
323 in
000000000000000000000000000000324 let start, res =
325 Switch.run @@ fun sw ->
326 let log =
···333 | `Runc r -> (start, Eio.Process.await r)
334 | `Void v -> (start, Void.to_eio_status (Eio.Promise.await v))
335 in
0000336 let stop = Mtime_clock.now () in
337 let span = Mtime.span start stop in
338 let time = Mtime.Span.to_uint64_ns span in
···321 in
322 `Runc (Runc.spawn ~sw log env config rootfs)
323 in
324+ let savedTio = Unix.tcgetattr Unix.stdin in
325+ let tio =
326+ {
327+ savedTio with
328+ (* input modes *)
329+ c_ignpar = true;
330+ c_istrip = false;
331+ c_inlcr = false;
332+ c_igncr = false;
333+ c_ixon = false;
334+ (* c_ixany = false; *)
335+ (* c_iuclc = false; *)
336+ c_ixoff = false;
337+ (* output modes *)
338+ c_opost = false;
339+ (* control modes *)
340+ c_isig = false;
341+ c_icanon = false;
342+ c_echo = false;
343+ c_echoe = false;
344+ c_echok = false;
345+ c_echonl = false;
346+ (* c_iexten = false; *)
347+348+ (* special characters *)
349+ c_vmin = 1;
350+ c_vtime = 0;
351+ }
352+ in
353+ Unix.tcsetattr Unix.stdin TCSADRAIN tio;
354 let start, res =
355 Switch.run @@ fun sw ->
356 let log =
···363 | `Runc r -> (start, Eio.Process.await r)
364 | `Void v -> (start, Void.to_eio_status (Eio.Promise.await v))
365 in
366+367+ (* restore tio *)
368+ Unix.tcsetattr Unix.stdin TCSADRAIN savedTio;
369+370 let stop = Mtime_clock.now () in
371 let span = Mtime.span start stop in
372 let time = Mtime.Span.to_uint64_ns span in