feat: optimize code (#149)

Co-authored-by: wencaiwulue <895703375@qq.com>
This commit is contained in:
naison
2024-02-15 11:38:14 +08:00
committed by GitHub
parent 14e91d5110
commit 3ad6127132
9 changed files with 63 additions and 48 deletions

View File

@@ -142,8 +142,8 @@ func (h *tunHandler) Handle(ctx context.Context, tun net.Conn) {
}
}
func (h tunHandler) printRoute() {
for {
func (h *tunHandler) printRoute(ctx context.Context) {
for ctx.Err() == nil {
select {
case <-time.Tick(time.Second * 5):
var i int
@@ -370,7 +370,7 @@ func (d *Device) SetTunInboundHandler(handler func(tunInbound <-chan *DataElem,
}
func (h *tunHandler) HandleServer(ctx context.Context, tun net.Conn) {
go h.printRoute()
go h.printRoute(ctx)
device := &Device{
tun: tun,