Skip to content

Commit fa83755

Browse files
committed
Fix sonarcloud warning
***NO_CI***
1 parent 7e85b73 commit fa83755

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

Websockets/ReceiveAndControllThread.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,33 +124,43 @@ public ReceiveAndControllThread(WebSocket webSocket)
124124
private void CheckTimeouts(object thread)
125125
{
126126
var receiveThread = (Thread)thread;
127+
128+
#pragma warning disable S3889 // OK to use in .NET nanoFramework context
127129
receiveThread.Suspend();
130+
#pragma warning restore S3889 // Neither "Thread.Resume" nor "Thread.Suspend" should be used
131+
128132
//Controlling ping and ControllerMessagesTimeout
129-
if (_webSocket.Pinging && _webSocket.PingTime.Add(_webSocket.ServerTimeout) < DateTime.UtcNow)
133+
if (_webSocket.Pinging
134+
&& _webSocket.PingTime.Add(_webSocket.ServerTimeout) < DateTime.UtcNow)
130135
{
131136
_webSocket.RawClose(WebSocketCloseStatus.PolicyViolation, Encoding.UTF8.GetBytes("Ping timeout"), true);
132137

133138
Debug.WriteLine($"{_webSocket.RemoteEndPoint} ping timed out");
134139
}
135140

136-
if (_webSocket.State == WebSocketFrame.WebSocketState.CloseSent && _webSocket.ClosingTime.Add(_webSocket.ServerTimeout) < DateTime.UtcNow)
141+
if (_webSocket.State == WebSocketFrame.WebSocketState.CloseSent
142+
&& _webSocket.ClosingTime.Add(_webSocket.ServerTimeout) < DateTime.UtcNow)
137143
{
138144
_webSocket.HardClose();
139145
}
140146

141-
if (_webSocket.KeepAliveInterval != Timeout.InfiniteTimeSpan && _webSocket.State != WebSocketFrame.WebSocketState.CloseSent && !_webSocket.Pinging && _webSocket.LastContactTimeStamp.Add(_webSocket.KeepAliveInterval) < DateTime.UtcNow)
147+
if (_webSocket.KeepAliveInterval != Timeout.InfiniteTimeSpan
148+
&& _webSocket.State != WebSocketFrame.WebSocketState.CloseSent
149+
&& !_webSocket.Pinging
150+
&& _webSocket.LastContactTimeStamp.Add(_webSocket.KeepAliveInterval) < DateTime.UtcNow)
142151
{
143152
_webSocket.SendPing();
144153
}
145154

155+
#pragma warning disable S3889 // OK to use in .NET nanoFramework context
146156
receiveThread.Resume();
147-
157+
#pragma warning restore S3889 // Neither "Thread.Resume" nor "Thread.Suspend" should be used
158+
148159
}
149160

150161
private void OnNewMessage(ReceiveMessageFrame message)
151162
{
152163
_webSocket.CallbacksMessageReceivedEventHandler?.Invoke(_webSocket, new MessageReceivedEventArgs() { Frame = message });
153164
}
154-
155165
}
156166
}

0 commit comments

Comments
 (0)