keep working on xnet TCP

This commit is contained in:
Patricio Whittingslow
2025-10-23 21:18:25 -03:00
parent 7ac4d556c2
commit 92a245957b
5 changed files with 203 additions and 61 deletions
+2 -1
View File
@@ -111,7 +111,8 @@ func StringExchange(seg Segment, A, B State, invertDir bool) string {
//
// SynSent --> <SEQ=300><ACK=91>[SYN,ACK] --> SynRcvd
func appendStringExchange(buf []byte, seg Segment, A, B State, invertDir bool) []byte {
const emptySpaces = " "
const emptySpaces = " "
const spacelen = len(emptySpaces)
const fill = len(emptySpaces) - 1
appendVal := func(buf []byte, name string, i Value) []byte {
buf = append(buf, '<')
+12 -1
View File
@@ -177,6 +177,12 @@ func (h *Handler) Recv(incomingPacket []byte) error {
}
return err
}
if h.scb.State() == StateClosed {
// TCB aborted, likely because it received an ACK in LastAck state.
// Clean up connection now.
h.reset(0, 0, 0)
return net.ErrClosed
}
if prevState != h.scb.State() {
h.info("tcp.Handler:rx-statechange", slog.Uint64("port", uint64(h.localPort)), slog.String("old", prevState.String()), slog.String("new", h.scb.State().String()), slog.String("rxflags", segIncoming.Flags.String()))
}
@@ -269,7 +275,12 @@ func (h *Handler) Send(b []byte) (int, error) {
tfrm.SetDestinationPort(h.remotePort)
tfrm.SetSegment(segment, offset)
tfrm.SetUrgentPtr(0)
return int(offset)*4 + int(segment.DATALEN), nil
datalen := int(offset)*4 + int(segment.DATALEN)
closedSuccess := prevState == StateTimeWait && segment.Flags.HasAny(FlagACK)
if closedSuccess {
h.reset(0, 0, 0)
}
return datalen, nil
}
// FreeTx returns the amount of space free in the transmit buffer. A call to [Handler.Write] with a larger buffer will fail.
+4
View File
@@ -792,6 +792,10 @@ func TestIssue19(t *testing.T) {
t.Fatal(err)
}
assertState(tcp.StateFinWait1)
pending, ok = tcb.PendingSegment(0)
if ok {
t.Fatal("expected no pending segment after finack")
}
// Receive FINACK response from client.
err = tcb.Recv(tcp.Segment{SEQ: issB, ACK: issA + httpLen, Flags: FINACK, WND: windowB})