upd frame format

This commit is contained in:
xtaci
2016-08-31 16:29:30 +08:00
parent 5836a971d3
commit b44c09c8de
3 changed files with 7 additions and 7 deletions
+2 -2
View File
@@ -3,11 +3,11 @@ package smux
import "io"
// Server is used to initialize a new server-side connection.
func Server(conn io.ReadWriteCloser, maxframes, framesize int) (*Session, error) {
func Server(conn io.ReadWriteCloser, maxframes int, framesize uint16) (*Session, error) {
return newSession(conn, false, maxframes, framesize), nil
}
// Client is used to initialize a new client-side connection.
func Client(conn io.ReadWriteCloser, maxframes, framesize int) (*Session, error) {
func Client(conn io.ReadWriteCloser, maxframes int, framesize uint16) (*Session, error) {
return newSession(conn, true, maxframes, framesize), nil
}
+2 -2
View File
@@ -21,7 +21,7 @@ type Session struct {
// stream related
nextStreamID uint32
streams map[uint32]*Stream
frameSize int
frameSize uint16
// rx pool control
tokens chan struct{}
@@ -47,7 +47,7 @@ func (lw *lockedWriter) Write(p []byte) (n int, err error) {
return
}
func newSession(conn io.ReadWriteCloser, client bool, maxframes, framesize int) *Session {
func newSession(conn io.ReadWriteCloser, client bool, maxframes int, framesize uint16) *Session {
s := new(Session)
s.conn = conn
s.frameSize = framesize
+3 -3
View File
@@ -13,13 +13,13 @@ type Stream struct {
id uint32
chNotifyReader chan struct{}
sess *Session
frameSize int
frameSize uint16
die chan struct{}
rlock sync.Mutex
buffer []byte
}
func newStream(id uint32, frameSize int, chNotifyReader chan struct{}, sess *Session) *Stream {
func newStream(id uint32, frameSize uint16, chNotifyReader chan struct{}, sess *Session) *Stream {
s := new(Stream)
s.id = id
s.chNotifyReader = chNotifyReader
@@ -108,7 +108,7 @@ func (s *Stream) Close() error {
func (s *Stream) split(bts []byte, cmd byte, sid uint32) []Frame {
var frames []Frame
for len(bts) > s.frameSize {
for len(bts) > int(s.frameSize) {
frame := newFrame(cmd, sid)
frame.data = make([]byte, s.frameSize)
n := copy(frame.data, bts)