Implement IDisposable

This commit is contained in:
Oliver Booth 2022-11-30 17:56:51 +00:00
parent 656a0b287d
commit 73d0bc8561
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
1 changed files with 8 additions and 1 deletions

View File

@ -4,7 +4,7 @@ using VpSharp.NativeApi;
namespace VpSharp.Internal;
internal sealed class Connection
internal sealed class Connection : IDisposable
{
private readonly object _lockObject;
private readonly Socket _socket;
@ -33,6 +33,12 @@ internal sealed class Connection
return (int) NetworkReturnCode.Success;
}
public void Dispose()
{
_timer?.Dispose();
_socket.Dispose();
}
private static void ConnectCallback(IAsyncResult ar)
{
var connection = ar.AsyncState as Connection;
@ -83,6 +89,7 @@ internal sealed class Connection
var connection = handle.Target as Connection;
connection?.BeforeDestroy();
handle.Free();
connection?.Dispose();
}
private void HandleTimeout()