def Exec.read
bend-kube-runtime@0.2.0.0 · src/exec.bend:264
import bend-kube-runtime@0.2.0.0/src/exec.bend as Exec
import Base
import bend-kube-runtime@0.2.0.0/src/net.bend as N
import bend-kube-runtime@0.2.0.0/src/client.bend as Cl
264
265def Exec.read(fuel: Nat, ev: XEv, +acc: Acc, +ms: U32) -> IO(Socket & Result<&2, &2, Cl.KErr, Out>):
266 match fuel ev:
267 case 0n XGot{s, r}:
268 IO.pure(Socket & Result<&2, &2, Cl.KErr, Out>, (s, Fail{Cl.KNet{0, "exec: output too long"}}))
269 case 0n XChk{s, e, c, b}:
270 IO.pure(Socket & Result<&2, &2, Cl.KErr, Out>, (s, Fail{Cl.KNet{0, "exec: output too long"}}))
271 case 1n+f XGot{s, Done{+bs}}:
272 +next = Acc.feed(acc, bs)
273 Exec.read(f, XChk{s, List.is_empty(&2, U32, bs), Acc.closed(next), Acc.error(next)}, next,
274 ms)
275 case 1n+f XGot{s, Fail{(c, m)}}:
276 IO.pure(Socket & Result<&2, &2, Cl.KErr, Out>, (s, Fail{Cl.KNet{c, "exec: recv: " ++ m}}))
277 case 1n+f XChk{s, e, c, Some{why}}:
278 IO.pure(Socket & Result<&2, &2, Cl.KErr, Out>, (s, Fail{Cl.KNet{0, "exec: " ++ why}}))
279 case 1n+f XChk{s, True{}, c, None{}}:
280 IO.pure(Socket & Result<&2, &2, Cl.KErr, Out>, (s, Done{Acc.out(acc)}))
281 case 1n+f XChk{s, False{}, True{}, None{}}:
282 IO.pure(Socket & Result<&2, &2, Cl.KErr, Out>, (s, Done{Acc.out(acc)}))
283 case 1n+f XChk{s, False{}, False{}, None{}}:
284 IO.bind(Socket & Result<&1, &1, U32 & String, List<&2, U32>>,
285 Socket & Result<&2, &2, Cl.KErr, Out>, N.Tls.recv(s, 65536, ms),
286 p => Exec.read(f, XEv.got(p), acc, ms))