diff --git a/syndicate/drivers/tcp.rkt b/syndicate/drivers/tcp.rkt index a2a6399..b796e3c 100644 --- a/syndicate/drivers/tcp.rkt +++ b/syndicate/drivers/tcp.rkt @@ -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 diff --git a/syndicate/schemas/tcp.prs b/syndicate/schemas/tcp.prs index 02714a0..9239133 100644 --- a/syndicate/schemas/tcp.prs +++ b/syndicate/schemas/tcp.prs @@ -21,5 +21,5 @@ Socket = CreditAmount = @count int / @unbounded =unbounded . -Mode = =bytes / @lines LineMode . +Mode = =bytes / @lines LineMode / . LineMode = =lf / =crlf .