@@ -26,12 +26,13 @@ type websocketConnection struct {
26
26
shipWriteChannel chan []byte
27
27
28
28
// internal handling of closed connections
29
- isConnectionClosed bool
29
+ connectionClosed bool
30
30
31
31
remoteSki string
32
32
33
- mux sync.Mutex
34
- shutdownOnce sync.Once
33
+ muxConnClosed sync.Mutex
34
+ muxShipWrite sync.Mutex
35
+ shutdownOnce sync.Once
35
36
}
36
37
37
38
// create a new websocket based shipDataProcessing implementation
@@ -44,10 +45,18 @@ func NewWebsocketConnection(conn *websocket.Conn, remoteSki string) *websocketCo
44
45
45
46
// check if the websocket connection is closed
46
47
func (w * websocketConnection ) isConnClosed () bool {
47
- w .mux .Lock ()
48
- defer w .mux .Unlock ()
48
+ w .muxConnClosed .Lock ()
49
+ defer w .muxConnClosed .Unlock ()
49
50
50
- return w .isConnectionClosed
51
+ return w .connectionClosed
52
+ }
53
+
54
+ // check if the websocket connection is closed
55
+ func (w * websocketConnection ) setConnClosed () {
56
+ w .muxConnClosed .Lock ()
57
+ defer w .muxConnClosed .Unlock ()
58
+
59
+ w .connectionClosed = true
51
60
}
52
61
53
62
func (w * websocketConnection ) run () {
@@ -161,7 +170,9 @@ func (w *websocketConnection) close() {
161
170
return
162
171
}
163
172
164
- w .mux .Lock ()
173
+ w .setConnClosed ()
174
+
175
+ w .muxShipWrite .Lock ()
165
176
166
177
if ! util .IsChannelClosed (w .closeChannel ) {
167
178
close (w .closeChannel )
@@ -177,9 +188,7 @@ func (w *websocketConnection) close() {
177
188
w .conn .Close ()
178
189
}
179
190
180
- w .isConnectionClosed = true
181
-
182
- w .mux .Unlock ()
191
+ w .muxShipWrite .Unlock ()
183
192
})
184
193
}
185
194
@@ -197,8 +206,8 @@ func (w *websocketConnection) WriteMessageToDataConnection(message []byte) error
197
206
return errors .New ("connection is closed" )
198
207
}
199
208
200
- w .mux .Lock ()
201
- defer w .mux .Unlock ()
209
+ w .muxShipWrite .Lock ()
210
+ defer w .muxShipWrite .Unlock ()
202
211
203
212
if w .conn == nil || w .shipWriteChannel == nil {
204
213
return errors .New ("connection is closed" )
0 commit comments