mirror of
https://github.com/soypat/lneto.git
synced 2026-08-22 23:49:08 +00:00
found failing case for multipacket
This commit is contained in:
@@ -69,6 +69,8 @@ func (conn *Conn) State() State { return conn.h.State() }
|
|||||||
// and available to read via a [Conn.Read] call.
|
// and available to read via a [Conn.Read] call.
|
||||||
func (conn *Conn) BufferedInput() int { return conn.h.BufferedInput() }
|
func (conn *Conn) BufferedInput() int { return conn.h.BufferedInput() }
|
||||||
|
|
||||||
|
func (conn *Conn) AvailableInput() int { return conn.h.FreeRx() }
|
||||||
|
|
||||||
// AvailableOutput returns amount of bytes available to write to output
|
// AvailableOutput returns amount of bytes available to write to output
|
||||||
// before [Conn.Write] returns an error due to insufficient space to store outgoing data.
|
// before [Conn.Write] returns an error due to insufficient space to store outgoing data.
|
||||||
func (conn *Conn) AvailableOutput() int { return conn.h.AvailableOutput() }
|
func (conn *Conn) AvailableOutput() int { return conn.h.AvailableOutput() }
|
||||||
|
|||||||
@@ -290,6 +290,11 @@ func (h *Handler) FreeTx() int {
|
|||||||
return h.bufTx.Free()
|
return h.bufTx.Free()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FreeRx returns the amount of space free in the receive buffer.
|
||||||
|
func (h *Handler) FreeRx() int {
|
||||||
|
return h.bufRx.Free()
|
||||||
|
}
|
||||||
|
|
||||||
// SizeRx returns the size of the TCP receive ring buffer.
|
// SizeRx returns the size of the TCP receive ring buffer.
|
||||||
func (h *Handler) SizeRx() int {
|
func (h *Handler) SizeRx() int {
|
||||||
return h.bufRx.Size()
|
return h.bufRx.Size()
|
||||||
|
|||||||
+14
-7
@@ -22,7 +22,8 @@ func TestStackAsyncTCP_multipacket(t *testing.T) {
|
|||||||
const seed = 1234
|
const seed = 1234
|
||||||
const MTU = 1500
|
const MTU = 1500
|
||||||
const svPort = 8080
|
const svPort = 8080
|
||||||
const maxPkt = 30
|
const maxPktLen = 30
|
||||||
|
const maxNPkt = 32
|
||||||
client, sv, clconn, svconn := newTCPStacks(t, seed, MTU)
|
client, sv, clconn, svconn := newTCPStacks(t, seed, MTU)
|
||||||
tst := tester{
|
tst := tester{
|
||||||
t: t, buf: make([]byte, MTU),
|
t: t, buf: make([]byte, MTU),
|
||||||
@@ -34,10 +35,13 @@ func TestStackAsyncTCP_multipacket(t *testing.T) {
|
|||||||
tst.TestTCPClose(client, sv, clconn, svconn)
|
tst.TestTCPClose(client, sv, clconn, svconn)
|
||||||
var buf [MTU]byte
|
var buf [MTU]byte
|
||||||
for i := 0; i < 30; i++ {
|
for i := 0; i < 30; i++ {
|
||||||
payloadSize := rng.Intn(maxPkt) + 1
|
payloadSize := rng.Intn(maxPktLen) + 1
|
||||||
tst.TestTCPSetupAndEstablish(sv, client, svconn, clconn, svPort, 1337)
|
tst.TestTCPSetupAndEstablish(sv, client, svconn, clconn, svPort, 1337)
|
||||||
a, _ := rng.Read(buf[:payloadSize])
|
npkt := rng.Intn(maxNPkt-1) + 2
|
||||||
tst.TestTCPEstablishedSingleData(sv, client, svconn, clconn, buf[:a])
|
for ipkt := 0; ipkt < npkt; ipkt++ {
|
||||||
|
a, _ := rng.Read(buf[:payloadSize])
|
||||||
|
tst.TestTCPEstablishedSingleData(sv, client, svconn, clconn, buf[:a])
|
||||||
|
}
|
||||||
tst.TestTCPClose(client, sv, clconn, svconn)
|
tst.TestTCPClose(client, sv, clconn, svconn)
|
||||||
if t.Failed() {
|
if t.Failed() {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
@@ -180,11 +184,14 @@ func (tst *tester) TestTCPHandshake(stack1, stack2 *StackAsync) {
|
|||||||
func (tst *tester) TestTCPEstablishedSingleData(srcStack, dstStack *StackAsync, srcConn, dstConn *tcp.Conn, sendData []byte) {
|
func (tst *tester) TestTCPEstablishedSingleData(srcStack, dstStack *StackAsync, srcConn, dstConn *tcp.Conn, sendData []byte) {
|
||||||
t := tst.t
|
t := tst.t
|
||||||
t.Helper()
|
t.Helper()
|
||||||
avail := srcConn.AvailableOutput()
|
availTx := srcConn.AvailableOutput()
|
||||||
if avail < len(sendData) {
|
availRx := dstConn.AvailableInput()
|
||||||
t.Fatal("insufficient space for write call", avail, len(sendData))
|
if availTx < len(sendData) {
|
||||||
|
t.Fatal("insufficient space for write call", availTx, len(sendData))
|
||||||
} else if len(sendData) <= 0 {
|
} else if len(sendData) <= 0 {
|
||||||
panic("empty data!")
|
panic("empty data!")
|
||||||
|
} else if availRx < len(sendData) {
|
||||||
|
t.Fatal("insufficient space for dst read call", availRx, len(sendData))
|
||||||
}
|
}
|
||||||
_, err := srcConn.Write(sendData)
|
_, err := srcConn.Write(sendData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user