mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 10:08:15 -05:00
simplify udp payload queue
This commit is contained in:
parent
1a1383c2ea
commit
292176c57f
@ -23,13 +23,11 @@ type UDPPayloadHandler func(*alloc.Buffer, *proxy.SessionInfo)
|
||||
type UDPPayloadQueue struct {
|
||||
queue []chan UDPPayload
|
||||
callback UDPPayloadHandler
|
||||
cancel *signal.CancelSignal
|
||||
}
|
||||
|
||||
func NewUDPPayloadQueue(option ListenOption) *UDPPayloadQueue {
|
||||
queue := &UDPPayloadQueue{
|
||||
callback: option.Callback,
|
||||
cancel: signal.NewCloseSignal(),
|
||||
queue: make([]chan UDPPayload, option.Concurrency),
|
||||
}
|
||||
for i := range queue.queue {
|
||||
@ -56,24 +54,15 @@ func (this *UDPPayloadQueue) Enqueue(payload UDPPayload) {
|
||||
}
|
||||
|
||||
func (this *UDPPayloadQueue) Dequeue(queue <-chan UDPPayload) {
|
||||
this.cancel.WaitThread()
|
||||
defer this.cancel.FinishThread()
|
||||
|
||||
for !this.cancel.Cancelled() {
|
||||
payload, open := <-queue
|
||||
if !open {
|
||||
return
|
||||
}
|
||||
for payload := range queue {
|
||||
this.callback(payload.payload, payload.session)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *UDPPayloadQueue) Close() {
|
||||
this.cancel.Cancel()
|
||||
for _, queue := range this.queue {
|
||||
close(queue)
|
||||
}
|
||||
this.cancel.WaitForDone()
|
||||
}
|
||||
|
||||
type ListenOption struct {
|
||||
|
Loading…
Reference in New Issue
Block a user