txqueue work

This commit is contained in:
soypat
2025-01-13 19:36:17 -03:00
parent 9abf0c11b9
commit 0a75ef4670
4 changed files with 56 additions and 9 deletions
+35
View File
@@ -0,0 +1,35 @@
package tcp
import (
"bytes"
"testing"
)
func TestTxQueueWrite(t *testing.T) {
const (
bufsize = 1024
maxPkt = 3
msg = "hello world"
)
buf := make([]byte, bufsize)
rtx := newRingTx(buf, maxPkt)
bufs := bytes.SplitAfter([]byte(msg), []byte("e"))
var data [bufsize]byte
for i, buf := range bufs {
n, err := rtx.Write(buf)
if err != nil {
t.Fatalf("writing packet %d: %s", i, err)
} else if n != len(buf) {
t.Fatalf("want %d written, got %d", len(buf), n)
}
n, err = rtx.MakePacket(data[:])
if err != nil {
t.Fatalf("making packet %d: %s", i, err)
} else if n != len(buf) {
t.Fatalf("want %d packet read, got %d", len(buf), n)
} else if !bytes.Equal(buf, data[:n]) {
t.Fatalf("want data %q, got data read %q", buf, data[:n])
}
}
}