mirror of
https://github.com/fatedier/frp.git
synced 2024-12-15 10:58:59 +08:00
49 lines
977 B
Go
49 lines
977 B
Go
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
|
|
}
|
|
|
|
if n >= s.headerSize+IKCP_OVERHEAD {
|
|
s.packetInput(buf[:n])
|
|
} else {
|
|
atomic.AddUint64(&DefaultSnmp.InErrs, 1)
|
|
}
|
|
} 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 {
|
|
if n >= l.headerSize+IKCP_OVERHEAD {
|
|
l.packetInput(buf[:n], from)
|
|
} else {
|
|
atomic.AddUint64(&DefaultSnmp.InErrs, 1)
|
|
}
|
|
} else {
|
|
l.notifyReadError(errors.WithStack(err))
|
|
return
|
|
}
|
|
}
|
|
}
|