From 7a164a8dfbe90837f8ef7c8d4848f08d987ba444 Mon Sep 17 00:00:00 2001 From: zhengchong <730427512@qq.com> Date: Sat, 29 May 2021 11:50:49 +0800 Subject: [PATCH] pref: The pack object should not be created frequently --- znet/connection.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/znet/connection.go b/znet/connection.go index f41c568..0881b25 100644 --- a/znet/connection.go +++ b/znet/connection.go @@ -95,13 +95,14 @@ func (c *Connection) StartReader() { defer fmt.Println(c.RemoteAddr().String(), "[conn Reader exit!]") defer c.Stop() + // 创建拆包解包的对象 + dp := NewDataPack() for { select { case <-c.ctx.Done(): return default: - // 创建拆包解包的对象 - dp := NewDataPack() + //读取客户端的Msg head headData := make([]byte, dp.GetHeadLen())