github.com/geph-official/geph2@v0.22.6-0.20210211030601-f527cb59b0df/libs/kcp-go/tx.go (about)

     1  package kcp
     2  
     3  import (
     4  	"sync/atomic"
     5  
     6  	"github.com/pkg/errors"
     7  	"golang.org/x/net/ipv4"
     8  )
     9  
    10  func (s *UDPSession) defaultTx(txqueue []ipv4.Message) {
    11  	nbytes := 0
    12  	npkts := 0
    13  	//start := time.Now()
    14  	//divider := len(txqueue)
    15  	for k := range txqueue {
    16  		if n, err := s.conn.WriteTo(txqueue[k].Buffers[0], txqueue[k].Addr); err == nil {
    17  			nbytes += n
    18  			npkts++
    19  			xmitBuf.Put(txqueue[k].Buffers[0])
    20  			txqueue[k].Buffers[0] = nil
    21  		} else {
    22  			s.notifyWriteError(errors.WithStack(err))
    23  			break
    24  		}
    25  
    26  	}
    27  	//log.Println("tx in", time.Since(start)/time.Duration(divider))
    28  	atomic.AddUint64(&DefaultSnmp.OutPkts, uint64(npkts))
    29  	atomic.AddUint64(&DefaultSnmp.OutBytes, uint64(nbytes))
    30  }