File tree 1 file changed +8
-0
lines changed
1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ package protocol
24
24
25
25
import (
26
26
"sort"
27
+ "sync"
27
28
"sync/atomic"
28
29
)
29
30
@@ -32,6 +33,7 @@ type Message struct {
32
33
ID uint64
33
34
Data []byte
34
35
36
+ chunksMutex sync.Mutex
35
37
chunks []chunk
36
38
numberOfChunks uint32
37
39
responseChanClosed int32
@@ -62,6 +64,9 @@ func (m *Message) notifyListener() {
62
64
// addChunk adds the given chunks to the list of chunks of the message.
63
65
// If the given chunk is the first chunk, the expected number of chunks is recorded.
64
66
func (m * Message ) addChunk (c chunk ) {
67
+ m .chunksMutex .Lock ()
68
+ defer m .chunksMutex .Unlock ()
69
+
65
70
m .chunks = append (m .chunks , c )
66
71
if c .IsFirst () {
67
72
m .numberOfChunks = c .NumberOfChunks ()
@@ -73,6 +78,9 @@ func (m *Message) addChunk(c chunk) {
73
78
// is returned.
74
79
// If all chunks are available, the Data field is build and set and true is returned.
75
80
func (m * Message ) assemble () bool {
81
+ m .chunksMutex .Lock ()
82
+ defer m .chunksMutex .Unlock ()
83
+
76
84
if m .Data != nil {
77
85
// Already assembled
78
86
return true
You can’t perform that action at this time.
0 commit comments