From 0c64d3e838bcf9c500081fa6ae2cd92fc0335431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=80=9D=E6=95=8F?= Date: Thu, 25 Aug 2022 12:02:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=9F=90=E4=B8=AAcancel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tap.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tap.go b/tap.go index d7e67e8..61c84c8 100644 --- a/tap.go +++ b/tap.go @@ -12,7 +12,6 @@ import ( "github.com/songgao/packets/ethernet" "github.com/songgao/water" "google.golang.org/grpc" - "google.golang.org/grpc/connectivity" "google.golang.org/grpc/credentials/insecure" ) @@ -40,10 +39,6 @@ func (cli *RPCClient) connect() { return } - ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) - defer cancel() - - log.Println(conn.WaitForStateChange(ctx, connectivity.Idle)) cli.conn = conn go cli.run() time.Sleep(time.Millisecond) @@ -59,6 +54,7 @@ func (cli *RPCClient) run() { }() c := gen.NewFrameServiceClient(cli.conn) + ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) defer cancel() stream, err := c.SendFrames(ctx) @@ -144,7 +140,7 @@ func (nc *NetCard) runRead() { framesBytes = append(framesBytes, []byte(rframe)) } - println(len(framesBytes)) + log.Println(len(framesBytes)) if len(framesBytes) > 0 { if nc.cli.conn == nil { nc.cli.connect()