From 34b9018af06e04ca8e77e1cea80d856eaf105aff Mon Sep 17 00:00:00 2001 From: gufeijun Date: Sun, 21 Feb 2021 16:00:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=A8=E6=88=B7=E5=9C=A8?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E4=B8=AD=E8=B0=83=E7=94=A8IConnecion.Stop()?= =?UTF-8?q?=E6=97=B6=E5=AF=BC=E8=87=B4=E7=9A=84OnConnStop=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E5=A4=9A=E6=AC=A1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- znet/connection.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/znet/connection.go b/znet/connection.go index c653ac7..d99d285 100644 --- a/znet/connection.go +++ b/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))