Skip to content

Commit ec1091d

Browse files
committed
Constant condition and null-check
1 parent be6bca5 commit ec1091d

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

Protest/Protocols/Telnet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private static async void HandleDownstream(HttpListenerContext ctx, WebSocket ws
131131
int count = stream.Read(data, 0, data.Length);
132132

133133
if (count == 0) { //remote host closed the connection
134-
if (ws.State == WebSocketState.Open) {
134+
if (ws!.State == WebSocketState.Open) {
135135
try {
136136
await ws?.CloseAsync(WebSocketCloseStatus.NormalClosure, String.Empty, CancellationToken.None);
137137
}
@@ -146,7 +146,7 @@ private static async void HandleDownstream(HttpListenerContext ctx, WebSocket ws
146146
if (data[i] > 127) data[i] = 46; //.
147147
}
148148

149-
await ws.SendAsync(new ArraySegment<byte>(data, 0, count), WebSocketMessageType.Text, true, CancellationToken.None);
149+
await ws!.SendAsync(new ArraySegment<byte>(data, 0, count), WebSocketMessageType.Text, true, CancellationToken.None);
150150

151151
//string dataString = Encoding.ASCII.GetString(data, 0, count);
152152
//Console.Write(dataString);

Protest/Tasks/Fetch.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -717,24 +717,26 @@ public static byte[] DevicesTask(string[] hosts, bool dns, bool wmi, bool ldap,
717717
}
718718
}
719719

720-
if (task.cancellationToken.IsCancellationRequested) {
721-
KeepAlive.Broadcast("{\"action\":\"abort-fetch\",\"type\":\"devices\"}"u8.ToArray(), "/fetch/status");
722-
Logger.Action(origin, "Devices fetch task aborted");
720+
if (task is not null) {
721+
if (task.cancellationToken.IsCancellationRequested) {
722+
KeepAlive.Broadcast("{\"action\":\"abort-fetch\",\"type\":\"devices\"}"u8.ToArray(), "/fetch/status");
723+
Logger.Action(origin, "Devices fetch task aborted");
723724

724-
task?.Dispose();
725-
task = null;
726-
return;
727-
}
725+
task?.Dispose();
726+
task = null;
727+
return;
728+
}
728729

729-
result = new Result() {
730-
name = task.name,
731-
type = Type.devices,
732-
started = task.started,
733-
finished = DateTime.UtcNow.Ticks,
734-
dataset = dataset,
735-
successful = task.CompletedSteps,
736-
unsuccessful = task.TotalSteps - task.CompletedSteps,
737-
};
730+
result = new Result() {
731+
name = task.name,
732+
type = Type.devices,
733+
started = task.started,
734+
finished = DateTime.UtcNow.Ticks,
735+
dataset = dataset,
736+
successful = task.CompletedSteps,
737+
unsuccessful = task.TotalSteps - task.CompletedSteps,
738+
};
739+
}
738740

739741
KeepAlive.Broadcast($"{{\"action\":\"finish-fetch\",\"type\":\"devices\",\"task\":{Encoding.UTF8.GetString(Status())}}}", "/fetch/status");
740742
Logger.Action(origin, "Fetch task finished");

Protest/Tasks/Issues.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public static async void WebSocketHandler(HttpListenerContext ctx) {
162162
}
163163
catch { }
164164
finally {
165-
if (ws?.State == WebSocketState.Open) {
165+
if (ws.State == WebSocketState.Open) {
166166
try {
167167
await ws.CloseAsync(WebSocketCloseStatus.NormalClosure, null, CancellationToken.None);
168168
}

0 commit comments

Comments
 (0)