From 889df45920407ff8430bc3532f2ec6843e7aceae Mon Sep 17 00:00:00 2001 From: gufeijun Date: Sun, 21 Feb 2021 15:40:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=A4=E4=B8=AAsendbuf?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=B8=AD=E5=8F=AF=E8=83=BD=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84panic=E5=92=8Cgo=E7=A8=8B=E6=B3=84=E9=9C=B2=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- znet/connection.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/znet/connection.go b/znet/connection.go index 5694129..c653ac7 100644 --- a/znet/connection.go +++ b/znet/connection.go @@ -206,11 +206,11 @@ func (c *Connection) RemoteAddr() net.Addr { //直接将Message数据发送数据给远程的TCP客户端 func (c *Connection) SendMsg(msgId uint32, data []byte) error { c.RLock() + defer c.RUnlock() if c.isClosed == true { - c.RUnlock() return errors.New("connection closed when send msg") } - c.RUnlock() + //将data封包,并且发送 dp := NewDataPack() @@ -228,11 +228,10 @@ func (c *Connection) SendMsg(msgId uint32, data []byte) error { func (c *Connection) SendBuffMsg(msgId uint32, data []byte) error { c.RLock() + defer c.RUnlock() if c.isClosed == true { - c.RUnlock() return errors.New("Connection closed when send buff msg") } - c.RUnlock() //将data封包,并且发送 dp := NewDataPack()