udp: Fold buffer handoff into ListenOut

This commit is contained in:
JackDoan committed 2026-10-15 17:02:42 -05:00
1 parent 1fb77bdda5
commit 06035252b2
12 files changed
+45 -60

No files matched your search

+5 -13
View File
@@ -182,22 +182,14 @@ func (u *TesterConn) WriteBatch(bufs [][]byte, addrs []netip.AddrPort) (int, err
return written, nil
}
func (u *TesterConn) ListenOut(r EncReader, flush func()) error {
// The batcher borrows plaintext decrypted in place inside p.Data
// until Flush, so the packet must stay alive across flush()
return u.ListenOutHandoff(r, func(bufs [][]byte) [][]byte {
flush()
return bufs
})
}
// HandoffShape is one buffer per handoff; the pool resizes the replacements it gets back as it needs.
func (u *TesterConn) HandoffShape() (n, size int) { return 1, MTU }
// ListenOutHandoff hands each packet's buffer over as a batch of one, the buffer it gets back goes to the pool. Like
// StdConn it carries on with the slice handoff returns, since a reader that keeps the packets keeps the one it was
// given.
func (u *TesterConn) ListenOutHandoff(r EncReader, handoff func(bufs [][]byte) [][]byte) error {
// ListenOut hands each packet's buffer over as a batch of one, the buffer it gets back goes to the pool. Like StdConn
// it carries on with the slice handoff returns, since a reader that keeps the packets keeps the one it was given.
// The batcher borrows plaintext decrypted in place inside p.Data until it flushes, inside handoff, so the packet
// must stay alive until handoff returns.
func (u *TesterConn) ListenOut(r EncReader, handoff func(bufs [][]byte) [][]byte) error {
bufs := make([][]byte, 1)
for {
select {