forked from xtaci/kcp-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtx_generic.go
50 lines (46 loc) · 987 Bytes
/
tx_generic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// +build !linux
package kcp
import (
"sync/atomic"
)
func (s *UDPSession) txLoop() {
for {
select {
case txqueue := <-s.chTxQueue:
nbytes := 0
for k := range txqueue {
if n, err := s.conn.WriteTo(txqueue[k].Buffers[0], txqueue[k].Addr); err == nil {
nbytes += n
} else {
s.notifyWriteError(err)
return
}
}
atomic.AddUint64(&DefaultSnmp.OutPkts, uint64(len(txqueue)))
atomic.AddUint64(&DefaultSnmp.OutBytes, uint64(nbytes))
case <-s.die:
return
}
}
}
func (l *Listener) txLoop() {
for {
select {
case txqueue := <-l.chTxQueue:
nbytes := 0
for k := range txqueue {
if n, err := l.conn.WriteTo(txqueue[k].Buffers[0], txqueue[k].Addr); err == nil {
nbytes += n
xmitBuf.Put(txqueue[k].Buffers[0])
} else {
l.Close()
return
}
}
atomic.AddUint64(&DefaultSnmp.OutPkts, uint64(len(txqueue)))
atomic.AddUint64(&DefaultSnmp.OutBytes, uint64(nbytes))
case <-l.die:
return
}
}
}