optimize recvLoop

This commit is contained in:
xtaci
2016-09-01 14:30:07 +08:00
parent c368df894a
commit 6f8177ccd6
2 changed files with 15 additions and 15 deletions
+8 -1
View File
@@ -215,7 +215,12 @@ func (s *Session) recvLoop() {
s.sendFrame(newFrame(cmdRST, f.sid))
}
s.tbf <- struct{}{}
default:
case cmdRST:
if _, ok := s.streams[f.sid]; ok {
s.streams[f.sid].Close()
}
s.tbf <- struct{}{}
case cmdPSH:
if _, ok := s.streams[f.sid]; ok {
s.frameQueues[f.sid] = append(s.frameQueues[f.sid], f)
select {
@@ -226,6 +231,8 @@ func (s *Session) recvLoop() {
s.sendFrame(newFrame(cmdRST, f.sid))
s.tbf <- struct{}{}
}
default:
s.sendFrame(newFrame(cmdRST, f.sid))
}
s.mu.Unlock()
atomic.StoreInt32(&s.dataReady, 1)
+7 -14
View File
@@ -2,7 +2,6 @@ package smux
import (
"bytes"
"io"
"sync"
"github.com/pkg/errors"
@@ -47,20 +46,14 @@ READ:
return n, nil
}
if f := s.sess.nioread(s.id); f != nil {
switch f.cmd {
case cmdPSH:
n = copy(b, f.data)
if len(f.data) > n {
s.buffer = make([]byte, len(f.data)-n)
copy(s.buffer, f.data[n:])
}
s.rlock.Unlock()
return n, nil
default:
s.rlock.Unlock()
return 0, io.EOF
if f := s.sess.nioread(s.id); f != nil && f.cmd == cmdPSH {
n = copy(b, f.data)
if len(f.data) > n {
s.buffer = make([]byte, len(f.data)-n)
copy(s.buffer, f.data[n:])
}
s.rlock.Unlock()
return n, nil
}
s.rlock.Unlock()