|
|
@@ -6,6 +6,7 @@ package splithttp
|
|
|
import (
|
|
|
"container/heap"
|
|
|
"io"
|
|
|
+ "sync"
|
|
|
|
|
|
"github.com/xtls/xray-core/common/errors"
|
|
|
)
|
|
|
@@ -16,11 +17,12 @@ type Packet struct {
|
|
|
}
|
|
|
|
|
|
type uploadQueue struct {
|
|
|
- pushedPackets chan Packet
|
|
|
- heap uploadHeap
|
|
|
- nextSeq uint64
|
|
|
- closed bool
|
|
|
- maxPackets int
|
|
|
+ pushedPackets chan Packet
|
|
|
+ writeCloseMutex sync.Mutex
|
|
|
+ heap uploadHeap
|
|
|
+ nextSeq uint64
|
|
|
+ closed bool
|
|
|
+ maxPackets int
|
|
|
}
|
|
|
|
|
|
func NewUploadQueue(maxPackets int) *uploadQueue {
|
|
|
@@ -34,6 +36,9 @@ func NewUploadQueue(maxPackets int) *uploadQueue {
|
|
|
}
|
|
|
|
|
|
func (h *uploadQueue) Push(p Packet) error {
|
|
|
+ h.writeCloseMutex.Lock()
|
|
|
+ defer h.writeCloseMutex.Unlock()
|
|
|
+
|
|
|
if h.closed {
|
|
|
return errors.New("splithttp packet queue closed")
|
|
|
}
|
|
|
@@ -43,6 +48,9 @@ func (h *uploadQueue) Push(p Packet) error {
|
|
|
}
|
|
|
|
|
|
func (h *uploadQueue) Close() error {
|
|
|
+ h.writeCloseMutex.Lock()
|
|
|
+ defer h.writeCloseMutex.Unlock()
|
|
|
+
|
|
|
h.closed = true
|
|
|
close(h.pushedPackets)
|
|
|
return nil
|