def Exec.head

bend-kube-runtime@0.2.0.0 · src/exec.bend:136

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

136# Reads until the head is whole.
137def Exec.head(fuel: Nat, ev: HEv, +sc: Scan, +ms: U32) ->
138  IO(Socket & Result<&2, &2, Cl.KErr, Scan>):
139  match fuel ev:
140    case 0n HGot{s, r}:
141      IO.pure(Socket & Result<&2, &2, Cl.KErr, Scan>, (s, Fail{Cl.KNet{0, "exec: head too long"}}))
142    case 0n HChk{s, f, e}:
143      IO.pure(Socket & Result<&2, &2, Cl.KErr, Scan>, (s, Fail{Cl.KNet{0, "exec: head too long"}}))
144    case 1n+f HGot{s, Done{+bs}}:
145      +next = Scan.feed(sc, bs)
146      Exec.head(f, HChk{s, Scan.found(next), List.is_empty(&2, U32, bs)}, next, ms)
147    case 1n+f HGot{s, Fail{(c, m)}}:
148      IO.pure(Socket & Result<&2, &2, Cl.KErr, Scan>, (s, Fail{Cl.KNet{c, "exec: recv: " ++ m}}))
149    case 1n+f HChk{s, True{}, e}:
150      IO.pure(Socket & Result<&2, &2, Cl.KErr, Scan>, (s, Done{sc}))
151    case 1n+f HChk{s, False{}, True{}}:
152      IO.pure(Socket & Result<&2, &2, Cl.KErr, Scan>,
153        (s, Fail{Cl.KNet{0, "exec: connection closed before the upgrade"}}))
154    case 1n+f HChk{s, False{}, False{}}:
155      IO.bind(Socket & Result<&1, &1, U32 & String, List<&2, U32>>,
156        Socket & Result<&2, &2, Cl.KErr, Scan>, N.Tls.recv(s, 65536, ms),
157        p => Exec.head(f, HEv.got(p), sc, ms))

Uses (21)

Used by (1)