mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-08-31 19:08:29 +00:00
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:
parent
87025b7b0e
commit
c713743f13
2 changed files with 19 additions and 10 deletions
|
|
@ -188,7 +188,7 @@ namespace PepperDash.Core
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
These enumerations are not case sensitive. Not all methods are valid for a ```genericComm``` device. For a comport, the only valid type would be ```Com```. For a direct network socket, valid options are ```Ssh```, ```Tcpip```, ```Telnet```, ```Udp```, and ```UdpServer```.
|
These enumerations are not case sensitive. Not all methods are valid for a ```genericComm``` device. For a comport, the only valid type would be ```Com```. For a direct network socket, valid options are ```Ssh```, ```Tcpip```, ```Telnet```, ```Udp```, and ```UdpServer```.
|
||||||
|
|
||||||
##### ComParams
|
##### ComParams
|
||||||
|
|
||||||
|
|
@ -288,7 +288,7 @@ This property maps to the number of the port on the device you have mapped the r
|
||||||
|
|
||||||
##### TcpSshParams
|
##### 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
|
```Json
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.CrestronSockets;
|
|
||||||
using ThreadingTimeout = System.Threading.Timeout;
|
using ThreadingTimeout = System.Threading.Timeout;
|
||||||
using NetSocketException = System.Net.Sockets.SocketException;
|
using NetSocketException = System.Net.Sockets.SocketException;
|
||||||
|
|
||||||
|
|
@ -22,7 +21,7 @@ namespace PepperDash.Core
|
||||||
|
|
||||||
private UdpClient client;
|
private UdpClient client;
|
||||||
private CancellationTokenSource receiveCancellationTokenSource;
|
private CancellationTokenSource receiveCancellationTokenSource;
|
||||||
private bool connectEnabled;
|
private bool _connectEnabled;
|
||||||
private bool connectionRefusedLogged;
|
private bool connectionRefusedLogged;
|
||||||
private SocketStatus clientStatus = SocketStatus.SOCKET_STATUS_NO_CONNECT;
|
private SocketStatus clientStatus = SocketStatus.SOCKET_STATUS_NO_CONNECT;
|
||||||
|
|
||||||
|
|
@ -124,6 +123,15 @@ namespace PepperDash.Core
|
||||||
get { return (ushort)ClientStatus; }
|
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>
|
/// <summary>
|
||||||
/// Gets or sets the AutoReconnect
|
/// Gets or sets the AutoReconnect
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -158,7 +166,7 @@ namespace PepperDash.Core
|
||||||
|
|
||||||
reconnectTimer = new Timer(o =>
|
reconnectTimer = new Timer(o =>
|
||||||
{
|
{
|
||||||
if (connectEnabled)
|
if (ConnectEnabled)
|
||||||
Connect();
|
Connect();
|
||||||
}, null, ThreadingTimeout.Infinite, ThreadingTimeout.Infinite);
|
}, null, ThreadingTimeout.Infinite, ThreadingTimeout.Infinite);
|
||||||
}
|
}
|
||||||
|
|
@ -176,7 +184,7 @@ namespace PepperDash.Core
|
||||||
|
|
||||||
reconnectTimer = new Timer(o =>
|
reconnectTimer = new Timer(o =>
|
||||||
{
|
{
|
||||||
if (connectEnabled)
|
if (ConnectEnabled)
|
||||||
Connect();
|
Connect();
|
||||||
}, null, ThreadingTimeout.Infinite, ThreadingTimeout.Infinite);
|
}, null, ThreadingTimeout.Infinite, ThreadingTimeout.Infinite);
|
||||||
}
|
}
|
||||||
|
|
@ -226,10 +234,10 @@ namespace PepperDash.Core
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConnectEnabled = true;
|
||||||
|
|
||||||
lock (stateLock)
|
lock (stateLock)
|
||||||
{
|
{
|
||||||
connectEnabled = true;
|
|
||||||
|
|
||||||
if (client != null)
|
if (client != null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -259,9 +267,10 @@ namespace PepperDash.Core
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Disconnect()
|
public void Disconnect()
|
||||||
{
|
{
|
||||||
|
ConnectEnabled = false;
|
||||||
|
|
||||||
lock (stateLock)
|
lock (stateLock)
|
||||||
{
|
{
|
||||||
connectEnabled = false;
|
|
||||||
reconnectTimer.Change(ThreadingTimeout.Infinite, ThreadingTimeout.Infinite);
|
reconnectTimer.Change(ThreadingTimeout.Infinite, ThreadingTimeout.Infinite);
|
||||||
CleanupClient();
|
CleanupClient();
|
||||||
ClientStatus = SocketStatus.SOCKET_STATUS_NO_CONNECT;
|
ClientStatus = SocketStatus.SOCKET_STATUS_NO_CONNECT;
|
||||||
|
|
@ -382,7 +391,7 @@ namespace PepperDash.Core
|
||||||
|
|
||||||
private void StartReconnectTimer()
|
private void StartReconnectTimer()
|
||||||
{
|
{
|
||||||
if (AutoReconnect && connectEnabled)
|
if (AutoReconnect && ConnectEnabled)
|
||||||
reconnectTimer.Change(AutoReconnectIntervalMs, ThreadingTimeout.Infinite);
|
reconnectTimer.Change(AutoReconnectIntervalMs, ThreadingTimeout.Infinite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue