mirror of
https://github.com/xtaci/smux.git
synced 2024-04-21 10:51:48 +00:00
optimize recvLoop
This commit is contained in:
+8
-1
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user