Compare commits

...

3 Commits

Author SHA1 Message Date
boyce
15580ffce9 新增wss证书配置支持 2025-04-21 21:23:34 +08:00
boyce
bd467a219b 废弃掉HttpService、TcpService、WSService 2025-03-28 10:33:51 +08:00
boyce
af15615345 优化日志生成路径 2025-03-14 18:03:01 +08:00
6 changed files with 28 additions and 9 deletions

View File

@@ -73,9 +73,22 @@ func (handler *WSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
handler.conns[conn] = struct{}{}
handler.mutexConns.Unlock()
c,ok:=conn.NetConn().(*net.TCPConn)
if !ok {
tlsConn,ok := conn.NetConn().(*tls.Conn)
if !ok {
log.Error("conn error")
return
}
c,ok = tlsConn.NetConn().(*net.TCPConn)
if !ok {
log.Error("conn error")
return
}
}
conn.UnderlyingConn().(*net.TCPConn).SetLinger(0)
conn.UnderlyingConn().(*net.TCPConn).SetNoDelay(true)
c.SetLinger(0)
c.SetNoDelay(true)
wsConn := newWSConn(conn, r.Header, handler.pendingWriteNum, handler.maxMsgLen, handler.messageType)
agent := handler.newAgent(wsConn)
agent.Run()

View File

@@ -479,11 +479,7 @@ func setLogPath(args interface{}) error {
return nil
}
logPath := strings.TrimSpace(args.(string))
dir, err := os.Stat(logPath)
if err != nil || dir.IsDir() == false {
return errors.New("Not found dir " + logPath)
}
_, err := os.Stat(logPath)
if err != nil {
err = os.MkdirAll(logPath, os.ModePerm)
if err != nil {

View File

@@ -34,6 +34,8 @@ type WSCfg struct {
PendingWriteNum int
MaxMsgLen uint32
LittleEndian bool //是否小端序
KeyFile string
CertFile string
}
type WSPackType int8
@@ -62,13 +64,18 @@ func (ws *WSModule) OnInit() error {
ws.WSServer.MaxMsgLen = ws.wsCfg.MaxMsgLen
ws.WSServer.Addr = ws.wsCfg.ListenAddr
//3.设置解析处理器
if ws.wsCfg.KeyFile != "" && ws.wsCfg.CertFile != "" {
ws.WSServer.KeyFile = ws.wsCfg.KeyFile
ws.WSServer.CertFile = ws.wsCfg.CertFile
}
// 设置解析处理器
ws.process.SetByteOrder(ws.wsCfg.LittleEndian)
ws.mapClient = make(map[string]*WSClient, ws.WSServer.MaxConnNum)
ws.WSServer.NewAgent = ws.NewWSClient
//4.设置网络事件处理
// 设置网络事件处理
ws.GetEventProcessor().RegEventReceiverFunc(event.Sys_Event_WebSocket, ws.GetEventHandler(), ws.wsEventHandler)
return nil

View File

@@ -83,6 +83,7 @@ type HttpSession struct {
sessionDone chan *HttpSession
}
// Deprecated: replace it with the GinModule
type HttpService struct {
service.Service

View File

@@ -14,6 +14,7 @@ import (
"time"
)
// Deprecated: replace it with the TcpModule
type TcpService struct {
tcpServer network.TCPServer
service.Service

View File

@@ -12,6 +12,7 @@ import (
"sync"
)
// Deprecated: replace it with the WSModule
type WSService struct {
service.Service
wsServer network.WSServer