def Conn.read

bend-kube-runtime@0.2.0.0 · src/client.bend:299

import bend-kube-runtime@0.2.0.0/src/client.bend as Client
import Base
import bend-kube-runtime@0.2.0.0/src/http.bend as H
import bend-kube-runtime@0.2.0.0/src/net.bend as N

299# Reads until the response is whole, the stream ends, or fuel runs out;
300# ms bounds each recv. Answers the socket and the decoder.
301def Conn.read(fuel: Nat, ev: ReadEv, +resp: H.Resp, +ms: U32) -> IO(Socket & H.Resp):
302  match fuel ev:
303    case 0n RGot{s, r}:
304      IO.pure(Socket & H.Resp, (s, Http.fail("response too long")))
305    case 0n RChk{s, d, e, b}:
306      IO.pure(Socket & H.Resp, (s, Http.fail("response too long")))
307    case 1n+f RGot{s, Done{+bs}}:
308      +next = H.Http.feed(bs, resp)
309      Conn.read(f, RChk{s, H.Http.is_done(next), List.is_empty(&2, U32, bs), Http.has_err(next)},
310        next, ms)
311    case 1n+f RGot{s, Fail{(c, m)}}:
312      IO.pure(Socket & H.Resp, (s, Http.lost(resp, "recv: " ++ m)))
313    case 1n+f RChk{s, True{}, e, b}:
314      IO.pure(Socket & H.Resp, (s, resp))
315    case 1n+f RChk{s, False{}, True{}, b}:
316      IO.pure(Socket & H.Resp, (s, H.Http.eof(resp)))
317    case 1n+f RChk{s, False{}, False{}, True{}}:
318      IO.pure(Socket & H.Resp, (s, resp))
319    case 1n+f RChk{s, False{}, False{}, False{}}:
320      IO.bind(Socket & Res(List<&2, U32>), Socket & H.Resp, N.Tls.recv(s, 65536, ms),
321        p => Conn.read(f, ReadEv.got(p), resp, ms))

Uses (24)

Used by (2)