From d4262b08ef472c5e8c51fb0e00e2178285d2a84f Mon Sep 17 00:00:00 2001 From: fumiama Date: Fri, 31 Dec 2021 14:24:08 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=88=86=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lower/nic.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lower/nic.go b/lower/nic.go index 354c679..3af7226 100644 --- a/lower/nic.go +++ b/lower/nic.go @@ -5,6 +5,7 @@ import ( "os" "os/exec" "strconv" + "time" "github.com/fumiama/water" "github.com/fumiama/water/waterutil" @@ -62,7 +63,11 @@ func (nc *NIC) Start(m *link.Me) { buf2 := make([]byte, m.MTU()+68) // 增加报头长度与 TEA 冗余 off := 0 isrev := false - for nc.hasstart { // 从 NIC 发送 + t := time.NewTimer(time.Millisecond) + for range t.C { // 从 NIC 发送 + if !nc.hasstart { + break + } var packet []byte if off > 0 && !isrev { packet = buf2 @@ -141,8 +146,12 @@ func (nc *NIC) send(m *link.Me, packet []byte) (n int, rem []byte) { if int(totl) > len(packet) { buf := make([]byte, int(totl)) copy(buf, packet) - nc.ifce.Read(buf[len(packet):]) - packet = buf + cnt, err := nc.ifce.Read(buf[len(packet):]) + if err != nil { + rem = packet + return + } + packet = buf[:cnt+len(packet)] } rem = packet[totl:] packet = packet[:totl]