batch.go 1.0 KB

12345678910111213141516171819202122232425262728
  1. package batch
  2. import "net/netip"
  3. type RxBatcher interface {
  4. // Reserve creates a pkt to borrow
  5. Reserve(sz int) []byte
  6. // Commit borrows pkt. The caller must keep pkt valid until the next Flush
  7. Commit(pkt []byte) error
  8. // Flush emits every queued packet in arrival order. Returns the
  9. // first error observed; keeps draining so one bad packet doesn't hold up
  10. // the rest. After Flush returns, borrowed payload slices may be recycled.
  11. Flush() error
  12. }
  13. type TxBatcher interface {
  14. // Reserve creates a pkt to borrow
  15. Reserve(sz int) []byte
  16. // Commit borrows pkt and records its destination plus the 2-bit
  17. // IP-level ECN codepoint to set on the outer (carrier) header. The
  18. // caller must keep pkt valid until the next Flush. Pass 0 (Not-ECT)
  19. // to leave the outer ECN field unset.
  20. Commit(pkt []byte, dst netip.AddrPort, outerECN byte)
  21. // Flush emits every queued packet via the underlying batch writer in
  22. // arrival order. Returns the first error observed. After Flush returns,
  23. // borrowed payload slices may be recycled.
  24. Flush() error
  25. }