mirror of
https://github.com/xtaci/kcp-go.git
synced 2024-04-21 12:32:15 +00:00
optimize counting
This commit is contained in:
+1
-3
@@ -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
|
||||
|
||||
+8
-12
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user