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