diff --git a/tx_generic.go b/tx_generic.go index 0eeab6d..5dd5cad 100644 --- a/tx_generic.go +++ b/tx_generic.go @@ -11,18 +11,16 @@ func (s *UDPSession) txLoop() { select { case txqueue := <-s.chTxQueue: nbytes := 0 - npkts := 0 for k := range txqueue { if n, err := s.conn.WriteTo(txqueue[k], s.remote); err == nil { nbytes += n - npkts++ } else { s.notifyWriteError(err) } xmitBuf.Put(txqueue[k]) } - atomic.AddUint64(&DefaultSnmp.OutPkts, uint64(npkts)) + atomic.AddUint64(&DefaultSnmp.OutPkts, uint64(len(txqueue))) atomic.AddUint64(&DefaultSnmp.OutBytes, uint64(nbytes)) case <-s.die: return diff --git a/tx_linux.go b/tx_linux.go index 3b31a7f..c38cadc 100644 --- a/tx_linux.go +++ b/tx_linux.go @@ -27,15 +27,13 @@ func (s *UDPSession) txLoopIPv4() { select { case txqueue := <-s.chTxQueue: if len(txqueue) > 0 { - var nbytes uint64 - var npkts uint64 + nbytes := 0 for k := range txqueue { idx := k % batchSize msgs[idx].Addr = s.remote msgs[idx].Buffers = [][]byte{txqueue[k]} - nbytes += uint64(len(txqueue[k])) - npkts++ + nbytes += len(txqueue[k]) if (k+1)%batchSize == 0 { if _, err := conn.WriteBatch(msgs, 0); err != nil { @@ -54,8 +52,8 @@ func (s *UDPSession) txLoopIPv4() { xmitBuf.Put(txqueue[k]) } - atomic.AddUint64(&DefaultSnmp.OutPkts, npkts) - atomic.AddUint64(&DefaultSnmp.OutBytes, nbytes) + atomic.AddUint64(&DefaultSnmp.OutPkts, uint64(len(txqueue))) + atomic.AddUint64(&DefaultSnmp.OutBytes, uint64(nbytes)) } case <-s.die: return @@ -71,15 +69,13 @@ func (s *UDPSession) txLoopIPv6() { select { case txqueue := <-s.chTxQueue: if len(txqueue) > 0 { - var nbytes uint64 - var npkts uint64 + nbytes := 0 for k := range txqueue { idx := k % batchSize msgs[idx].Addr = s.remote msgs[idx].Buffers = [][]byte{txqueue[k]} - nbytes += uint64(len(txqueue[k])) - npkts++ + nbytes += len(txqueue[k]) if (k+1)%batchSize == 0 { if _, err := conn.WriteBatch(msgs, 0); err != nil { @@ -98,8 +94,8 @@ func (s *UDPSession) txLoopIPv6() { xmitBuf.Put(txqueue[k]) } - atomic.AddUint64(&DefaultSnmp.OutPkts, npkts) - atomic.AddUint64(&DefaultSnmp.OutBytes, nbytes) + atomic.AddUint64(&DefaultSnmp.OutPkts, uint64(len(txqueue))) + atomic.AddUint64(&DefaultSnmp.OutBytes, uint64(nbytes)) } case <-s.die: return