Skip to content

Commit

Permalink
NuGet v3.0.17, minor fixes and small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jchristn committed Dec 23, 2024
1 parent 2a26a5c commit 3f12d8a
Show file tree
Hide file tree
Showing 24 changed files with 972 additions and 179 deletions.
12 changes: 6 additions & 6 deletions src/ClientTest/Client.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using SuperSimpleTcp;
using System;
using System.Collections.Generic;
using System.Text;

namespace ClientTest
namespace ClientTest
{
using SuperSimpleTcp;
using System;
using System.Collections.Generic;
using System.Text;

class Program
{
static string _ServerIp;
Expand Down
2 changes: 1 addition & 1 deletion src/ClientTest/ClientTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net461;net48;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net461;net48;net6.0;net8.0</TargetFrameworks>
<AssemblyName>Client</AssemblyName>
</PropertyGroup>

Expand Down
14 changes: 7 additions & 7 deletions src/ServerTest/Server.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using SuperSimpleTcp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ServerTest
namespace ServerTest
{
using SuperSimpleTcp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
static string _ListenerIp;
Expand Down
2 changes: 1 addition & 1 deletion src/ServerTest/ServerTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net461;net48;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net461;net48;net6.0;net8.0</TargetFrameworks>
<AssemblyName>Server</AssemblyName>
</PropertyGroup>

Expand Down
14 changes: 8 additions & 6 deletions src/SuperSimpleTcp.UnitTest/IntegrationTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SuperSimpleTcp.UnitTest
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using DataReceivedEventArgs = SuperSimpleTcp.DataReceivedEventArgs;

[TestClass]
public class IntegrationTest
{
Expand Down
14 changes: 7 additions & 7 deletions src/SuperSimpleTcp.UnitTest/ServerSettingsTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace SuperSimpleTcp.UnitTest
namespace SuperSimpleTcp.UnitTest
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

[TestClass]
public class ServerSettingsTest
{
Expand Down
8 changes: 4 additions & 4 deletions src/SuperSimpleTcp.UnitTest/ServerTest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Threading.Tasks;

namespace SuperSimpleTcp.UnitTest
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Threading.Tasks;

[TestClass]
public class ServerTest
{
Expand Down
8 changes: 4 additions & 4 deletions src/SuperSimpleTcp.UnitTest/StringHelper.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Linq;

namespace SuperSimpleTcp.UnitTest
namespace SuperSimpleTcp.UnitTest
{
using System;
using System.Linq;

internal static class StringHelper
{
private static Random _random = new Random();
Expand Down
6 changes: 3 additions & 3 deletions src/SuperSimpleTcp.UnitTest/TestCertificateHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.IO;

namespace SuperSimpleTcp.UnitTest
namespace SuperSimpleTcp.UnitTest
{
using System.IO;

public static class TestCertificateHelper
{
public static void CreateCertificate(string certificateFilePath)
Expand Down
12 changes: 6 additions & 6 deletions src/SuperSimpleTcp/ClientMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Net.Security;
using System.Net.Sockets;
using System.Threading;

namespace SuperSimpleTcp
namespace SuperSimpleTcp
{
using System;
using System.Net.Security;
using System.Net.Sockets;
using System.Threading;

internal class ClientMetadata : IDisposable
{
#region Public-Members
Expand Down
6 changes: 3 additions & 3 deletions src/SuperSimpleTcp/Common.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;

namespace SuperSimpleTcp
namespace SuperSimpleTcp
{
using System;

internal static class Common
{
internal static void ParseIpPort(string ipPort, out string ip, out int port)
Expand Down
6 changes: 3 additions & 3 deletions src/SuperSimpleTcp/ConnectionEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;

namespace SuperSimpleTcp
namespace SuperSimpleTcp
{
using System;

/// <summary>
/// Arguments for connection events.
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions src/SuperSimpleTcp/DataReceivedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;

namespace SuperSimpleTcp
namespace SuperSimpleTcp
{
using System;

/// <summary>
/// Arguments for data received from connected endpoints.
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions src/SuperSimpleTcp/DataSentEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;

namespace SuperSimpleTcp
namespace SuperSimpleTcp
{
using System;

/// <summary>
/// Arguments for data sent to a connected endpoint.
/// </summary>
Expand Down
82 changes: 52 additions & 30 deletions src/SuperSimpleTcp/SimpleTcpClient.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Security;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace SuperSimpleTcp
namespace SuperSimpleTcp
{
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Security;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

/// <summary>
/// SimpleTcp client with SSL support.
/// Set the Connected, Disconnected, and DataReceived events.
Expand Down Expand Up @@ -1178,18 +1178,29 @@ private async Task IdleServerMonitor()
{
while (!_token.IsCancellationRequested)
{
await Task.Delay(_settings.IdleServerEvaluationIntervalMs, _token).ConfigureAwait(false);
try
{
await Task.Delay(_settings.IdleServerEvaluationIntervalMs, _token).ConfigureAwait(false);

if (_settings.IdleServerTimeoutMs == 0) continue;
if (_settings.IdleServerTimeoutMs == 0) continue;

DateTime timeoutTime = _lastActivity.AddMilliseconds(_settings.IdleServerTimeoutMs);
DateTime timeoutTime = _lastActivity.AddMilliseconds(_settings.IdleServerTimeoutMs);

if (DateTime.Now > timeoutTime)
if (DateTime.Now > timeoutTime)
{
Logger?.Invoke($"{_header}disconnecting from {ServerIpPort} due to timeout");
_isConnected = false;
_isTimeout = true;
_tokenSource.Cancel(); // DataReceiver will fire events including dispose
}
}
catch (TaskCanceledException)
{
break;
}
catch (OperationCanceledException)
{
Logger?.Invoke($"{_header}disconnecting from {ServerIpPort} due to timeout");
_isConnected = false;
_isTimeout = true;
_tokenSource.Cancel(); // DataReceiver will fire events including dispose
break;
}
}
}
Expand All @@ -1198,16 +1209,27 @@ private async Task ConnectedMonitor()
{
while (!_token.IsCancellationRequested)
{
await Task.Delay(_settings.ConnectionLostEvaluationIntervalMs, _token).ConfigureAwait(false);
try
{
await Task.Delay(_settings.ConnectionLostEvaluationIntervalMs, _token).ConfigureAwait(false);

if (!_isConnected)
continue; //Just monitor connected clients
if (!_isConnected)
continue; //Just monitor connected clients

if (!PollSocket())
if (!PollSocket())
{
Logger?.Invoke($"{_header}disconnecting from {ServerIpPort} due to connection lost");
_isConnected = false;
_tokenSource.Cancel(); // DataReceiver will fire events including dispose
}
}
catch (TaskCanceledException)
{
Logger?.Invoke($"{_header}disconnecting from {ServerIpPort} due to connection lost");
_isConnected = false;
_tokenSource.Cancel(); // DataReceiver will fire events including dispose
break;
}
catch (OperationCanceledException)
{
break;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/SuperSimpleTcp/SimpleTcpClientEvents.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;

namespace SuperSimpleTcp
namespace SuperSimpleTcp
{
using System;

/// <summary>
/// SimpleTcp client events.
/// </summary>
Expand Down
10 changes: 5 additions & 5 deletions src/SuperSimpleTcp/SimpleTcpClientSettings.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Net;
using System.Net.Security;

namespace SuperSimpleTcp
namespace SuperSimpleTcp
{
using System;
using System.Net;
using System.Net.Security;

/// <summary>
/// SimpleTcp client settings.
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions src/SuperSimpleTcp/SimpleTcpKeepaliveSettings.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;

namespace SuperSimpleTcp
namespace SuperSimpleTcp
{
using System;

/// <summary>
/// SimpleTcp keepalive settings.
/// Keepalive probes are sent after an idle period defined by TcpKeepAliveTime (seconds).
Expand Down
39 changes: 19 additions & 20 deletions src/SuperSimpleTcp/SimpleTcpServer.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Security;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace SuperSimpleTcp
namespace SuperSimpleTcp
{
/// <summary>
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Security;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

/// <summary>
/// SimpleTcp server with SSL support.
/// Set the ClientConnected, ClientDisconnected, and DataReceived events.
/// Once set, use Start() to begin listening for connections.
Expand Down Expand Up @@ -476,9 +476,8 @@ public Task StartAsync()
/// </summary>
public void Stop()
{
if (!_isListening) throw new InvalidOperationException("SimpleTcpServer is not running.");

_isListening = false;

_listener.Stop();
_listenerTokenSource.Cancel();
_acceptConnections.Wait();
Expand Down
6 changes: 3 additions & 3 deletions src/SuperSimpleTcp/SimpleTcpServerEvents.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;

namespace SuperSimpleTcp
namespace SuperSimpleTcp
{
using System;

/// <summary>
/// SimpleTcp server events.
/// </summary>
Expand Down
Loading

0 comments on commit 3f12d8a

Please sign in to comment.