Use flow control to avoid being spammed by fast talkers

This commit is contained in:
Tony Garnock-Jones 2020-06-10 13:38:26 +02:00
parent 55f01cea3f
commit 3030d1959e
1 changed files with 2 additions and 1 deletions

View File

@ -14,9 +14,10 @@
(assert (tcp-accepted id))
(assert (server-poa id))
(stop-when (retracted (server-poa-ready id)))
(on-start (issue-unbounded-credit! tcp-in id))
(on-start (issue-credit! #:amount 32768 tcp-in id))
(define accumulate! (packet-accumulator (lambda (p) (send! (message-poa->server id p)))))
(on (message (tcp-in id $bs))
(issue-credit! #:amount (bytes-length bs) tcp-in id)
(accumulate! bs))
(on (message (message-server->poa id $p))
(send! (tcp-out id (encode p)))