From d9af02812f22aad5d415fb0b01b855d21c2d1078 Mon Sep 17 00:00:00 2001 From: rurirei <72071920+rurirei@users.noreply.github.com> Date: Sat, 6 May 2023 03:18:08 +0000 Subject: [PATCH] Add ctx to UDP dispatcherConn (#2024) --- transport/internet/udp/dispatcher.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/transport/internet/udp/dispatcher.go b/transport/internet/udp/dispatcher.go index 48b90b63..32c8c8ac 100644 --- a/transport/internet/udp/dispatcher.go +++ b/transport/internet/udp/dispatcher.go @@ -142,12 +142,14 @@ type dispatcherConn struct { dispatcher *Dispatcher cache chan *udp.Packet done *done.Instance + ctx context.Context } func DialDispatcher(ctx context.Context, dispatcher routing.Dispatcher) (net.PacketConn, error) { c := &dispatcherConn{ cache: make(chan *udp.Packet, 16), done: done.New(), + ctx: ctx, } d := &Dispatcher{ @@ -197,8 +199,7 @@ func (c *dispatcherConn) WriteTo(p []byte, addr net.Addr) (int, error) { n := copy(raw, p) buffer.Resize(0, int32(n)) - ctx := context.Background() - c.dispatcher.Dispatch(ctx, net.DestinationFromAddr(addr), buffer) + c.dispatcher.Dispatch(c.ctx, net.DestinationFromAddr(addr), buffer) return n, nil }