代码拉取完成,页面将自动刷新
package gate
import (
"time"
"gitee.com/nbcx/leaf/chanrpc"
"gitee.com/nbcx/leaf/network"
"gitee.com/nbcx/leaf/network/tcp"
"gitee.com/nbcx/leaf/network/ws"
)
type Gate struct {
MaxConnNum int
PendingWriteNum int
MaxMsgLen uint32
Processor network.Processor
AgentChanRPC *chanrpc.Server
// websocket
WSAddr string
HTTPTimeout time.Duration
CertFile string
KeyFile string
// tcp
TCPAddr string
LenMsgLen int
LittleEndian bool
}
func (gate *Gate) Run(closeSig chan bool) {
var wsServer *ws.WSServer
if gate.WSAddr != "" {
wsServer = new(ws.WSServer)
wsServer.Addr = gate.WSAddr
wsServer.MaxConnNum = gate.MaxConnNum
wsServer.PendingWriteNum = gate.PendingWriteNum
wsServer.MaxMsgLen = gate.MaxMsgLen
wsServer.HTTPTimeout = gate.HTTPTimeout
wsServer.CertFile = gate.CertFile
wsServer.KeyFile = gate.KeyFile
wsServer.NewAgent = func(conn *ws.WSConn) network.Agent {
a := &agent{conn: conn, gate: gate}
if gate.AgentChanRPC != nil {
gate.AgentChanRPC.Go("NewAgent", a)
}
return a
}
}
var tcpServer *tcp.TCPServer
if gate.TCPAddr != "" {
tcpServer = new(tcp.TCPServer)
tcpServer.Addr = gate.TCPAddr
tcpServer.MaxConnNum = gate.MaxConnNum
tcpServer.PendingWriteNum = gate.PendingWriteNum
tcpServer.LenMsgLen = gate.LenMsgLen
tcpServer.MaxMsgLen = gate.MaxMsgLen
tcpServer.LittleEndian = gate.LittleEndian
tcpServer.NewAgent = func(conn *tcp.TCPConn) network.Agent {
a := &agent{conn: conn, gate: gate}
if gate.AgentChanRPC != nil {
gate.AgentChanRPC.Go("NewAgent", a)
}
return a
}
}
if wsServer != nil {
wsServer.Start()
}
if tcpServer != nil {
tcpServer.Start()
}
<-closeSig
if wsServer != nil {
wsServer.Close()
}
if tcpServer != nil {
tcpServer.Close()
}
}
func (gate *Gate) OnDestroy() {}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。