This commit is contained in:
impact-eintr
2022-12-07 19:43:27 +08:00
parent d4d5c61a83
commit de9a9295b5
15 changed files with 2709 additions and 2709 deletions

View File

@@ -1,50 +1,50 @@
package tcp
import (
"netstack/tcpip/header"
"sync"
)
type segmentQueue struct {
mu sync.Mutex
list segmentList // 队列实现
limit int // 队列容量
used int // 队列长度
}
func (q *segmentQueue) empty() bool {
q.mu.Lock()
r := q.used == 0
q.mu.Unlock()
return r
}
func (q *segmentQueue) enqueue(s *segment) bool {
q.mu.Lock()
r := q.used < q.limit
if r {
q.list.PushBack(s)
q.used += s.data.Size() + header.TCPMinimumSize
}
q.mu.Unlock()
return r
}
func (q *segmentQueue) dequeue() *segment {
q.mu.Lock()
s := q.list.Front()
if s != nil {
q.list.Remove(s)
q.used -= s.data.Size() + header.TCPMinimumSize
}
q.mu.Unlock()
return s
}
func (q *segmentQueue) setLimit(limit int) {
q.mu.Lock()
q.limit = limit
q.mu.Unlock()
}
package tcp
import (
"netstack/tcpip/header"
"sync"
)
type segmentQueue struct {
mu sync.Mutex
list segmentList // 队列实现
limit int // 队列容量
used int // 队列长度
}
func (q *segmentQueue) empty() bool {
q.mu.Lock()
r := q.used == 0
q.mu.Unlock()
return r
}
func (q *segmentQueue) enqueue(s *segment) bool {
q.mu.Lock()
r := q.used < q.limit
if r {
q.list.PushBack(s)
q.used += s.data.Size() + header.TCPMinimumSize
}
q.mu.Unlock()
return r
}
func (q *segmentQueue) dequeue() *segment {
q.mu.Lock()
s := q.list.Front()
if s != nil {
q.list.Remove(s)
q.used -= s.data.Size() + header.TCPMinimumSize
}
q.mu.Unlock()
return s
}
func (q *segmentQueue) setLimit(limit int) {
q.mu.Lock()
q.limit = limit
q.mu.Unlock()
}