def reply.drain

bend-kit-http@0.38.5.0 · http.bend:5587

import bend-kit-http@0.38.5.0/http.bend as Http
import Base
import bend-kit-wire@0.4.8.0/wire.bend as Wire
import bend-kit-time@0.3.0.0/time.bend as Time

5587# ponytail: cap drain at 32 MiB and 2.55 s; use socket half-close if larger peers need guaranteed delivery.
5588def reply.drain(n: Nat, alive: Bool, +until: Time.Duration, st: Socket & Bool) -> IO(Unit):
5589  match n:
5590    case 0n:
5591      (s, more) = st
5592      Socket.close(s)
5593    case 1n+p:
5594      match alive:
5595        case False{}:
5596          (s, more) = st
5597          Socket.close(s)
5598        case True{}:
5599          (s, more) = st
5600          match more:
5601            case False{}:
5602              Socket.close(s)
5603            case True{}:
5604              do IO<Unit>:
5605                got : Socket & Result<&1, &1, U32 & String, U32 & Array<U32>> <- Wire.recv.words(s, 65536, 50)
5606                now : Time.Duration <- Time.mono()
5607                reply.drain(p, Cmp.is_lt(Time.Duration.cmp(now, until)), until, reply.drain.of(got))

Uses (19)

Used by (1)