Skip to content

Add net8.0 target and increase net47 to net472 #1128

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

Merged
merged 15 commits into from
Jun 13, 2025
4 changes: 2 additions & 2 deletions src/NetMQ.Tests/ClientServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void Tcp()
}

[Fact]
public async void Async()
public async Task Async()
{
using var server = new ServerSocket();
using var client = new ClientSocket();
Expand All @@ -72,7 +72,7 @@ public async void Async()
}

[Fact]
public async void AsyncWithCancellationToken()
public async Task AsyncWithCancellationToken()
{
using CancellationTokenSource source = new CancellationTokenSource();
using var server = new ServerSocket();
Expand Down
6 changes: 3 additions & 3 deletions src/NetMQ.Tests/NetMQPollerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public void AddTwoSocketAfterRemoving()


[Fact]
public void RemoveSocket()
public async Task RemoveSocket()
{
using (var router1 = new RouterSocket())
using (var router2 = new RouterSocket())
Expand Down Expand Up @@ -396,8 +396,8 @@ public void RemoveSocket()

poller.Stop();
// await the pollerTask, 1ms should suffice
pollerTask.Wait(1);
Assert.True(pollerTask.IsCompleted);
var completedTask = await Task.WhenAny(pollerTask, Task.Delay(1));
Assert.Equal(pollerTask, completedTask);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/NetMQ.Tests/NetMQQueueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void EnqueueDequeue()
}

[Fact]
public void EnqueueShouldNotBlockWhenCapacityIsZero()
public async Task EnqueueShouldNotBlockWhenCapacityIsZero()
{
using (var mockSocket = new PairSocket())
using (var queue = new NetMQQueue<int>())
Expand All @@ -39,8 +39,8 @@ public void EnqueueShouldNotBlockWhenCapacityIsZero()
}
});

bool completed = task.Wait(TimeSpan.FromSeconds(1));
Assert.True(completed, "Enqueue task should have completed " + socketWatermarkCapacity + " enqueue within 1 second");
var completedTask = await Task.WhenAny(task, Task.Delay(1000));
Assert.True(task == completedTask, "Enqueue task should have completed " + socketWatermarkCapacity + " enqueue within 1 second");
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/NetMQ.Tests/PgmTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void TwoPublishers()
}

[Fact(Skip = "Requires MSMQ for PGM sockets")]
public void Sending1000Messages()
public async Task Sending1000Messages()
{
// creating two different context and sending 1000 messages

Expand Down Expand Up @@ -230,8 +230,8 @@ public void Sending1000Messages()
}
});

pubTask.Wait();
subTask.Wait();
await pubTask;
await subTask;

Assert.Equal(1000, count);
}
Expand Down Expand Up @@ -266,7 +266,7 @@ public void LargeMessage()
[Theory(Skip = "Requires MSMQ for PGM sockets")]
[InlineData("pgm://239.0.0.1:1000")]
[InlineData("tcp://localhost:60000")]
public void SubscriberCleanupOnUnbind(string address)
public async Task SubscriberCleanupOnUnbind(string address)
{
for (var i = 0; i < 10; i++)
{
Expand All @@ -290,8 +290,8 @@ public void SubscriberCleanupOnUnbind(string address)
// var duration = DateTime.Now - time;

monitor.Stop();

monitorTask.Wait();
await monitorTask;
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/NetMQ.Tests/RadioDish.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using NetMQ.Sockets;
using Xunit;
using Xunit.Abstractions;
Expand Down Expand Up @@ -47,7 +48,7 @@ public void TestBlocking()
}

[Fact]
public async void TestAsync()
public async Task TestAsync()
{
using var radio = new RadioSocket();
using var dish = new DishSocket();
Expand All @@ -56,7 +57,7 @@ public async void TestAsync()
int port = radio.BindRandomPort("tcp://*");
dish.Connect($"tcp://127.0.0.1:{port}");

Thread.Sleep(100);
await Task.Delay(100);

await radio.SendAsync("1", "HELLO");
await radio.SendAsync("2", "HELLO");
Expand Down
3 changes: 2 additions & 1 deletion src/NetMQ.Tests/ScatterGather.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading;
using System.Threading.Tasks;
using NetMQ.Sockets;
using Xunit;

Expand Down Expand Up @@ -47,7 +48,7 @@ public void TestBlocking()
}

[Fact]
public async void TestAsync()
public async Task TestAsync()
{
using var scatter = new ScatterSocket();
using var gather = new GatherSocket();
Expand Down
4 changes: 2 additions & 2 deletions src/NetMQ.Tests/SocketTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void LargeMessage()
}

[Fact]
public void ReceiveMessageWithTimeout()
public async Task ReceiveMessageWithTimeout()
{
{
var pubSync = new AutoResetEvent(false);
Expand Down Expand Up @@ -134,7 +134,7 @@ public void ReceiveMessageWithTimeout()
t1.Start();
t2.Start();

Task.WaitAll(t1, t2);
await Task.WhenAll(t1, t2);
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/NetMQ/Core/Address.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using System.Diagnostics;
using System.Net;

namespace NetMQ.Core
Expand Down Expand Up @@ -102,7 +103,8 @@
return;
}

AddressString = endpoint.ToString();
Debug.Assert(endpoint != null);
AddressString = endpoint.ToString()!;

Check warning on line 107 in src/NetMQ/Core/Address.cs

View workflow job for this annotation

GitHub Actions / windows

Dereference of a possibly null reference.

Check warning on line 107 in src/NetMQ/Core/Address.cs

View workflow job for this annotation

GitHub Actions / ununtu

Dereference of a possibly null reference.
}


Expand All @@ -112,9 +114,9 @@
{
switch (Protocol)
{
case TcpProtocol: return Resolved.ToString();
case IpcProtocol: return Resolved.ToString();
case PgmProtocol: return Resolved.ToString();
case TcpProtocol: return Resolved!.ToString()!;
case IpcProtocol: return Resolved!.ToString()!;
case PgmProtocol: return Resolved!.ToString()!;
}
}

Expand All @@ -123,7 +125,7 @@
return Protocol + "://" + AddressString;
}

return base.ToString();
return base.ToString()!;
}

public string Protocol { get; }
Expand Down
2 changes: 1 addition & 1 deletion src/NetMQ/Core/Transports/ByteArraySegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public static explicit operator byte[](ByteArraySegment buffer)
/// and has the same Offset property value
/// and it's buffer points to the SAME byte-array as the otherObject does.
/// </remarks>
public override bool Equals(object otherObject)
public override bool Equals(object? otherObject)
{
var byteArraySegment = otherObject as ByteArraySegment;
if (byteArraySegment != null)
Expand Down
8 changes: 4 additions & 4 deletions src/NetMQ/Core/Transports/Tcp/TcpListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,16 @@ private void Close()
if (m_handle == null)
return;

Assumes.NotNull(m_endpoint);

try
{
m_handle.Dispose();
m_socket.EventClosed(m_endpoint, m_handle);
if (m_endpoint is not null)
m_socket.EventClosed(m_endpoint, m_handle);
}
catch (SocketException ex)
{
m_socket.EventCloseFailed(m_endpoint, ex.SocketErrorCode.ToErrorCode());
if (m_endpoint is not null)
m_socket.EventCloseFailed(m_endpoint, ex.SocketErrorCode.ToErrorCode());
}

m_handle = null;
Expand Down
4 changes: 3 additions & 1 deletion src/NetMQ/Core/Utils/ByteArrayEqualityComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ internal sealed class ByteArrayEqualityComparer : IEqualityComparer<byte[]>
/// <param name="x">one of the two byte-arrays to compare</param>
/// <param name="y">the other byte-array to compare against</param>
/// <returns></returns>
public bool Equals(byte[] x, byte[] y)
public bool Equals(byte[]? x, byte[]? y)
{
if (x == y) return true;
if (x is null || y is null) return false;
if (x.Length != y.Length)
{
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/NetMQ/Core/Utils/Signaler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Signaler()

m_writeSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Unspecified) { NoDelay = true };

m_writeSocket.Connect(listener.LocalEndPoint);
m_writeSocket.Connect(listener.LocalEndPoint!);
m_readSocket = listener.Accept();
}

Expand Down
10 changes: 7 additions & 3 deletions src/NetMQ/Msg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public byte[] ToArray()
var data = new byte[Size];

if (Size > 0)
Buffer.BlockCopy(m_data, m_offset, data, 0, Size);
Buffer.BlockCopy(m_data!, m_offset, data, 0, Size);

return data;
}
Expand Down Expand Up @@ -548,6 +548,7 @@ public override string ToString()
/// <returns>The string</returns>
public string GetString(Encoding encoding)
{
Assumes.NotNull(m_data);
return encoding.GetString(m_data, m_offset, Size);
}

Expand All @@ -560,6 +561,7 @@ public string GetString(Encoding encoding)
/// <returns>The string</returns>
public string GetString(Encoding encoding, int offset, int count)
{
Assumes.NotNull(m_data);
return encoding.GetString(m_data, m_offset + offset, count);
}

Expand All @@ -573,7 +575,7 @@ public void Put(byte[]? src, int dstOffset, int len)
{
if (len == 0 || src == null)
return;

Assumes.NotNull(m_data);
Buffer.BlockCopy(src, 0, m_data, dstOffset, len);
}

Expand All @@ -587,6 +589,7 @@ public void Put(byte[]? src, int dstOffset, int len)
public void Put(byte[]? src, int srcOffset, int dstOffset, int len) {
if (len == 0 || src == null)
return;
Assumes.NotNull(m_data);
Buffer.BlockCopy(src, srcOffset, m_data, dstOffset, len);
}

Expand Down Expand Up @@ -619,6 +622,7 @@ public void Put(byte b, int i)
/// <param name="index">The index to write the string to</param>
public void Put(Encoding encoding, string str, int index)
{
Assumes.NotNull(m_data);
encoding.GetBytes(str, 0, str.Length, m_data, m_offset + index);
}
/// <summary>
Expand Down Expand Up @@ -728,7 +732,7 @@ public byte[] CloneData()
var data = new byte[Size];

if (Size > 0)
Buffer.BlockCopy(m_data, m_offset, data, 0, Size);
Buffer.BlockCopy(m_data!, m_offset, data, 0, Size);

return data;
}
Expand Down
5 changes: 3 additions & 2 deletions src/NetMQ/NetMQBeacon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private void Configure(string interfaceName, int port)
}
}

if (bindTo != null)
if (bindTo != null && sendTo != null)
{
m_broadcastAddress = new IPEndPoint(sendTo, m_udpPort);
m_udpSocket.Bind(new IPEndPoint(bindTo, m_udpPort));
Expand Down Expand Up @@ -266,6 +266,7 @@ private void OnPipeReady(object sender, NetMQSocketEventArgs e)
private void SendUdpFrame(NetMQFrame frame)
{
Assumes.NotNull(m_udpSocket);
Assumes.NotNull(m_broadcastAddress);

try
{
Expand Down Expand Up @@ -299,7 +300,7 @@ private bool TryReceiveUdpFrame([NotNullWhen(returnValue: true)] out NetMQFrame?
return false;
}

peerName = peer.ToString();
peerName = peer.ToString()!;
frame = new NetMQFrame(buffer, bytesRead);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/NetMQ/NetMQFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
return true;
}

bool IEquatable<NetMQFrame>.Equals(NetMQFrame other)

Check warning on line 261 in src/NetMQ/NetMQFrame.cs

View workflow job for this annotation

GitHub Actions / windows

Nullability of reference types in type of parameter 'other' doesn't match implemented member 'bool IEquatable<NetMQFrame>.Equals(NetMQFrame? other)' (possibly because of nullability attributes).

Check warning on line 261 in src/NetMQ/NetMQFrame.cs

View workflow job for this annotation

GitHub Actions / ununtu

Nullability of reference types in type of parameter 'other' doesn't match implemented member 'bool IEquatable<NetMQFrame>.Equals(NetMQFrame? other)' (possibly because of nullability attributes).
{
return Equals(other);
}
Expand All @@ -268,7 +268,7 @@
/// </summary>
/// <param name="obj">the Object to compare this to</param>
/// <returns>true only if the given Object is a NetMQFrame equal to this one</returns>
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return Equals(obj as NetMQFrame);
}
Expand Down
6 changes: 3 additions & 3 deletions src/NetMQ/NetMQPoller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public NetMQPoller()

// Try to dequeue and execute all pending tasks
while (m_tasksQueue.TryDequeue(out Task? task, TimeSpan.Zero))
TryExecuteTask(task);
TryExecuteTask(task!);
};

m_sockets.Add(((ISocketPollable)m_tasksQueue).Socket);
Expand Down Expand Up @@ -641,8 +641,8 @@ private void RunPoller()

#if !NET35
// Try to dequeue and execute all pending tasks before stopping poller
while (m_tasksQueue.TryDequeue(out Task? task, TimeSpan.Zero))
TryExecuteTask(task);
while (m_tasksQueue.TryDequeue(out Task? task, TimeSpan.Zero) )
TryExecuteTask(task!);
#endif
}
finally
Expand Down
7 changes: 4 additions & 3 deletions src/NetMQ/NetMQQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public event EventHandler<NetMQQueueEventArgs<T>> ReceiveReady
/// <param name="result">Will be filled with the item upon success</param>
/// <param name="timeout">Timeout to try and dequeue and item</param>
/// <returns>Will return false if it didn't succeed to dequeue an item after the timeout.</returns>
public bool TryDequeue([MaybeNull] out T result, TimeSpan timeout)
public bool TryDequeue(out T? result, TimeSpan timeout)
{
if (m_reader.TryReceive(ref m_dequeueMsg, timeout))
{
Expand All @@ -111,11 +111,12 @@ public bool TryDequeue([MaybeNull] out T result, TimeSpan timeout)
/// Dequeue an item from the queue, will block if queue is empty. Dequeueing and item is not thread safe.
/// </summary>
/// <returns>Dequeued item</returns>
public T Dequeue()
public T? Dequeue()
{
m_reader.TryReceive(ref m_dequeueMsg, SendReceiveConstants.InfiniteTimeout);

m_queue.TryDequeue(out T result);
m_queue.TryDequeue(out T? result);


return result;
}
Expand Down
Loading
Loading