Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 src/NetMQ.Tests/ClientServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public async void AsyncWithCancellationToken()
await Assert.ThrowsAnyAsync<OperationCanceledException>(async () => await server.ReceiveStringAsync(source.Token));
}

#if NETCOREAPP3_1
#if NET8_0_OR_GREATER
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IAsyncEnumerable earliest's availability is on Net Standard 2.1, I believe this check to be too restrictive in theory (although this is just a test project).

It should probably be either #if NET or #if NETSTANDARD2_1_OR_GREATER?


[Fact(Timeout = 120)]
public async void AsyncEnumerableCanceled()
Expand Down
2 changes: 1 addition & 1 deletion src/NetMQ/Annotations.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.

#if !NETSTANDARD2_1
#if !NETSTANDARD2_1 && !NET8_0_OR_GREATER
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Since this is to "stub in" attributes that only available on later frameworks, we probably should only target the missing frameworks?

Should probably be #if NET_FRAMEWORK?


namespace System.Diagnostics.CodeAnalysis
{
Expand Down
2 changes: 1 addition & 1 deletion src/NetMQ/AsyncReceiveExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETSTANDARD2_0 || NETSTANDARD2_1 || NET47
#if NET8_0_OR_GREATER || NET8_0_OR_GREATER || NETSTANDARD2_0 || NETSTANDARD2_1 || NET47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NET8_0_OR_GREATER was added twice.

I also believe a more "generic" statement like #if NETSTANDARD2_0_OR_GREATER || NET47_OR_GREATER would target all compatible frameworks and be "future" proof (won't need to review pragma if like more .NetFramework come out)


using System;
using System.Collections.Generic;
Expand Down
2 changes: 1 addition & 1 deletion src/NetMQ/Core/Mechanisms/CurveClientMechanism.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ PullMsgResult ProduceInitiate(ref Msg msg)

VouchNoncePrefix.CopyTo(vouchNonce);
using var rng = RandomNumberGenerator.Create();
#if NETSTANDARD2_1
#if NET8_0_OR_GREATER || NETSTANDARD2_1
rng.GetBytes(vouchNonce.Slice(8));
#else
byte[] temp = new byte[16];
Expand Down
4 changes: 2 additions & 2 deletions src/NetMQ/Core/Mechanisms/CurveServerMechanism.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ PullMsgResult ProduceWelcome(ref Msg msg)
// 8-byte prefix plus 16-byte random nonce
CookieNoncePrefix.CopyTo(cookieNonce);
using var rng = RandomNumberGenerator.Create();
#if NETSTANDARD2_1
#if NET8_0_OR_GREATER || NETSTANDARD2_1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Spans are available in all non-NetFramework and NetStandard2.1, so it should probably be #if NETSTANDARD2_1_OR_GREATER

rng.GetBytes(cookieNonce.Slice(8));
#else
byte[] temp = new byte[16];
Expand All @@ -184,7 +184,7 @@ PullMsgResult ProduceWelcome(ref Msg msg)
// Create full nonce for encryption
// 8-byte prefix plus 16-byte random nonce
WelcomeNoncePrefix.CopyTo(welcomeNonce);
#if NETSTANDARD2_1
#if NET8_0_OR_GREATER || NETSTANDARD2_1
rng.GetBytes(welcomeNonce.Slice(8));
#else
rng.GetBytes(temp);
Expand Down
2 changes: 1 addition & 1 deletion src/NetMQ/Core/Transports/Pgm/PgmSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ internal void Init()
Debug.WriteLine(xMsg);

// If running on Microsoft Windows, suggest to the developer that he may need to install MSMQ in order to get PGM socket support.
#if NETSTANDARD1_1_OR_GREATER
#if NET8_0_OR_GREATER || NETSTANDARD1_1_OR_GREATER
bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
#else
bool isWindows = true;
Expand Down
8 changes: 8 additions & 0 deletions src/NetMQ/Core/Transports/Tcp/TcpConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ public void OutCompleted(SocketError socketError, int bytesTransferred)
// Set the TCP keep-alive option values to the underlying socket.
m_s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, m_options.TcpKeepalive);


#if NET8_0_OR_GREATER
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last comment in the same "general" idea, these options became available in net5/netcore3.1, might be worth to do a #if NET here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the #if NET idea and made a commit

if (m_options.TcpKeepaliveIdle != -1)
m_s.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveTime, m_options.TcpKeepaliveIdle / 1000);
if (m_options.TcpKeepaliveIntvl != -1)
m_s.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveInterval, m_options.TcpKeepaliveIntvl / 1000);
#else
if (m_options.TcpKeepaliveIdle != -1 && m_options.TcpKeepaliveIntvl != -1)
{
// Write the TCP keep-alive options to a byte-array, to feed to the IOControl method..
Expand All @@ -261,6 +268,7 @@ public void OutCompleted(SocketError socketError, int bytesTransferred)

m_s.IOControl(IOControlCode.KeepAliveValues, (byte[])bytes, null);
}
#endif
}

// Create the engine object for this connection.
Expand Down
108 changes: 58 additions & 50 deletions src/NetMQ/Core/Transports/Tcp/TcpListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ You should have received a copy of the GNU Lesser General Public License
using System;
using System.Diagnostics;
using System.Net.Sockets;
#if NETSTANDARD2_0 || NETSTANDARD2_1
#if NET8_0_OR_GREATER || NETSTANDARD2_0 || NETSTANDARD2_1
using System.Runtime.InteropServices;
#endif
using AsyncIO;
Expand All @@ -45,12 +45,12 @@ internal class TcpListener : Own, IProactorEvents
/// </summary>
private AsyncSocket? m_handle;

/*
/// <summary>
/// socket being accepted
/// </summary>
private AsyncSocket m_acceptedSocket;
*/
/*
/// <summary>
/// socket being accepted
/// </summary>
private AsyncSocket m_acceptedSocket;
*/

/// <summary>
/// Socket the listener belongs to.
Expand Down Expand Up @@ -107,7 +107,7 @@ protected override void ProcessPlug()
protected override void ProcessTerm(int linger)
{
Assumes.NotNull(m_handle);

m_ioObject.SetHandler(this);
m_ioObject.RemoveSocket(m_handle);
Close();
Expand Down Expand Up @@ -141,7 +141,7 @@ public virtual void SetAddress(string addr)
}
}

#if NETSTANDARD2_0 || NETSTANDARD2_1
#if NET8_0_OR_GREATER || NETSTANDARD2_0 || NETSTANDARD2_1
// This command is failing on linux
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
m_handle.ExclusiveAddressUse = false;
Expand Down Expand Up @@ -194,68 +194,76 @@ public void InCompleted(SocketError socketError, int bytesTransferred)
switch (socketError)
{
case SocketError.Success:
{
// TODO: check TcpFilters
var acceptedSocket = m_handle.GetAcceptedSocket();
{
// TODO: check TcpFilters
var acceptedSocket = m_handle.GetAcceptedSocket();

acceptedSocket.NoDelay = true;

if (m_options.TcpKeepalive != -1)
{
acceptedSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, m_options.TcpKeepalive);

if (m_options.TcpKeepaliveIdle != -1 && m_options.TcpKeepaliveIntvl != -1)
if (m_options.TcpKeepalive != -1)
{
var bytes = new ByteArraySegment(new byte[12]);
acceptedSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, m_options.TcpKeepalive);
#if NET8_0_OR_GREATER
if (m_options.TcpKeepaliveIdle != -1)
acceptedSocket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveTime, m_options.TcpKeepaliveIdle / 1000);
if (m_options.TcpKeepaliveIntvl != -1)
acceptedSocket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveInterval, m_options.TcpKeepaliveIntvl / 1000);
#else

if (m_options.TcpKeepaliveIdle != -1 && m_options.TcpKeepaliveIntvl != -1)
{
var bytes = new ByteArraySegment(new byte[12]);

Endianness endian = BitConverter.IsLittleEndian ? Endianness.Little : Endianness.Big;

Endianness endian = BitConverter.IsLittleEndian ? Endianness.Little : Endianness.Big;
bytes.PutInteger(endian, m_options.TcpKeepalive, 0);
bytes.PutInteger(endian, m_options.TcpKeepaliveIdle, 4);
bytes.PutInteger(endian, m_options.TcpKeepaliveIntvl, 8);

bytes.PutInteger(endian, m_options.TcpKeepalive, 0);
bytes.PutInteger(endian, m_options.TcpKeepaliveIdle, 4);
bytes.PutInteger(endian, m_options.TcpKeepaliveIntvl, 8);
acceptedSocket.IOControl(IOControlCode.KeepAliveValues, (byte[])bytes, null);
}
#endif

acceptedSocket.IOControl(IOControlCode.KeepAliveValues, (byte[])bytes, null);
}
}

// Create the engine object for this connection.
var engine = new StreamEngine(acceptedSocket, m_options, m_endpoint);
// Create the engine object for this connection.
var engine = new StreamEngine(acceptedSocket, m_options, m_endpoint);

// Choose I/O thread to run connector in. Given that we are already
// running in an I/O thread, there must be at least one available.
IOThread? ioThread = ChooseIOThread(m_options.Affinity);
// Choose I/O thread to run connector in. Given that we are already
// running in an I/O thread, there must be at least one available.
IOThread? ioThread = ChooseIOThread(m_options.Affinity);

Assumes.NotNull(ioThread);
Assumes.NotNull(ioThread);

// Create and launch a session object.
// TODO: send null in address parameter, is unneeded in this case
SessionBase session = SessionBase.Create(ioThread, false, m_socket, m_options, new Address(m_handle.LocalEndPoint));
session.IncSeqnum();
LaunchChild(session);
// Create and launch a session object.
// TODO: send null in address parameter, is unneeded in this case
SessionBase session = SessionBase.Create(ioThread, false, m_socket, m_options, new Address(m_handle.LocalEndPoint));
session.IncSeqnum();
LaunchChild(session);

SendAttach(session, engine, false);
SendAttach(session, engine, false);

m_socket.EventAccepted(m_endpoint, acceptedSocket);
m_socket.EventAccepted(m_endpoint, acceptedSocket);

Accept();
break;
}
Accept();
break;
}
case SocketError.ConnectionReset:
case SocketError.NoBufferSpaceAvailable:
case SocketError.TooManyOpenSockets:
{
m_socket.EventAcceptFailed(m_endpoint, socketError.ToErrorCode());
{
m_socket.EventAcceptFailed(m_endpoint, socketError.ToErrorCode());

Accept();
break;
}
Accept();
break;
}
default:
{
NetMQException exception = NetMQException.Create(socketError);
{
NetMQException exception = NetMQException.Create(socketError);

m_socket.EventAcceptFailed(m_endpoint, exception.ErrorCode);
throw exception;
}
m_socket.EventAcceptFailed(m_endpoint, exception.ErrorCode);
throw exception;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/NetMQ/Core/Utils/OpCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static bool Open()
string val = Environment.GetEnvironmentVariable("NETQM_SUPPRESS_RDTSC");
if (!string.IsNullOrEmpty(val))
return false;
#if NETSTANDARD1_1_OR_GREATER || NET471_OR_GREATER
#if NET8_0_OR_GREATER || NETSTANDARD1_1_OR_GREATER || NET471_OR_GREATER
if (RuntimeInformation.ProcessArchitecture != Architecture.X86 &&
RuntimeInformation.ProcessArchitecture != Architecture.X64)
{
Expand Down
2 changes: 1 addition & 1 deletion src/NetMQ/Core/Utils/SpanUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal static class SpanUtility
{
public static string ToAscii(Span<byte> bytes)
{
#if NETSTANDARD2_1
#if NET8_0_OR_GREATER || NETSTANDARD2_1
return Encoding.ASCII.GetString(bytes);
#else
return Encoding.ASCII.GetString(bytes.ToArray());
Expand Down
4 changes: 2 additions & 2 deletions src/NetMQ/GroupSocketExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public static bool TryReceiveBytes(this IGroupInSocket socket, TimeSpan timeout,

#region AsyncEnumerable

#if NETSTANDARD2_1
#if NET8_0_OR_GREATER || NETSTANDARD2_1
/// <summary>
/// Provides a consuming IAsyncEnumerable for receiving messages from the socket.
/// </summary>
Expand Down Expand Up @@ -575,7 +575,7 @@ public static bool TryReceiveString(this IGroupInSocket socket, TimeSpan timeout

#region AsyncEnumerable

#if NETSTANDARD2_1
#if NET8_0_OR_GREATER || NETSTANDARD2_1
/// <summary>
/// Provides a consuming IAsyncEnumerable for receiving messages from the socket.
/// </summary>
Expand Down
10 changes: 3 additions & 7 deletions src/NetMQ/NetMQ.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Description>A 100% native C# port of the lightweight high performance messaging library ZeroMQ</Description>
<Version>4.0.0.0</Version>
<TargetFrameworks>net47;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net47;netstandard21;net8.0</TargetFrameworks>
<DebugType>portable</DebugType>
<AssemblyOriginatorKeyFile>./NetMQ.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
Expand Down Expand Up @@ -38,12 +38,8 @@
<PackageReference Include="NaCl.Net" Version="0.1.13" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.ServiceModel.Primitives" Version="8.1.1" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.1' ">
<PackageReference Include="System.ServiceModel.Primitives" Version="8.1.1" />
<ItemGroup Condition=" '$(TargetFramework)' != '.NETFramework' ">
<PackageReference Include="System.ServiceModel.Primitives" Version="8.1.2" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' ">
Expand Down
2 changes: 1 addition & 1 deletion src/NetMQ/NetMQRuntime.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETSTANDARD2_0 || NETSTANDARD2_1 || NET47
#if NET8_0_OR_GREATER || NETSTANDARD2_0 || NETSTANDARD2_1 || NET47

using System;
using System.Threading;
Expand Down
6 changes: 3 additions & 3 deletions src/NetMQ/NetMQSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public abstract class NetMQSocket : INetMQSocket
private EventHandler<NetMQSocketEventArgs>? m_sendReady;
private int m_isClosed;

#if NETSTANDARD2_0 || NETSTANDARD2_1 || NET47
#if NET8_0_OR_GREATER || NETSTANDARD2_0 || NETSTANDARD2_1 || NET47
private NetMQRuntime? m_runtime;
#endif

Expand Down Expand Up @@ -249,7 +249,7 @@ public void Unbind(string address)
/// <summary>Closes this socket, rendering it unusable. Equivalent to calling <see cref="Dispose()"/>.</summary>
public void Close()
{
#if NETSTANDARD2_0 || NETSTANDARD2_1 || NET47
#if NET8_0_OR_GREATER || NETSTANDARD2_0 || NETSTANDARD2_1 || NET47
if (m_runtime != null)
{
m_runtime.Remove(this);
Expand Down Expand Up @@ -391,7 +391,7 @@ public virtual bool TrySend(ref Msg msg, TimeSpan timeout, bool more)

#endregion

#if NETSTANDARD2_0 || NETSTANDARD2_1 || NET47
#if NET8_0_OR_GREATER || NETSTANDARD2_0 || NETSTANDARD2_1 || NET47

internal void AttachToRuntime()
{
Expand Down
4 changes: 2 additions & 2 deletions src/NetMQ/ReceiveThreadSafeSocketExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static ValueTask<byte[]> ReceiveBytesAsync(this IThreadSafeInSocket socke

#region AsyncEnumerable

#if NETSTANDARD2_1
#if NET8_0_OR_GREATER || NETSTANDARD2_1

/// <summary>
/// Provides a consuming IAsyncEnumerable for receiving messages from the socket.
Expand Down Expand Up @@ -302,7 +302,7 @@ public static ValueTask<string> ReceiveStringAsync(this IThreadSafeInSocket sock

#region AsyncEnumerable

#if NETSTANDARD2_1
#if NET8_0_OR_GREATER || NETSTANDARD2_1

/// <summary>
/// Provides a consuming IAsyncEnumerable for receiving messages from the socket.
Expand Down
4 changes: 2 additions & 2 deletions src/NetMQ/RoutingIdSocketExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public static bool TryReceiveBytes(this IRoutingIdSocket socket, TimeSpan timeou

#region AsyncEnumerable

#if NETSTANDARD2_1
#if NET8_0_OR_GREATER || NETSTANDARD2_1

/// <summary>
/// Provides a consuming IAsyncEnumerable for receiving messages from the socket.
Expand Down Expand Up @@ -564,7 +564,7 @@ public static bool TryReceiveString(this IRoutingIdSocket socket, TimeSpan timeo

#region AsyncEnumerable

#if NETSTANDARD2_1
#if NET8_0_OR_GREATER || NETSTANDARD2_1

/// <summary>
/// Provides a consuming IAsyncEnumerable for receiving messages from the socket.
Expand Down
2 changes: 1 addition & 1 deletion src/NetMQ/ThreadSafeSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public void Unbind(string address)
/// <summary>Closes this socket, rendering it unusable. Equivalent to calling <see cref="Dispose()"/>.</summary>
public void Close()
{
// #if NETSTANDARD2_0 || NETSTANDARD2_1 || NET47
// #if NET8_0_OR_GREATER || NETSTANDARD2_0 || NETSTANDARD2_1 || NET47
// if (m_runtime != null)
// {
// m_runtime.Remove(this);
Expand Down
2 changes: 1 addition & 1 deletion src/NetMQ/Utils/EncodingExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !NETSTANDARD2_1
#if !NETSTANDARD2_1 && !NET8_0_OR_GREATER
using System;
using System.Text;

Expand Down
2 changes: 1 addition & 1 deletion src/Performance/NetMQ.SimpleTests/NetMQ.SimpleTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

Expand Down
Loading