multiple changes

This commit is contained in:
ffdfgdfg
2019-10-12 22:56:37 +08:00
parent 4c8d7b0738
commit 1f8e441090
14 changed files with 176 additions and 33 deletions

View File

@@ -51,15 +51,23 @@ func (Self *PriorityQueue) New() {
func (Self *PriorityQueue) Push(packager *common.MuxPackager) {
Self.mutex.Lock()
if Self.popWait {
defer Self.allowPop()
}
if packager.Flag == common.MUX_CONN_CLOSE {
Self.insert(packager) // the close package may need priority,
// prevent wait too long to close
} else {
switch packager.Flag {
case common.MUX_PING_FLAG, common.MUX_PING_RETURN:
Self.list.PushFront(packager)
// the ping package need highest priority
// prevent ping calculation error
case common.MUX_CONN_CLOSE:
Self.insert(packager)
// the close package may need priority too, set second
// prevent wait too long to close conn
default:
Self.list.PushBack(packager)
}
if Self.popWait {
Self.mutex.Unlock()
Self.allowPop()
return
}
Self.mutex.Unlock()
return
}
@@ -68,7 +76,14 @@ func (Self *PriorityQueue) insert(packager *common.MuxPackager) {
element := Self.list.Back()
for {
if element == nil { // PriorityQueue dose not have any of msg package with this close package id
Self.list.PushFront(packager) // insert close package to first
element = Self.list.Front()
if element != nil {
Self.list.InsertAfter(packager, element)
// insert close package to second
} else {
Self.list.PushFront(packager)
// list is empty, push to front
}
break
}
if element.Value.(*common.MuxPackager).Flag == common.MUX_NEW_MSG &&
@@ -136,11 +151,13 @@ func (Self *FIFOQueue) New() {
func (Self *FIFOQueue) Push(element *ListElement) {
Self.mutex.Lock()
if Self.popWait {
defer Self.allowPop()
}
Self.list = append(Self.list, element)
Self.length += uint32(element.l)
if Self.popWait {
Self.mutex.Unlock()
Self.allowPop()
return
}
Self.mutex.Unlock()
return
}