修复bug
This commit is contained in:
parent
d58fa26143
commit
495530a575
22
ws/wsConn.go
22
ws/wsConn.go
@ -1,7 +1,6 @@
|
||||
package ws
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"github.com/fox/fox/ipb"
|
||||
"github.com/fox/fox/log"
|
||||
@ -56,7 +55,6 @@ func (c *wsConnect) SendMsg(data []byte) error {
|
||||
func (c *wsConnect) Close() {
|
||||
c.once.Do(func() {
|
||||
//log.Debug(c.Log("关闭链接"))
|
||||
_ = c.wsConn.WriteMessage(websocket.CloseMessage, []byte{})
|
||||
c.inChan.Close()
|
||||
c.outChan.Close()
|
||||
_ = c.wsConn.Close()
|
||||
@ -92,25 +90,6 @@ func (c *wsConnect) readWsLoop() {
|
||||
//log.Debug(c.Log("关闭连接:%v", err))
|
||||
return
|
||||
}
|
||||
switch msgType {
|
||||
//case websocket.PingMessage:
|
||||
// log.Debug(c.Log("received ping message"))
|
||||
// _ = c.sendMsg(websocket.PongMessage, []byte("pong"))
|
||||
//case websocket.PongMessage:
|
||||
// log.Debug(c.Log("received pong from client"))
|
||||
case websocket.CloseMessage:
|
||||
code := websocket.CloseNormalClosure
|
||||
reason := ""
|
||||
if len(data) >= 2 {
|
||||
code = int(binary.BigEndian.Uint16(data))
|
||||
reason = string(data[2:])
|
||||
}
|
||||
log.Debug(c.Log("关闭原因码:%d 描述:%s", code, reason))
|
||||
// 发送响应关闭帧(必须回传相同状态码)
|
||||
rspMsg := websocket.FormatCloseMessage(code, reason)
|
||||
_ = c.wsConn.WriteControl(websocket.CloseMessage, rspMsg, time.Now().Add(5*time.Second))
|
||||
return
|
||||
default:
|
||||
if msgType != wsMsgType {
|
||||
continue
|
||||
}
|
||||
@ -121,7 +100,6 @@ func (c *wsConnect) readWsLoop() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *wsConnect) writeWsLoop() {
|
||||
ticker := time.NewTicker(pingPeriod)
|
||||
|
Loading…
x
Reference in New Issue
Block a user