From efdaea1b5ecb00c9de739d54d16718f417deadeb Mon Sep 17 00:00:00 2001 From: Arceliar Date: Thu, 2 May 2019 17:37:49 -0500 Subject: [PATCH] fix some races and GetBytes/PutBytes usage, but this still seems to deadlock somewhere in iperf tests --- src/tuntap/conn.go | 5 +++-- src/tuntap/iface.go | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/tuntap/conn.go b/src/tuntap/conn.go index e59e560e..ae8fcc0b 100644 --- a/src/tuntap/conn.go +++ b/src/tuntap/conn.go @@ -3,6 +3,7 @@ package tuntap import ( "errors" + "github.com/yggdrasil-network/yggdrasil-go/src/util" "github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil" ) @@ -40,7 +41,7 @@ func (s *tunConn) reader() error { select { case <-read: if n > 0 { - s.tun.send <- b[:n] + s.tun.send <- append(util.GetBytes(), b[:n]...) } case <-s.stop: s.tun.log.Debugln("Stopping conn reader for", s) @@ -68,8 +69,8 @@ func (s *tunConn) writer() error { } if _, err := s.conn.Write(b); err != nil { s.tun.log.Errorln(s.conn.String(), "TUN/TAP conn write error:", err) - continue } + util.PutBytes(b) } } } diff --git a/src/tuntap/iface.go b/src/tuntap/iface.go index d837633b..5b8e77bb 100644 --- a/src/tuntap/iface.go +++ b/src/tuntap/iface.go @@ -95,6 +95,7 @@ func (tun *TunAdapter) writer() error { } } else { w, err = tun.iface.Write(b[:n]) + util.PutBytes(b) } if err != nil { tun.log.Errorln("TUN/TAP iface write error:", err) @@ -219,9 +220,11 @@ func (tun *TunAdapter) reader() error { } // If we have a connection now, try writing to it if isIn && session != nil { + packet := append(util.GetBytes(), bs[:n]...) select { - case session.send <- bs[:n]: + case session.send <- packet: default: + util.PutBytes(packet) } }