remove context in udp hub

pull/861/head
Darien Raymond 2018-02-08 22:09:41 +01:00
parent 0e8d9ae2bf
commit 278fd7261e
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
1 changed files with 4 additions and 16 deletions

View File

@ -1,8 +1,6 @@
package udp
import (
"context"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/dice"
"v2ray.com/core/common/net"
@ -75,7 +73,6 @@ type ListenOption struct {
type Hub struct {
conn *net.UDPConn
cancel context.CancelFunc
queue *PayloadQueue
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)
}
}
ctx, cancel := context.WithCancel(context.Background())
hub := &Hub{
conn: udpConn,
queue: NewPayloadQueue(option),
option: option,
cancel: cancel,
}
go hub.start(ctx)
go hub.start()
return hub, nil
}
func (h *Hub) Close() error {
h.cancel()
h.conn.Close()
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)
L:
for {
select {
case <-ctx.Done():
break L
default:
}
for {
buffer := buf.New()
var noob int
var addr *net.UDPAddr
@ -153,7 +141,7 @@ L:
if err != nil {
newError("failed to read UDP msg").Base(err).WriteToLog()
buffer.Release()
continue
break
}
payload := Payload{