checkpt, try to parse packets only once

This commit is contained in:
JackDoan
2026-05-07 11:04:16 -05:00
parent 6cb00c613c
commit 0375aff451
5 changed files with 37 additions and 9 deletions

View File

@@ -5,8 +5,15 @@ import "net/netip"
type RxBatcher interface {
// Reserve creates a pkt to borrow
Reserve(sz int) []byte
// Commit borrows pkt. The caller must keep pkt valid until the next Flush
// Commit borrows pkt. The caller must keep pkt valid until the next Flush.
// Walks IP+L4 headers itself; prefer CommitInbound when the caller already
// has an RxParsed in hand from ParseInbound.
Commit(pkt []byte) error
// CommitInbound is Commit with a hint produced by ParseInbound, so the
// batcher can skip the IP+L4 re-parse. Borrowed slice contract is the
// same as Commit. Implementations that don't coalesce may delegate to
// Commit.
CommitInbound(pkt []byte, parsed *RxParsed) error
// Flush emits every queued packet in arrival order. Returns the
// first error observed; keeps draining so one bad packet doesn't hold up
// the rest. After Flush returns, borrowed payload slices may be recycled.

View File

@@ -40,6 +40,13 @@ func (p *Passthrough) Commit(pkt []byte) error {
return nil
}
// CommitInbound ignores the hint — Passthrough never coalesces, so there's
// no IP/L4 re-parse to skip. Present so Passthrough satisfies the RxBatcher
// interface alongside MultiCoalescer.
func (p *Passthrough) CommitInbound(pkt []byte, _ *RxParsed) error {
return p.Commit(pkt)
}
func (p *Passthrough) Flush() error {
var firstErr error
for _, s := range p.slots {