mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
优化ws模块
This commit is contained in:
@@ -14,7 +14,7 @@ import (
|
|||||||
type WSModule struct {
|
type WSModule struct {
|
||||||
service.Module
|
service.Module
|
||||||
|
|
||||||
wsServer network.WSServer
|
WSServer network.WSServer
|
||||||
|
|
||||||
mapClientLocker sync.RWMutex
|
mapClientLocker sync.RWMutex
|
||||||
mapClient map[string]*WSClient
|
mapClient map[string]*WSClient
|
||||||
@@ -57,16 +57,16 @@ func (ws *WSModule) OnInit() error {
|
|||||||
return fmt.Errorf("please call the Init function correctly")
|
return fmt.Errorf("please call the Init function correctly")
|
||||||
}
|
}
|
||||||
|
|
||||||
ws.wsServer.MaxConnNum = ws.wsCfg.MaxConnNum
|
ws.WSServer.MaxConnNum = ws.wsCfg.MaxConnNum
|
||||||
ws.wsServer.PendingWriteNum = ws.wsCfg.PendingWriteNum
|
ws.WSServer.PendingWriteNum = ws.wsCfg.PendingWriteNum
|
||||||
ws.wsServer.MaxMsgLen = ws.wsCfg.MaxMsgLen
|
ws.WSServer.MaxMsgLen = ws.wsCfg.MaxMsgLen
|
||||||
ws.wsServer.Addr = ws.wsCfg.ListenAddr
|
ws.WSServer.Addr = ws.wsCfg.ListenAddr
|
||||||
|
|
||||||
//3.设置解析处理器
|
//3.设置解析处理器
|
||||||
ws.process.SetByteOrder(ws.wsCfg.LittleEndian)
|
ws.process.SetByteOrder(ws.wsCfg.LittleEndian)
|
||||||
|
|
||||||
ws.mapClient = make(map[string]*WSClient, ws.wsServer.MaxConnNum)
|
ws.mapClient = make(map[string]*WSClient, ws.WSServer.MaxConnNum)
|
||||||
ws.wsServer.NewAgent = ws.NewWSClient
|
ws.WSServer.NewAgent = ws.NewWSClient
|
||||||
|
|
||||||
//4.设置网络事件处理
|
//4.设置网络事件处理
|
||||||
ws.GetEventProcessor().RegEventReceiverFunc(event.Sys_Event_WebSocket, ws.GetEventHandler(), ws.wsEventHandler)
|
ws.GetEventProcessor().RegEventReceiverFunc(event.Sys_Event_WebSocket, ws.GetEventHandler(), ws.wsEventHandler)
|
||||||
@@ -80,7 +80,7 @@ func (ws *WSModule) Init(wsCfg *WSCfg, process processor.IRawProcessor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ws *WSModule) Start() error {
|
func (ws *WSModule) Start() error {
|
||||||
return ws.wsServer.Start()
|
return ws.WSServer.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ws *WSModule) wsEventHandler(ev event.IEvent) {
|
func (ws *WSModule) wsEventHandler(ev event.IEvent) {
|
||||||
@@ -197,3 +197,7 @@ func (ws *WSModule) SendRawMsg(clientId string, msg []byte) error {
|
|||||||
ws.mapClientLocker.Unlock()
|
ws.mapClientLocker.Unlock()
|
||||||
return client.wsConn.WriteMsg(msg)
|
return client.wsConn.WriteMsg(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ws *WSModule) SetMessageType(messageType int) {
|
||||||
|
ws.WSServer.SetMessageType(messageType)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user