mirror of
https://github.com/xtaci/kcp-go.git
synced 2024-04-21 12:32:15 +00:00
commit a8ae293a9ddee042c35e2501f93fa5dfa2425302 Merge:bdaf81e1a84985Author: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 22:48:13 2020 +0800 Merge branch 'master' into autotune commitbdaf81e88eAuthor: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 22:38:31 2020 +0800 add loc commitce66a98f95Author: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 19:53:42 2020 +0800 lint commitad7383d8a3Author: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 19:05:35 2020 +0800 fix typo commitdc0fc2364cAuthor: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 16:47:14 2020 +0800 adjust tests commitec45b72c39Author: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 16:45:17 2020 +0800 remove obsolete decoder in listener commit827aa70e29Author: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 16:42:42 2020 +0800 use hierarchical defensive receiving strategy commitf5ca6b0e3aAuthor: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 16:34:30 2020 +0800 optimize condition commitff34f7683fAuthor: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 15:18:00 2020 +0800 fix test commita08b274651Author: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 15:13:20 2020 +0800 solve compability issue with non FEC sender commitab7596783bAuthor: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 15:02:34 2020 +0800 implements autotune in fec decoder commit260f61b3ebAuthor: xtaci <daniel820313@gmail.com> Date: Fri Oct 9 14:34:48 2020 +0800 hack 16-bit to identify FEC from packet commit105bfec567Author: xtaci <daniel820313@gmail.com> Date: Fri Oct 2 21:38:47 2020 +0800 add autotune
40 lines
770 B
Go
40 lines
770 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
|
|
}
|
|
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
|
|
}
|
|
}
|
|
}
|