优化tcpservice

This commit is contained in:
duanhf2012
2024-10-09 09:50:11 +08:00
parent b943ea9a83
commit 75790302ec

View File

@@ -41,7 +41,7 @@ type TcpPack struct {
type Client struct { type Client struct {
id string id string
tcpConn *network.TCPConn tcpConn *network.NetConn
tcpService *TcpService tcpService *TcpService
} }
@@ -120,13 +120,13 @@ func (tcpService *TcpService) SetProcessor(process processor.IProcessor, handler
tcpService.RegEventReceiverFunc(event.Sys_Event_Tcp, handler, tcpService.TcpEventHandler) tcpService.RegEventReceiverFunc(event.Sys_Event_Tcp, handler, tcpService.TcpEventHandler)
} }
func (tcpService *TcpService) NewClient(conn *network.TCPConn) network.Agent { func (tcpService *TcpService) NewClient(conn network.Conn) network.Agent {
tcpService.mapClientLocker.Lock() tcpService.mapClientLocker.Lock()
defer tcpService.mapClientLocker.Unlock() defer tcpService.mapClientLocker.Unlock()
uuId, _ := uuid.NewUUID() uuId, _ := uuid.NewUUID()
clientId := strings.ReplaceAll(uuId.String(), "-", "") clientId := strings.ReplaceAll(uuId.String(), "-", "")
pClient := &Client{tcpConn: conn, id: clientId} pClient := &Client{tcpConn: conn.(*network.NetConn), id: clientId}
pClient.tcpService = tcpService pClient.tcpService = tcpService
tcpService.mapClient[clientId] = pClient tcpService.mapClient[clientId] = pClient