Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add .netstandard 2.1 support #242

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/NetCoreServer/FileCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public bool Remove(string key)
/// <returns>'true' if the cache path was setup, 'false' if failed to setup the cache path</returns>
public bool InsertPath(string path, string prefix = "/", string filter = "*.*", TimeSpan timeout = new TimeSpan(), InsertHandler handler = null)
{
handler ??= (FileCache cache, string key, byte[] value, TimeSpan timespan) => cache.Add(key, value, timespan);
handler = handler ?? ((FileCache cache, string key, byte[] value, TimeSpan timespan) => cache.Add(key, value, timespan));

// Try to find and remove the previous path
RemovePathInternal(path);
Expand Down
2 changes: 1 addition & 1 deletion source/NetCoreServer/HttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public class HttpClientEx : HttpClient
/// <returns>HTTP request Task</returns>
public Task<HttpResponse> SendRequest(HttpRequest request, TimeSpan? timeout = null)
{
timeout ??= TimeSpan.FromMinutes(1);
timeout = timeout ?? TimeSpan.FromMinutes(1);

_tcs = new TaskCompletionSource<HttpResponse>();
Request = request;
Expand Down
2 changes: 1 addition & 1 deletion source/NetCoreServer/HttpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class HttpServer : TcpServer
/// <param name="timeout">Refresh cache timeout (default is 1 hour)</param>
public void AddStaticContent(string path, string prefix = "/", string filter = "*.*", TimeSpan? timeout = null)
{
timeout ??= TimeSpan.FromHours(1);
timeout = timeout ?? TimeSpan.FromHours(1);

bool Handler(FileCache cache, string key, byte[] value, TimeSpan timespan)
{
Expand Down
2 changes: 1 addition & 1 deletion source/NetCoreServer/HttpsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public class HttpsClientEx : HttpsClient
/// <returns>HTTP request Task</returns>
public Task<HttpResponse> SendRequest(HttpRequest request, TimeSpan? timeout = null)
{
timeout ??= TimeSpan.FromMinutes(1);
timeout = timeout ?? TimeSpan.FromMinutes(1);

_tcs = new TaskCompletionSource<HttpResponse>();
Request = request;
Expand Down
2 changes: 1 addition & 1 deletion source/NetCoreServer/HttpsServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class HttpsServer : SslServer
/// <param name="timeout">Refresh cache timeout (default is 1 hour)</param>
public void AddStaticContent(string path, string prefix = "/", string filter = "*.*", TimeSpan? timeout = null)
{
timeout ??= TimeSpan.FromHours(1);
timeout = timeout ?? TimeSpan.FromHours(1);

bool Handler(FileCache cache, string key, byte[] value, TimeSpan timespan)
{
Expand Down
15 changes: 9 additions & 6 deletions source/NetCoreServer/NetCoreServer.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Version>7.0.0.0</Version>
<Authors>Ivan Shynkarenka</Authors>
<Copyright>Copyright (c) 2019-2022 Ivan Shynkarenka</Copyright>
<RepositoryUrl>https://github.com/chronoxor/NetCoreServer</RepositoryUrl>
<Description>Ultra fast and low latency asynchronous socket server &amp; client C# .NET Core library with support TCP, SSL, UDP, HTTP, HTTPS, WebSocket protocols and 10K connections problem solution</Description>
<AssemblyName>GoPlay.NetCoreServer</AssemblyName>
<Authors>Jennal</Authors>
<Copyright>Copyright © What2d Ltd. 2023</Copyright>
<RepositoryUrl>https://github.com/jennal/NetCoreServer</RepositoryUrl>
<Description>Fork from [https://github.com/chronoxor/NetCoreServer](https://github.com/chronoxor/NetCoreServer), make it support .NET Standard 2.1

Ultra fast and low latency asynchronous socket server &amp; client C# .NET Core library with support TCP, SSL, UDP, HTTP, HTTPS, WebSocket protocols and 10K connections problem solution</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/chronoxor/NetCoreServer</PackageProjectUrl>
<PackageProjectUrl>https://github.com/jennal/NetCoreServer</PackageProjectUrl>
<PackageTags>async;client;server;tcp;udp;ssl;tls;http;https;websocket;low latency;performance</PackageTags>
<TargetFrameworks>net6.0;net7.0;netstandard2.1</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
4 changes: 4 additions & 0 deletions source/NetCoreServer/SslClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,14 @@ public virtual bool Connect()
// Apply the option: keep alive
if (OptionKeepAlive)
Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
#if NET6_0_OR_GREATER
if (OptionTcpKeepAliveTime >= 0)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveTime, OptionTcpKeepAliveTime);
if (OptionTcpKeepAliveInterval >= 0)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveInterval, OptionTcpKeepAliveInterval);
if (OptionTcpKeepAliveRetryCount >= 0)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveRetryCount, OptionTcpKeepAliveRetryCount);
#endif
// Apply the option: no delay
if (OptionNoDelay)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
Expand Down Expand Up @@ -840,12 +842,14 @@ private void ProcessConnect(SocketAsyncEventArgs e)
// Apply the option: keep alive
if (OptionKeepAlive)
Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
#if NET6_0_OR_GREATER
if (OptionTcpKeepAliveTime >= 0)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveTime, OptionTcpKeepAliveTime);
if (OptionTcpKeepAliveInterval >= 0)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveInterval, OptionTcpKeepAliveInterval);
if (OptionTcpKeepAliveRetryCount >= 0)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveRetryCount, OptionTcpKeepAliveRetryCount);
#endif
// Apply the option: no delay
if (OptionNoDelay)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
Expand Down
8 changes: 7 additions & 1 deletion source/NetCoreServer/SslContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ public class SslContext
/// <summary>
/// Initialize SSL context with default protocols
/// </summary>
public SslContext() : this(SslProtocols.Tls13) {}
public SslContext() : this(
#if NET6_0_OR_GREATER
SslProtocols.Tls13
#else
SslProtocols.Tls12
#endif
) {}
/// <summary>
/// Initialize SSL context with given protocols
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions source/NetCoreServer/SslSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@ internal void Connect(Socket socket)
// Apply the option: keep alive
if (Server.OptionKeepAlive)
Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
#if NET6_0_OR_GREATER
if (Server.OptionTcpKeepAliveTime >= 0)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveTime, Server.OptionTcpKeepAliveTime);
if (Server.OptionTcpKeepAliveInterval >= 0)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveInterval, Server.OptionTcpKeepAliveInterval);
if (Server.OptionTcpKeepAliveRetryCount >= 0)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveRetryCount, Server.OptionTcpKeepAliveRetryCount);
#endif
// Apply the option: no delay
if (Server.OptionNoDelay)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
Expand Down
4 changes: 4 additions & 0 deletions source/NetCoreServer/TcpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,14 @@ public virtual bool Connect()
// Apply the option: keep alive
if (OptionKeepAlive)
Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
#if NET6_0_OR_GREATER
if (OptionTcpKeepAliveTime >= 0)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveTime, OptionTcpKeepAliveTime);
if (OptionTcpKeepAliveInterval >= 0)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveInterval, OptionTcpKeepAliveInterval);
if (OptionTcpKeepAliveRetryCount >= 0)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveRetryCount, OptionTcpKeepAliveRetryCount);
#endif
// Apply the option: no delay
if (OptionNoDelay)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
Expand Down Expand Up @@ -791,12 +793,14 @@ private void ProcessConnect(SocketAsyncEventArgs e)
// Apply the option: keep alive
if (OptionKeepAlive)
Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
#if NET6_0_OR_GREATER
if (OptionTcpKeepAliveTime >= 0)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveTime, OptionTcpKeepAliveTime);
if (OptionTcpKeepAliveInterval >= 0)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveInterval, OptionTcpKeepAliveInterval);
if (OptionTcpKeepAliveRetryCount >= 0)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveRetryCount, OptionTcpKeepAliveRetryCount);
#endif
// Apply the option: no delay
if (OptionNoDelay)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
Expand Down
2 changes: 2 additions & 0 deletions source/NetCoreServer/TcpSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,14 @@ internal void Connect(Socket socket)
// Apply the option: keep alive
if (Server.OptionKeepAlive)
Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
#if NET6_0_OR_GREATER
if (Server.OptionTcpKeepAliveTime >= 0)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveTime, Server.OptionTcpKeepAliveTime);
if (Server.OptionTcpKeepAliveInterval >= 0)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveInterval, Server.OptionTcpKeepAliveInterval);
if (Server.OptionTcpKeepAliveRetryCount >= 0)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveRetryCount, Server.OptionTcpKeepAliveRetryCount);
#endif
// Apply the option: no delay
if (Server.OptionNoDelay)
Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
Expand Down
4 changes: 4 additions & 0 deletions source/NetCoreServer/UdpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,11 @@ public virtual long Send(EndPoint endpoint, ReadOnlySpan<byte> buffer)
try
{
// Sent datagram to the server
#if NET6_0_OR_GREATER
long sent = Socket.SendTo(buffer, SocketFlags.None, endpoint);
#else
long sent = Socket.SendTo(buffer.ToArray(), SocketFlags.None, endpoint);
#endif
if (sent > 0)
{
// Update statistic
Expand Down
4 changes: 4 additions & 0 deletions source/NetCoreServer/UdpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,11 @@ public virtual long Send(EndPoint endpoint, ReadOnlySpan<byte> buffer)
try
{
// Sent datagram to the client
#if NET6_0_OR_GREATER
long sent = Socket.SendTo(buffer, SocketFlags.None, endpoint);
#else
long sent = Socket.SendTo(buffer.ToArray(), SocketFlags.None, endpoint);
#endif
if (sent > 0)
{
// Update statistic
Expand Down