mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-12 22:54:43 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
15580ffce9 | ||
|
|
bd467a219b |
@@ -73,9 +73,22 @@ func (handler *WSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
handler.conns[conn] = struct{}{}
|
handler.conns[conn] = struct{}{}
|
||||||
handler.mutexConns.Unlock()
|
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)
|
c.SetLinger(0)
|
||||||
conn.UnderlyingConn().(*net.TCPConn).SetNoDelay(true)
|
c.SetNoDelay(true)
|
||||||
wsConn := newWSConn(conn, r.Header, handler.pendingWriteNum, handler.maxMsgLen, handler.messageType)
|
wsConn := newWSConn(conn, r.Header, handler.pendingWriteNum, handler.maxMsgLen, handler.messageType)
|
||||||
agent := handler.newAgent(wsConn)
|
agent := handler.newAgent(wsConn)
|
||||||
agent.Run()
|
agent.Run()
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ type WSCfg struct {
|
|||||||
PendingWriteNum int
|
PendingWriteNum int
|
||||||
MaxMsgLen uint32
|
MaxMsgLen uint32
|
||||||
LittleEndian bool //是否小端序
|
LittleEndian bool //是否小端序
|
||||||
|
KeyFile string
|
||||||
|
CertFile string
|
||||||
}
|
}
|
||||||
|
|
||||||
type WSPackType int8
|
type WSPackType int8
|
||||||
@@ -62,13 +64,18 @@ func (ws *WSModule) OnInit() error {
|
|||||||
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.设置解析处理器
|
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.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.设置网络事件处理
|
// 设置网络事件处理
|
||||||
ws.GetEventProcessor().RegEventReceiverFunc(event.Sys_Event_WebSocket, ws.GetEventHandler(), ws.wsEventHandler)
|
ws.GetEventProcessor().RegEventReceiverFunc(event.Sys_Event_WebSocket, ws.GetEventHandler(), ws.wsEventHandler)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ type HttpSession struct {
|
|||||||
sessionDone chan *HttpSession
|
sessionDone chan *HttpSession
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: replace it with the GinModule
|
||||||
type HttpService struct {
|
type HttpService struct {
|
||||||
service.Service
|
service.Service
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Deprecated: replace it with the TcpModule
|
||||||
type TcpService struct {
|
type TcpService struct {
|
||||||
tcpServer network.TCPServer
|
tcpServer network.TCPServer
|
||||||
service.Service
|
service.Service
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Deprecated: replace it with the WSModule
|
||||||
type WSService struct {
|
type WSService struct {
|
||||||
service.Service
|
service.Service
|
||||||
wsServer network.WSServer
|
wsServer network.WSServer
|
||||||
|
|||||||
Reference in New Issue
Block a user