def conn_pump
cswap-bend-cli@0.1.0.0 · server.bend:146
import cswap-bend-cli@0.1.0.0/server.bend as Server
import Base
import cswap-bend-cli@0.1.0.0/frame.bend as Fr
import cswap-bend-cli@0.1.0.0/rpc.bend as Rpc
import cswap-bend-cli@0.1.0.0/fmt/out.bend as O
146@unsafe def conn_pump(p: CP, +fmt: O.Fmt) -> IO(Unit):
147 match p:
148 case CRecv{s, buf}:
149 IO.bind(Socket & Result<&1, &1, U32 & String, Maybe<&1, String>>, Unit, TCP.recv(s, chunk()), r => conn_pump(after_recv(r, buf), fmt))
150 case CFrames{s, +buf}:
151 conn_pump(c_cut(Fr.take(Rpc.is_block(fmt), buf), s, buf), fmt)
152 case CHandle{s, msg, rest}:
153 IO.bind(String, Unit, Rpc.handle(fmt, msg), resp => conn_pump(CReply{s, resp, rest}, fmt))
154 case CReply{s, +resp, rest}:
155 conn_pump(c_reply(String.is_empty(resp), s, resp, rest), fmt)
156 case CSend{s, resp, rest}:
157 IO.bind(Socket & Result<&1, &1, (U32 & String) & List<&2, U32>, Unit>, Unit, TCP.send(s, resp), r => conn_pump(after_send(r, rest), fmt))
158 case CTail{s, +buf}:
159 conn_pump(c_tail(Fr.blank(buf), s, buf), fmt)
160 case CClose{s}:
161 Socket.close(s)