@@ -200,13 +200,13 @@ namespace ix
200
200
201
201
WebSocketTransport::ReadyState WebSocketTransport::getReadyState () const
202
202
{
203
- std::lock_guard<std::mutex > lock (_setReadyStateMutex );
203
+ std::lock_guard<std::recursive_mutex > lock (_readyStateMutex );
204
204
return _readyState;
205
205
}
206
206
207
207
void WebSocketTransport::setReadyState (ReadyState readyState)
208
208
{
209
- std::lock_guard<std::mutex > lock (_setReadyStateMutex );
209
+ std::lock_guard<std::recursive_mutex > lock (_readyStateMutex );
210
210
211
211
// No state change, return
212
212
if (_readyState == readyState) return ;
@@ -310,7 +310,7 @@ namespace ix
310
310
311
311
WebSocketTransport::PollResult WebSocketTransport::poll ()
312
312
{
313
- if (_readyState == ReadyState::OPEN)
313
+ if (getReadyState () == ReadyState::OPEN)
314
314
{
315
315
if (pingIntervalExceeded ())
316
316
{
@@ -331,7 +331,7 @@ namespace ix
331
331
332
332
// No timeout if state is not OPEN, otherwise computed
333
333
// pingIntervalOrTimeoutGCD (equals to -1 if no ping and no ping timeout are set)
334
- int lastingTimeoutDelayInMs = (_readyState != ReadyState::OPEN) ? 0 : _pingIntervalSecs;
334
+ int lastingTimeoutDelayInMs = (getReadyState () != ReadyState::OPEN) ? 0 : _pingIntervalSecs;
335
335
336
336
if (_pingIntervalSecs > 0 )
337
337
{
@@ -384,7 +384,7 @@ namespace ix
384
384
closeSocket ();
385
385
}
386
386
387
- if (_readyState == ReadyState::CLOSING && closingDelayExceeded ())
387
+ if (getReadyState () == ReadyState::CLOSING && closingDelayExceeded ())
388
388
{
389
389
_rxbuf.clear ();
390
390
// close code and reason were set when calling close()
@@ -700,7 +700,7 @@ namespace ix
700
700
}
701
701
702
702
// We receive a CLOSE frame from remote and are NOT the ones who triggered the close
703
- if (_readyState != ReadyState::CLOSING)
703
+ if (getReadyState () != ReadyState::CLOSING)
704
704
{
705
705
// send back the CLOSE frame
706
706
setReadyState (ReadyState::CLOSING);
@@ -742,15 +742,17 @@ namespace ix
742
742
{
743
743
_rxbuf.clear ();
744
744
745
+ ReadyState rs = getReadyState ();
746
+
745
747
// if we previously closed the connection (CLOSING state), then set state to CLOSED
746
748
// (code/reason were set before)
747
- if (_readyState == ReadyState::CLOSING)
749
+ if (rs == ReadyState::CLOSING)
748
750
{
749
751
closeSocket ();
750
752
setReadyState (ReadyState::CLOSED);
751
753
}
752
754
// if we weren't closing, then close using abnormal close code and message
753
- else if (_readyState != ReadyState::CLOSED)
755
+ else if (rs != ReadyState::CLOSED)
754
756
{
755
757
closeSocketAndSwitchToClosedState (WebSocketCloseConstants::kAbnormalCloseCode ,
756
758
WebSocketCloseConstants::kAbnormalCloseMessage ,
@@ -828,7 +830,8 @@ namespace ix
828
830
bool compress,
829
831
const OnProgressCallback& onProgressCallback)
830
832
{
831
- if (_readyState != ReadyState::OPEN && _readyState != ReadyState::CLOSING)
833
+ ReadyState rs = getReadyState ();
834
+ if (rs != ReadyState::OPEN && rs != ReadyState::CLOSING)
832
835
{
833
836
return WebSocketSendInfo (false );
834
837
}
@@ -1076,7 +1079,7 @@ namespace ix
1076
1079
else if (ret <= 0 )
1077
1080
{
1078
1081
closeSocket ();
1079
- if (_readyState != ReadyState::CLOSING)
1082
+ if (getReadyState () != ReadyState::CLOSING)
1080
1083
{
1081
1084
setReadyState (ReadyState::CLOSED);
1082
1085
}
@@ -1177,7 +1180,8 @@ namespace ix
1177
1180
{
1178
1181
_requestInitCancellation = true ;
1179
1182
1180
- if (_readyState == ReadyState::CLOSING || _readyState == ReadyState::CLOSED)
1183
+ ReadyState rs = getReadyState ();
1184
+ if (rs == ReadyState::CLOSING || rs == ReadyState::CLOSED)
1181
1185
{
1182
1186
// Wake up the socket polling thread, as
1183
1187
// Socket::isReadyToRead() might be still waiting the
0 commit comments