From 7c973404c4cd456e7241d6ae3dd42ae924530434 Mon Sep 17 00:00:00 2001 From: yann Date: Thu, 16 Feb 2023 16:57:18 +0800 Subject: [PATCH 1/2] feat:pendingBaseQueue slice change list --- pending_queue.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/pending_queue.go b/pending_queue.go index 8082cf52..42e0cade 100644 --- a/pending_queue.go +++ b/pending_queue.go @@ -1,41 +1,43 @@ package sctp import ( + "container/list" "errors" ) // pendingBaseQueue type pendingBaseQueue struct { - queue []*chunkPayloadData + queue *list.List } func newPendingBaseQueue() *pendingBaseQueue { - return &pendingBaseQueue{queue: []*chunkPayloadData{}} + return &pendingBaseQueue{queue: list.New()} } func (q *pendingBaseQueue) push(c *chunkPayloadData) { - q.queue = append(q.queue, c) + q.queue.PushBack(c) } func (q *pendingBaseQueue) pop() *chunkPayloadData { - if len(q.queue) == 0 { - return nil - } - c := q.queue[0] - q.queue = q.queue[1:] - return c + c := q.queue.Front() + q.queue.Remove(c) + return c.Value.(*chunkPayloadData) } func (q *pendingBaseQueue) get(i int) *chunkPayloadData { - if len(q.queue) == 0 || i < 0 || i >= len(q.queue) { + if q.queue.Len() == 0 || i < 0 || i >= q.queue.Len() { return nil } - return q.queue[i] + c := q.queue.Front() + for j := 0; j < i; j++ { + c = c.Next() + } + return c.Value.(*chunkPayloadData) } func (q *pendingBaseQueue) size() int { - return len(q.queue) + return q.queue.Len() } // pendingQueue From bfc0280132bfc1e9e190c32ccb7a7a5c9768e595 Mon Sep 17 00:00:00 2001 From: yanzq Date: Thu, 16 Feb 2023 17:49:18 +0800 Subject: [PATCH 2/2] fix:pendingBaseQueue pop --- pending_queue.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pending_queue.go b/pending_queue.go index 42e0cade..994cd6e9 100644 --- a/pending_queue.go +++ b/pending_queue.go @@ -21,6 +21,9 @@ func (q *pendingBaseQueue) push(c *chunkPayloadData) { func (q *pendingBaseQueue) pop() *chunkPayloadData { c := q.queue.Front() + if c == nil { + return nil + } q.queue.Remove(c) return c.Value.(*chunkPayloadData) }