diff --git a/server.go b/server.go index c2d58eb891d171487b0e27bcfd6c080840527256..7562402f95f2fae89521246912ba340ee42c2d0f 100644 --- a/server.go +++ b/server.go @@ -19,10 +19,12 @@ type Options struct { AutoMergePacket bool CloseHandler func(*Session) PrivateKey *rsa.PrivateKey + SendChanSize int } // 协议服务器 type Server struct { + option Options server *link.Server handler sessionHandler timer *CountdownTimer @@ -43,6 +45,10 @@ func NewServer(options Options) (*Server, error) { options.Keepalive = 60 } + if options.SendChanSize <= 0{ + options.SendChanSize = 24 + } + if options.PrivateKey != nil && options.PrivateKey.Size() != 128 { return nil, errors.New("RSA key must be 1024 bits") } @@ -51,6 +57,7 @@ func NewServer(options Options) (*Server, error) { closeHandler: options.CloseHandler, sessions: make(map[uint64]*Session), privateKey: options.PrivateKey, + option: options, } server.handler.server = &server server.handler.autoMergePacket = options.AutoMergePacket @@ -73,7 +80,7 @@ func (server *Server) Run(network string, port int) error { p := Protocol{ privateKey: server.privateKey, } - server.server = link.NewServer(listen, &p, 24, server.handler) + server.server = link.NewServer(listen, &p, server.SendChanSize, server.handler) log.Infof("[JT/T 808] protocol server started on %s", address) return server.server.Serve() }