hotfix: close chan (#245)

This commit is contained in:
naison
2024-05-13 19:58:56 +08:00
committed by GitHub
parent e7f00f5899
commit 3e51bf0f4d
15 changed files with 163 additions and 46 deletions

View File

@@ -193,10 +193,10 @@ func (d *Device) readFromTun() {
return
}
if n != 0 {
d.tunInboundRaw <- &DataElem{
util.SafeWrite(d.tunInboundRaw, &DataElem{
data: b[:],
length: n,
}
})
}
}
}
@@ -238,12 +238,16 @@ func (d *Device) parseIPHeader(ctx context.Context) {
}
log.Debugf("[tun] %s --> %s, length: %d", e.src, e.dst, e.length)
d.tunInbound <- e
util.SafeWrite(d.tunInbound, e)
}
}
func (d *Device) Close() {
d.tun.Close()
util.SafeClose(d.tunInbound)
util.SafeClose(d.tunOutbound)
util.SafeClose(d.tunInboundRaw)
util.SafeClose(Chan)
}
func heartbeats(ctx context.Context, tun net.Conn, in chan<- *DataElem) {
@@ -300,12 +304,12 @@ func heartbeats(ctx context.Context, tun net.Conn, in chan<- *DataElem) {
} else {
src, dst = srcIPv6, config.RouterIP6
}
in <- &DataElem{
util.SafeWrite(in, &DataElem{
data: data[:],
length: length,
src: src,
dst: dst,
}
})
}
time.Sleep(time.Second)
}