mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-22 16:41:29 +00:00
Add ctx to UDP dispatcherConn (#2024)
This commit is contained in:
parent
6cc5d1de44
commit
d9af02812f
|
@ -142,12 +142,14 @@ type dispatcherConn struct {
|
||||||
dispatcher *Dispatcher
|
dispatcher *Dispatcher
|
||||||
cache chan *udp.Packet
|
cache chan *udp.Packet
|
||||||
done *done.Instance
|
done *done.Instance
|
||||||
|
ctx context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func DialDispatcher(ctx context.Context, dispatcher routing.Dispatcher) (net.PacketConn, error) {
|
func DialDispatcher(ctx context.Context, dispatcher routing.Dispatcher) (net.PacketConn, error) {
|
||||||
c := &dispatcherConn{
|
c := &dispatcherConn{
|
||||||
cache: make(chan *udp.Packet, 16),
|
cache: make(chan *udp.Packet, 16),
|
||||||
done: done.New(),
|
done: done.New(),
|
||||||
|
ctx: ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
d := &Dispatcher{
|
d := &Dispatcher{
|
||||||
|
@ -197,8 +199,7 @@ func (c *dispatcherConn) WriteTo(p []byte, addr net.Addr) (int, error) {
|
||||||
n := copy(raw, p)
|
n := copy(raw, p)
|
||||||
buffer.Resize(0, int32(n))
|
buffer.Resize(0, int32(n))
|
||||||
|
|
||||||
ctx := context.Background()
|
c.dispatcher.Dispatch(c.ctx, net.DestinationFromAddr(addr), buffer)
|
||||||
c.dispatcher.Dispatch(ctx, net.DestinationFromAddr(addr), buffer)
|
|
||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue