mirror of https://github.com/v2ray/v2ray-core
remove context in udp hub
parent
0e8d9ae2bf
commit
278fd7261e
|
@ -1,8 +1,6 @@
|
||||||
package udp
|
package udp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
|
|
||||||
"v2ray.com/core/common/buf"
|
"v2ray.com/core/common/buf"
|
||||||
"v2ray.com/core/common/dice"
|
"v2ray.com/core/common/dice"
|
||||||
"v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
|
@ -75,7 +73,6 @@ type ListenOption struct {
|
||||||
|
|
||||||
type Hub struct {
|
type Hub struct {
|
||||||
conn *net.UDPConn
|
conn *net.UDPConn
|
||||||
cancel context.CancelFunc
|
|
||||||
queue *PayloadQueue
|
queue *PayloadQueue
|
||||||
option ListenOption
|
option ListenOption
|
||||||
}
|
}
|
||||||
|
@ -106,19 +103,16 @@ func ListenUDP(address net.Address, port net.Port, option ListenOption) (*Hub, e
|
||||||
return nil, newError("failed to control socket").Base(err)
|
return nil, newError("failed to control socket").Base(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
|
||||||
hub := &Hub{
|
hub := &Hub{
|
||||||
conn: udpConn,
|
conn: udpConn,
|
||||||
queue: NewPayloadQueue(option),
|
queue: NewPayloadQueue(option),
|
||||||
option: option,
|
option: option,
|
||||||
cancel: cancel,
|
|
||||||
}
|
}
|
||||||
go hub.start(ctx)
|
go hub.start()
|
||||||
return hub, nil
|
return hub, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Hub) Close() error {
|
func (h *Hub) Close() error {
|
||||||
h.cancel()
|
|
||||||
h.conn.Close()
|
h.conn.Close()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -130,16 +124,10 @@ func (h *Hub) WriteTo(payload []byte, dest net.Destination) (int, error) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Hub) start(ctx context.Context) {
|
func (h *Hub) start() {
|
||||||
oobBytes := make([]byte, 256)
|
oobBytes := make([]byte, 256)
|
||||||
L:
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
break L
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
|
|
||||||
|
for {
|
||||||
buffer := buf.New()
|
buffer := buf.New()
|
||||||
var noob int
|
var noob int
|
||||||
var addr *net.UDPAddr
|
var addr *net.UDPAddr
|
||||||
|
@ -153,7 +141,7 @@ L:
|
||||||
if err != nil {
|
if err != nil {
|
||||||
newError("failed to read UDP msg").Base(err).WriteToLog()
|
newError("failed to read UDP msg").Base(err).WriteToLog()
|
||||||
buffer.Release()
|
buffer.Release()
|
||||||
continue
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
payload := Payload{
|
payload := Payload{
|
||||||
|
|
Loading…
Reference in New Issue