def reply.drain

bend-kit-http@0.38.4.0 · http.bend:5595

import bend-kit-http@0.38.4.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

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

Uses (19)

Used by (1)