remove overly verbose logging and short circuit TCP nop encapsulate

This commit is contained in:
Patricio Whittingslow
2026-02-27 08:43:31 -03:00
parent 76f896af40
commit 04664afe3a
2 changed files with 9 additions and 5 deletions
+2 -2
View File
@@ -366,11 +366,11 @@ func (conn *Conn) Encapsulate(carrierData []byte, offsetToIP, offsetToFrame int)
} else if len(raddr) != len(conn.remoteAddr) {
return 0, errMismatchedIPVersion
}
conn.trace("TCPConn.encaps", slog.Uint64("lport", uint64(conn.h.LocalPort())), slog.Uint64("rport", uint64(conn.h.remotePort)))
n, err = conn.h.Send(carrierData[offsetToFrame:])
if err != nil {
if err != nil || n == 0 {
return 0, err
}
conn.trace("TCPConn.encaps", slog.Uint64("lport", uint64(conn.h.LocalPort())), slog.Uint64("rport", uint64(conn.h.remotePort)))
err = internal.SetIPAddrs(ipFrame, conn.ipID, nil, conn.remoteAddr)
if err != nil {
return 0, err
+7 -3
View File
@@ -236,15 +236,19 @@ func (h *Handler) Close() error {
// It does no IP interfacing or CRC calculation of packet, which is left to the caller to perform.
// The returned integer is the length written to the argument buffer.
func (h *Handler) Send(b []byte) (int, error) {
h.trace("tcp.Handler:start", slog.Uint64("port", uint64(h.localPort)))
if h.IsTxOver() {
return 0, net.ErrClosed
}
awaitingSyn := h.AwaitingSynSend()
buffered := h.bufTx.BufferedUnsent()
if !awaitingSyn && buffered == 0 && !h.closing && !h.scb.HasPending() {
// Early nop short circuit.
return 0, nil
}
tfrm, err := NewFrame(b)
if err != nil {
return 0, err
}
buffered := h.bufTx.BufferedUnsent()
if buffered == 0 && h.closing {
// If Close called and no more data to be sent, terminate connection!
h.closing = false
@@ -258,7 +262,7 @@ func (h *Handler) Send(b []byte) (int, error) {
offset := uint8(5)
mss := uint16(len(b) - sizeHeaderTCP)
var segment Segment
if h.AwaitingSynSend() {
if awaitingSyn {
// Handling init syn segment.
segment = ClientSynSegment(h.bufTx.iss, Size(h.bufRx.Size()))
h.optcodec.PutOption16(b[sizeHeaderTCP:], OptMaxSegmentSize, mss)