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

Loading…
Cancel
Save