Whole-packet flow credit

This commit is contained in:
Tony Garnock-Jones 2021-06-15 12:46:09 +02:00
parent b64b111a45
commit 9451f9886f
2 changed files with 20 additions and 1 deletions

View File

@ -10,6 +10,7 @@
send-credit
send-lines-credit
send-bytes-credit
send-packet-credit
send-line
send-data
send-eof)
@ -162,6 +163,21 @@
(turn! facet (lambda () (send-data (target-proc) bs)))
(loop (update-count (- count read-count) mode q))]
[(? eof-object?) (eof-and-finish)]))]
[(list (cons count (and mode (Mode-packet packet-size))) q)
(handle-evt (read-bytes-evt packet-size i)
(match-lambda
[(? bytes? packet) #:when (< (bytes-length packet) packet-size)
(log-syndicate/drivers/tcp-debug
"short inbound packet (length ~a; expected ~a bytes) ~v for ~v"
(bytes-length packet) packet-size packet name)
(eof-and-finish)]
[(? bytes? packet)
(log-syndicate/drivers/tcp-debug
"inbound packet (length ~a) ~v for ~v"
(bytes-length packet) packet name)
(turn! facet (lambda () (send-data (target-proc) packet mode)))
(loop (update-count (- count 1) mode q))]
[(? eof-object?) (eof-and-finish)]))]
[(list (cons count (and mode (Mode-lines line-mode))) q)
(handle-evt (read-bytes-line-evt i (match line-mode
[(LineMode-lf) 'linefeed]
@ -264,6 +280,9 @@
(define (send-bytes-credit conn amount)
(send-credit conn (CreditAmount-count amount) (Mode-bytes)))
(define (send-packet-credit conn packet-size #:count [count 1])
(send-credit conn (CreditAmount-count count) (Mode-packet packet-size)))
(define (->bytes data)
(if (bytes? data)
data

View File

@ -21,5 +21,5 @@ Socket =
CreditAmount = @count int / @unbounded =unbounded .
Mode = =bytes / @lines LineMode .
Mode = =bytes / @lines LineMode / <packet @size int>.
LineMode = =lf / =crlf .