From 66a847a0c24874d9527355ce6c2bf8d1c5d32965 Mon Sep 17 00:00:00 2001 From: ignoramous Date: Fri, 17 Jun 2022 05:07:20 +0530 Subject: [PATCH] m. refactor eliminate a redundant variable --- pkg/tcpip/link/fdbased/endpoint.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pkg/tcpip/link/fdbased/endpoint.go b/pkg/tcpip/link/fdbased/endpoint.go index 564abbeec..e0d58b355 100644 --- a/pkg/tcpip/link/fdbased/endpoint.go +++ b/pkg/tcpip/link/fdbased/endpoint.go @@ -555,17 +555,15 @@ func (e *endpoint) writePacket(pkt *stack.PacketBuffer) tcpip.Error { func (e *endpoint) sendBatch(batchFDInfo fdInfo, pkts []*stack.PacketBuffer) (int, tcpip.Error) { // Degrade to writePacket if underlying fd is not a socket. if !batchFDInfo.isSocket { - written := 0 - for i := 0; i < len(pkts); i++ { - if err := e.writePacket(pkts[i]); err != nil { - if written > 0 { - return written, nil - } - return 0, err + var written int + var err error + for written < len(pkts) { + if err = e.writePacket(pkts[written]); err != nil { + break } - written = i + written++ } - return written, nil + return written, err } // Send a batch of packets through batchFD.