Skip to content

Commit

Permalink
optimize code on LOCK# , and a bug fix in write notify
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Jan 20, 2017
1 parent b0e1333 commit 2fc9562
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions sess.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ func (s *UDPSession) updateTask() {
case <-tc:
s.mu.Lock()
s.kcp.Update()
if s.kcp.WaitSnd() < 2*int(s.kcp.snd_wnd) {
if s.kcp.WaitSnd() < int(s.kcp.snd_wnd) {
s.notifyWriteEvent()
}
s.mu.Unlock()
Expand Down Expand Up @@ -546,22 +546,20 @@ func (s *UDPSession) notifyWriteEvent() {
}

func (s *UDPSession) kcpInput(data []byte) {
kcpInErrors := uint64(0)
fecErrs := uint64(0)
fecRecovered := uint64(0)
var kcpInErrors, fecErrs, fecRecovered, fecSegs uint64

if s.fec != nil {
f := s.fec.decode(data)
s.mu.Lock()
if f.flag == typeData {
if ret := s.kcp.Input(data[fecHeaderSizePlus2:], true); ret != 0 {
atomic.AddUint64(&DefaultSnmp.KCPInErrors, 1)
kcpInErrors++
}
}

if f.flag == typeData || f.flag == typeFEC {
if f.flag == typeFEC {
atomic.AddUint64(&DefaultSnmp.FECSegs, 1)
fecSegs++
}

if recovers := s.fec.input(f); recovers != nil {
Expand Down Expand Up @@ -595,7 +593,7 @@ func (s *UDPSession) kcpInput(data []byte) {
} else {
s.mu.Lock()
if ret := s.kcp.Input(data, true); ret != 0 {
atomic.AddUint64(&DefaultSnmp.KCPInErrors, 1)
kcpInErrors++
}
// notify reader
if n := s.kcp.PeekSize(); n > 0 {
Expand All @@ -609,6 +607,9 @@ func (s *UDPSession) kcpInput(data []byte) {

atomic.AddUint64(&DefaultSnmp.InSegs, 1)
atomic.AddUint64(&DefaultSnmp.InBytes, uint64(len(data)))
if fecSegs > 0 {
atomic.AddUint64(&DefaultSnmp.FECSegs, fecSegs)
}
if kcpInErrors > 0 {
atomic.AddUint64(&DefaultSnmp.KCPInErrors, kcpInErrors)
}
Expand Down

0 comments on commit 2fc9562

Please sign in to comment.