From 03eb17436a584457cf23cb76e2e5acd2937911fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=80=9D=E6=95=8F?= Date: Mon, 29 Aug 2022 10:45:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- device.go | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/device.go b/device.go index f9f6707..359edea 100644 --- a/device.go +++ b/device.go @@ -184,14 +184,11 @@ func (nc *NetCard) runRead() { for atomic.LoadInt32(&isLoop) > 0 { var rframe ethernet.Frame rframe.Resize(1500) - - nc.Lock(func() { - n, err := ifce.Read([]byte(rframe)) - if err != nil { - log.Fatal(err) - } - rframe = rframe[:n] - }) + n, err := ifce.Read([]byte(rframe)) + if err != nil { + log.Fatal(err) + } + rframe = rframe[:n] if !waterutil.IsIPv4(rframe) || waterutil.IPv4Source(rframe).Equal(net.IPv4(0, 0, 0, 0)) { continue @@ -204,6 +201,7 @@ func (nc *NetCard) runRead() { } }) if realAddr == "" { + log.Printf("%s is not exists", waterutil.IPv4Destination(rframe)) continue } @@ -272,14 +270,12 @@ func (nc *NetCard) runWrite() { log.Printf("get wframes decode len: %d", len(bufs[0])) - nc.Lock(func() { - for _, buf := range bufs { - _, err := ifce.Write(buf) - if err != nil { - log.Panic(err) - } + for _, buf := range bufs { + _, err := ifce.Write(buf) + if err != nil { + log.Panic(err) } - }) + } }