Skip to content

Commit

Permalink
Don't ignore context in DialUDP
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Aug 28, 2021
1 parent 5f767d1 commit 03170d9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions transport/internet/udp/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,15 @@ func handleInput(ctx context.Context, conn *connEntry, dest net.Destination, cal
}

type dispatcherConn struct {
ctx context.Context
dispatcher *Dispatcher
cache chan *udp.Packet
done *done.Instance
}

func DialDispatcher(ctx context.Context, dispatcher routing.Dispatcher) (net.PacketConn, error) {
c := &dispatcherConn{
ctx: ctx,
cache: make(chan *udp.Packet, 16),
done: done.New(),
}
Expand Down Expand Up @@ -168,8 +170,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
}

Expand Down

0 comments on commit 03170d9

Please sign in to comment.