diff options
Diffstat (limited to 'vendor/github.com/xtaci/kcp-go/v5/readloop.go')
-rw-r--r-- | vendor/github.com/xtaci/kcp-go/v5/readloop.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/vendor/github.com/xtaci/kcp-go/v5/readloop.go b/vendor/github.com/xtaci/kcp-go/v5/readloop.go new file mode 100644 index 0000000..697395a --- /dev/null +++ b/vendor/github.com/xtaci/kcp-go/v5/readloop.go @@ -0,0 +1,39 @@ +package kcp + +import ( + "sync/atomic" + + "github.com/pkg/errors" +) + +func (s *UDPSession) defaultReadLoop() { + buf := make([]byte, mtuLimit) + var src string + for { + if n, addr, err := s.conn.ReadFrom(buf); err == nil { + // make sure the packet is from the same source + if src == "" { // set source address + src = addr.String() + } else if addr.String() != src { + atomic.AddUint64(&DefaultSnmp.InErrs, 1) + continue + } + s.packetInput(buf[:n]) + } else { + s.notifyReadError(errors.WithStack(err)) + return + } + } +} + +func (l *Listener) defaultMonitor() { + buf := make([]byte, mtuLimit) + for { + if n, from, err := l.conn.ReadFrom(buf); err == nil { + l.packetInput(buf[:n], from) + } else { + l.notifyReadError(errors.WithStack(err)) + return + } + } +} |