From 5ef9e2c42dd20909a89337c1b689168f0c7e65e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=80=9D=E6=95=8F?= Date: Thu, 1 Sep 2022 15:09:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0TAP=E6=B5=8B=E8=AF=95(TODO=20=E8=A7=A3?= =?UTF-8?q?=E6=9E=90arp)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rpc_client.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/rpc_client.go b/rpc_client.go index 975f979..3001de0 100644 --- a/rpc_client.go +++ b/rpc_client.go @@ -58,7 +58,11 @@ func (cli *RPCClient) CheckConnect() { return } - cli.conn = conn + cli.Lock(func() bool { + cli.conn = conn + return true + }) + go cli.run() } @@ -99,16 +103,22 @@ func (cli *RPCClient) run() { buf := bytes.NewBuffer(nil) for { + select { case <-cli.trigger: case <-ticker.C: } - cli.Lock(func() bool { + if !cli.Lock(func() bool { + if len(cli.Frames) == 0 { + return false + } Compress(buf, cli.Frames) cli.Frames = cli.Frames[:0] return true - }) + }) { + continue + } // 发到对面的网卡 err = stream.Send(&gen.RequestFrames{ @@ -117,7 +127,6 @@ func (cli *RPCClient) run() { if err != nil { log.Panic(err) } - buf.Reset() } }