Browse Source

修复用户在路由中调用IConnecion.Stop()时导致的OnConnStop调用多次问题

master
gufeijun 4 years ago
parent
commit
34b9018af0
  1. 11
      znet/connection.go

11
znet/connection.go

@ -162,20 +162,20 @@ func (c *Connection) Start() {
//停止连接,结束当前连接状态M
func (c *Connection) Stop() {
fmt.Println("Conn Stop()...ConnID = ", c.ConnID)
c.Lock()
defer c.Unlock()
//如果用户注册了该链接的关闭回调业务,那么在此刻应该显示调用
c.TcpServer.CallOnConnStop(c)
//如果当前链接已经关闭
if c.isClosed == true {
return
}
c.isClosed = true
fmt.Println("Conn Stop()...ConnID = ", c.ConnID)
//如果用户注册了该链接的关闭回调业务,那么在此刻应该显示调用
c.TcpServer.CallOnConnStop(c)
// 关闭socket链接
c.Conn.Close()
//关闭Writer
@ -211,7 +211,6 @@ func (c *Connection) SendMsg(msgId uint32, data []byte) error {
return errors.New("connection closed when send msg")
}
//将data封包,并且发送
dp := NewDataPack()
msg, err := dp.Pack(NewMsgPackage(msgId, data))

Loading…
Cancel
Save