Skip to content

Commit 6ef5c76

Browse files
committed
call _cancellationTokenSource Dispose and pass it on socket connect method
1 parent 5ad82b7 commit 6ef5c76

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/OpenRGB.NET/OpenRGBClient.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void Connect()
7979
if (Connected)
8080
return;
8181

82-
_socket.Connect(_ip, _port, _timeoutMs);
82+
_socket.Connect(_ip, _port, _timeoutMs, _cancellationTokenSource.Token);
8383
_readLoopTask = Task.Run(ReadLoop);
8484

8585
var length = PacketHeader.Length + PacketFactory.GetStringOperationLength(_name);
@@ -504,6 +504,7 @@ public void PluginSpecific(int pluginId, int pluginPacketType, ReadOnlySpan<byte
504504
public void Dispose()
505505
{
506506
_cancellationTokenSource.Cancel();
507+
_cancellationTokenSource.Dispose();
507508

508509
try
509510
{

src/OpenRGB.NET/Utils/SocketExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
using System;
22
using System.Net.Sockets;
3+
using System.Threading;
34
using System.Threading.Tasks;
45

56
namespace OpenRGB.NET.Utils;
67

78
internal static class SocketExtensions
89
{
9-
public static void Connect(this Socket socket, string host, int port, int timeoutMs)
10+
public static void Connect(this Socket socket, string host, int port, int timeoutMs, CancellationToken cancellationToken)
1011
{
1112
var result = socket.ConnectAsync(host, port);
12-
Task.WaitAny(new[] { result }, timeoutMs);
13+
Task.WaitAny([result], timeoutMs, cancellationToken);
1314

1415
if (socket.Connected)
1516
return;

0 commit comments

Comments
 (0)