Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
veniware committed Apr 18, 2024
1 parent d6c3130 commit 360b755
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 19 deletions.
10 changes: 4 additions & 6 deletions Protest/Http/Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,12 @@ public static byte[] Minify(byte[] bytes, bool softMinify) {
public static byte[] GZip(byte[] bytes) {
if (bytes is null) return Array.Empty<byte>();

MemoryStream ms = new MemoryStream();
using (GZipStream zip = new GZipStream(ms, CompressionMode.Compress, true)) {
zip.Write(bytes, 0, bytes.Length);
}
using MemoryStream ms = new MemoryStream();
using GZipStream zip = new GZipStream(ms, CompressionMode.Compress, true);
zip.Write(bytes, 0, bytes.Length);

byte[] array = ms.ToArray();
ms.Dispose();


return array;
}
public static byte[] UnGZip(byte[] bytes) {
Expand Down
2 changes: 1 addition & 1 deletion Protest/Http/KeepAlive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public static async Task CloseConnection(string sessionId) {
pair.Value.ws.SendAsync(MSG_FORCE_RELOAD, WebSocketMessageType.Text, true, CancellationToken.None);
}
await pair.Value.ws.CloseAsync(WebSocketCloseStatus.NormalClosure, null, CancellationToken.None);
pair.Value.ws.Dispose();
pair.Value.ws?.Dispose();
}

connections.TryRemove(pair.Key, out _);
Expand Down
1 change: 0 additions & 1 deletion Protest/Http/Listener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ private static readonly Dictionary<string, Func<HttpListenerContext, Dictionary<
{ "/log/list", (ctx, parameters, username) => Logger.List(parameters) },
};


public Listener(string ip, ushort port, string path) {
if (!HttpListener.IsSupported) throw new NotSupportedException();
cache = new Cache(path);
Expand Down
5 changes: 1 addition & 4 deletions Protest/Protocols/Icmp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private static async Task<string> PingArrayAsync(string[] name, string[] id, int
return String.Join((char)127, result);
}
private static async Task<string> PingAsync(string hostname, string id, int timeout) {
Ping p = new Ping();
using Ping p = new Ping();

try {
PingReply reply = await p.SendPingAsync(hostname, timeout, ICMP_PAYLOAD);
Expand All @@ -195,9 +195,6 @@ private static async Task<string> PingAsync(string hostname, string id, int time
catch (Exception) {
return id + ((char)127).ToString() + "Unknown error";
}
finally {
p.Dispose();
}
}

private static async Task<string> ArpPingArrayAsync(string[] name, string[] id) {
Expand Down
2 changes: 1 addition & 1 deletion Protest/Tasks/Fetch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ public static byte[] DevicesTask(string[] hosts, bool dns, bool wmi, bool kerber
KeepAlive.Broadcast("{\"action\":\"abort-fetch\",\"type\":\"devices\"}"u8.ToArray(), "/fetch/status");
Logger.Action(origin, "Devices fetch task aborted");

task.Dispose();
task?.Dispose();
task = null;
return;
}
Expand Down
2 changes: 1 addition & 1 deletion Protest/Tasks/Lifeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private static void LifelineLoop() {
task.Sleep(Math.Max((int)((FOUR_HOURS_IN_TICKS - (DateTime.UtcNow.Ticks - startTimeStamp)) / 10_000), 0));

if (task.cancellationToken.IsCancellationRequested) {
task.Dispose();
task?.Dispose();
task = null;
return;
}
Expand Down
2 changes: 1 addition & 1 deletion Protest/Tasks/Watchdog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private static void WatchLoop() {
task.Sleep(Math.Max(nextSleep - (int)((DateTime.UtcNow.Ticks - loopStartTimeStamp) / 10_000), 0));

if (task.cancellationToken.IsCancellationRequested) {
task.Dispose();
task?.Dispose();
task = null;
return;
}
Expand Down
5 changes: 1 addition & 4 deletions Protest/Tools/Monitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public static async void WebSocketHandler(HttpListenerContext ctx) {
}

private static long HandlePing(string host, int timeout) {
Ping p = new Ping();
using Ping p = new Ping();
try {
PingReply reply = p.Send(host, timeout);

Expand All @@ -336,9 +336,6 @@ private static long HandlePing(string host, int timeout) {
catch (Exception) {
return -1;
}
finally {
p.Dispose();
}
}

[SupportedOSPlatform("windows")]
Expand Down

0 comments on commit 360b755

Please sign in to comment.