Fix connectEnabled thread safety; remove unused import; fix docs

Agent-Logs-Url: https://github.com/PepperDash/Essentials/sessions/91306f72-52ee-4cef-97af-49599612d3ed

Co-authored-by: jonnyarndt <21110580+jonnyarndt@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-05-02 20:36:27 +00:00 committed by GitHub
parent 87025b7b0e
commit c713743f13
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 10 deletions

View file

@ -288,7 +288,7 @@ This property maps to the number of the port on the device you have mapped the r
##### TcpSshParams
A ```Ssh```, ```TcpIp```, ```Udp```, or ```UdpServer``` device requires a ```tcpSshProperties``` object to set the propeties of the socket.
A ```Ssh```, ```TcpIp```, ```Udp```, or ```UdpServer``` device requires a ```tcpSshProperties``` object to set the properties of the socket.
```Json
{

View file

@ -4,7 +4,6 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronSockets;
using ThreadingTimeout = System.Threading.Timeout;
using NetSocketException = System.Net.Sockets.SocketException;
@ -22,7 +21,7 @@ namespace PepperDash.Core
private UdpClient client;
private CancellationTokenSource receiveCancellationTokenSource;
private bool connectEnabled;
private bool _connectEnabled;
private bool connectionRefusedLogged;
private SocketStatus clientStatus = SocketStatus.SOCKET_STATUS_NO_CONNECT;
@ -124,6 +123,15 @@ namespace PepperDash.Core
get { return (ushort)ClientStatus; }
}
/// <summary>
/// Will be set and unset by Connect and Disconnect only
/// </summary>
public bool ConnectEnabled
{
get { lock (stateLock) { return _connectEnabled; } }
private set { lock (stateLock) { _connectEnabled = value; } }
}
/// <summary>
/// Gets or sets the AutoReconnect
/// </summary>
@ -158,7 +166,7 @@ namespace PepperDash.Core
reconnectTimer = new Timer(o =>
{
if (connectEnabled)
if (ConnectEnabled)
Connect();
}, null, ThreadingTimeout.Infinite, ThreadingTimeout.Infinite);
}
@ -176,7 +184,7 @@ namespace PepperDash.Core
reconnectTimer = new Timer(o =>
{
if (connectEnabled)
if (ConnectEnabled)
Connect();
}, null, ThreadingTimeout.Infinite, ThreadingTimeout.Infinite);
}
@ -226,10 +234,10 @@ namespace PepperDash.Core
return;
}
ConnectEnabled = true;
lock (stateLock)
{
connectEnabled = true;
if (client != null)
return;
@ -259,9 +267,10 @@ namespace PepperDash.Core
/// </summary>
public void Disconnect()
{
ConnectEnabled = false;
lock (stateLock)
{
connectEnabled = false;
reconnectTimer.Change(ThreadingTimeout.Infinite, ThreadingTimeout.Infinite);
CleanupClient();
ClientStatus = SocketStatus.SOCKET_STATUS_NO_CONNECT;
@ -382,7 +391,7 @@ namespace PepperDash.Core
private void StartReconnectTimer()
{
if (AutoReconnect && connectEnabled)
if (AutoReconnect && ConnectEnabled)
reconnectTimer.Change(AutoReconnectIntervalMs, ThreadingTimeout.Infinite);
}