Skip to content

Commit

Permalink
Annotate all public API for nullability
Browse files Browse the repository at this point in the history
  • Loading branch information
drewnoakes committed May 21, 2020
1 parent aa4ea84 commit f74c15a
Show file tree
Hide file tree
Showing 66 changed files with 611 additions and 535 deletions.
23 changes: 10 additions & 13 deletions src/NetMQ/AsyncReceiveExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#if NETSTANDARD2_0 || NETSTANDARD2_1 || NET47
#nullable enable
#if NETSTANDARD2_0 || NETSTANDARD2_1 || NET47

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;

namespace NetMQ
{
Expand Down Expand Up @@ -33,7 +33,7 @@ public static class AsyncReceiveExtensions
/// <param name="cancellationToken">The token used to propagate notification that this operation should be canceled.</param>
/// <returns>The content of the received message.</returns>
public static async Task<NetMQMessage> ReceiveMultipartMessageAsync(
[NotNull] this NetMQSocket socket,
this NetMQSocket socket,
int expectedFrameCount = 4,
CancellationToken cancellationToken = default(CancellationToken))
{
Expand Down Expand Up @@ -63,9 +63,8 @@ public static async Task<NetMQMessage> ReceiveMultipartMessageAsync(
/// <param name="socket">The socket to receive from.</param>
/// <param name="cancellationToken">The token used to propagate notification that this operation should be canceled.</param>
/// <returns>The content of the received message frame and boolean indicate if another frame of the same message follows.</returns>
[NotNull]
public static Task<(byte[], bool)> ReceiveFrameBytesAsync(
[NotNull] this NetMQSocket socket,
this NetMQSocket socket,
CancellationToken cancellationToken = default(CancellationToken)
)
{
Expand Down Expand Up @@ -117,9 +116,8 @@ void Listener(object sender, NetMQSocketEventArgs args)
/// <param name="socket">The socket to receive from.</param>
/// <param name="cancellationToken">The token used to propagate notification that this operation should be canceled.</param>
/// <returns>The content of the received message frame as a string and a boolean indicate if another frame of the same message follows.</returns>
[NotNull]
public static Task<(string, bool)> ReceiveFrameStringAsync(
[NotNull] this NetMQSocket socket,
this NetMQSocket socket,
CancellationToken cancellationToken = default(CancellationToken)
)
{
Expand All @@ -134,10 +132,9 @@ void Listener(object sender, NetMQSocketEventArgs args)
/// <param name="encoding">The encoding used to convert the frame's data to a string.</param>
/// <param name="cancellationToken">The token used to propagate notification that this operation should be canceled.</param>
/// <returns>The content of the received message frame as a string and boolean indicate if another frame of the same message follows..</returns>
[NotNull]
public static Task<(string, bool)> ReceiveFrameStringAsync(
[NotNull] this NetMQSocket socket,
[NotNull] Encoding encoding,
this NetMQSocket socket,
Encoding encoding,
CancellationToken cancellationToken = default(CancellationToken))
{
if (NetMQRuntime.Current == null)
Expand Down Expand Up @@ -190,7 +187,7 @@ void Listener(object sender, NetMQSocketEventArgs args)
/// </summary>
/// <param name="socket">The socket to receive from.</param>
/// <returns>Boolean indicate if another frame of the same message follows</returns>
public static Task<bool> SkipFrameAsync([NotNull] this NetMQSocket socket)
public static Task<bool> SkipFrameAsync(this NetMQSocket socket)
{
if (NetMQRuntime.Current == null)
throw new InvalidOperationException("NetMQRuntime must be created before calling async functions");
Expand Down Expand Up @@ -235,7 +232,7 @@ void Listener(object sender, NetMQSocketEventArgs args)
/// Receive all frames of the next message from <paramref name="socket"/>, asynchronously, then ignore their contents.
/// </summary>
/// <param name="socket">The socket to receive from.</param>
public static async Task SkipMultipartMessageAsync([NotNull] this NetMQSocket socket)
public static async Task SkipMultipartMessageAsync(this NetMQSocket socket)
{
while (true)
{
Expand All @@ -256,7 +253,7 @@ public static async Task SkipMultipartMessageAsync([NotNull] this NetMQSocket so
/// <param name="socket">The socket to receive from.</param>
/// <returns>The routing key and a boolean indicate if another frame of the same message follows.</returns>

public static async Task<(RoutingKey, bool)> ReceiveRoutingKeyAsync([NotNull] this NetMQSocket socket)
public static async Task<(RoutingKey, bool)> ReceiveRoutingKeyAsync(this NetMQSocket socket)
{
var (bytes, more) = await socket.ReceiveFrameBytesAsync();

Expand Down
11 changes: 5 additions & 6 deletions src/NetMQ/AtomicCounterPool.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using JetBrains.Annotations;
#nullable enable

using NetMQ.Core.Utils;
using System;
using System.Threading;
Expand All @@ -15,14 +16,13 @@ public interface IAtomicCounterPool : IDisposable
/// Take an AtomicCounter from the pool.
/// </summary>
/// <returns>an atomic counter</returns>
[NotNull]
AtomicCounter Take();

/// <summary>
/// Return the given atomic counter to the common pool.
/// </summary>
/// <param name="counter">the atomic counter to return to the buffer-pool</param>
void Return([NotNull] AtomicCounter counter);
void Return(AtomicCounter counter);
}

/// <summary>
Expand Down Expand Up @@ -99,7 +99,7 @@ public static void SetGCCounterPool()
/// Set BufferPool to use the specified IAtomicCounterPool implementation to manage the pool.
/// </summary>
/// <param name="counterPool">the implementation of <see cref="IAtomicCounterPool"/> to use</param>
public static void SetCustomCounterPool([NotNull] IAtomicCounterPool counterPool)
public static void SetCustomCounterPool(IAtomicCounterPool counterPool)
{
var prior = Interlocked.Exchange(ref s_counterPool, counterPool);

Expand All @@ -110,7 +110,6 @@ public static void SetCustomCounterPool([NotNull] IAtomicCounterPool counterPool
/// Allocate an atomic counter from the current <see cref="IAtomicCounterPool"/>.
/// </summary>
/// <returns>an atomic counter</returns>
[NotNull]
public static AtomicCounter Take()
{
return s_counterPool.Take();
Expand All @@ -120,7 +119,7 @@ public static AtomicCounter Take()
/// Returns <paramref name="counter"/> to the <see cref="IAtomicCounterPool"/>.
/// </summary>
/// <param name="counter">The atomic counter to be returned to the pool.</param>
public static void Return([NotNull] AtomicCounter counter)
public static void Return(AtomicCounter counter)
{
s_counterPool.Return(counter);
}
Expand Down
11 changes: 5 additions & 6 deletions src/NetMQ/BufferPool.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#nullable enable

using System;
using System.ServiceModel.Channels;
using System.Threading;
using JetBrains.Annotations;

namespace NetMQ
{
Expand All @@ -16,14 +17,13 @@ public interface IBufferPool : IDisposable
/// </summary>
/// <param name="size">the number of bytes to take</param>
/// <returns>a byte-array that comes from the buffer-pool</returns>
[NotNull]
byte[] Take(int size);

/// <summary>
/// Return the given byte-array buffer to the common buffer-pool.
/// </summary>
/// <param name="buffer">the byte-array to return to the buffer-pool</param>
void Return([NotNull] byte[] buffer);
void Return(byte[] buffer);
}

/// <summary>
Expand Down Expand Up @@ -180,7 +180,7 @@ public static void SetBufferManagerBufferPool(long maxBufferPoolSize, int maxBuf
/// Set BufferPool to use the specified IBufferPool implementation to manage the buffer-pool.
/// </summary>
/// <param name="bufferPool">the implementation of <see cref="IBufferPool"/> to use</param>
public static void SetCustomBufferPool([NotNull] IBufferPool bufferPool)
public static void SetCustomBufferPool(IBufferPool bufferPool)
{
var prior = Interlocked.Exchange(ref s_bufferPool, bufferPool);

Expand All @@ -192,7 +192,6 @@ public static void SetCustomBufferPool([NotNull] IBufferPool bufferPool)
/// </summary>
/// <param name="size">The minimum size required, in bytes.</param>
/// <returns>A byte array having at least <paramref name="size"/> bytes.</returns>
[NotNull]
public static byte[] Take(int size)
{
return s_bufferPool.Take(size);
Expand All @@ -202,7 +201,7 @@ public static byte[] Take(int size)
/// Returns <paramref name="buffer"/> to the <see cref="IBufferPool"/>.
/// </summary>
/// <param name="buffer">The byte array to be returned to the pool.</param>
public static void Return([NotNull] byte[] buffer)
public static void Return(byte[] buffer)
{
s_bufferPool.Return(buffer);
}
Expand Down
2 changes: 2 additions & 0 deletions src/NetMQ/EmptyArray.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

namespace NetMQ
{
internal static class EmptyArray<T>
Expand Down
4 changes: 3 additions & 1 deletion src/NetMQ/Endianness.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace NetMQ
#nullable enable

namespace NetMQ
{
/// <summary>
/// This enum-type specifies either big-endian (Big) or little-endian (Little),
Expand Down
2 changes: 2 additions & 0 deletions src/NetMQ/ErrorCode.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

namespace NetMQ
{
/// <summary>
Expand Down
11 changes: 6 additions & 5 deletions src/NetMQ/EventDelegator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
#nullable enable

using System;
using System.Threading;
using JetBrains.Annotations;

namespace NetMQ
{
Expand All @@ -16,15 +17,15 @@ internal class EventDelegator<T> : IDisposable where T : EventArgs
{
private readonly Action m_registerToEvent;
private readonly Action m_unregisterFromEvent;
private EventHandler<T> m_event;
private EventHandler<T>? m_event;
private int m_counter;

/// <summary>
/// Initialises a new instance.
/// </summary>
/// <param name="registerToEvent">an Action to perform when the first handler is registered for the event</param>
/// <param name="unregisterFromEvent">an Action to perform when the last handler is unregistered from the event</param>
public EventDelegator([NotNull] Action registerToEvent, [NotNull] Action unregisterFromEvent)
public EventDelegator(Action registerToEvent, Action unregisterFromEvent)
{
m_registerToEvent = registerToEvent;
m_unregisterFromEvent = unregisterFromEvent;
Expand Down Expand Up @@ -53,7 +54,7 @@ public event EventHandler<T> Event
/// </summary>
/// <param name="sender">the sender that the event-handler that gets notified of this event will receive</param>
/// <param name="args">the subclass of EventArgs that the event-handler will receive</param>
public void Fire([NotNull] object sender, [NotNull] T args)
public void Fire(object sender, T args)
{
m_event?.Invoke(sender, args);
}
Expand Down
2 changes: 2 additions & 0 deletions src/NetMQ/INetMQPoller.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

using System;

namespace NetMQ
Expand Down
17 changes: 9 additions & 8 deletions src/NetMQ/INetMQSocket.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using JetBrains.Annotations;
#nullable enable

using System;
using NetMQ.Core.Utils;

namespace NetMQ
Expand Down Expand Up @@ -54,7 +55,7 @@ public interface INetMQSocket : IOutgoingSocket, IReceivingSocket, ISocketPollab
/// <exception cref="AddressAlreadyInUseException">The specified address is already in use.</exception>
/// <exception cref="NetMQException">No IO thread was found, or the protocol's listener encountered an
/// error during initialisation.</exception>
void Bind([NotNull] string address);
void Bind(string address);

/// <summary>Binds the specified TCP <paramref name="address"/> to an available port, assigned by the operating system.</summary>
/// <returns>the chosen port-number</returns>
Expand All @@ -64,7 +65,7 @@ public interface INetMQSocket : IOutgoingSocket, IReceivingSocket, ISocketPollab
/// <exception cref="AddressAlreadyInUseException">The specified address is already in use.</exception>
/// <exception cref="NetMQException">No IO thread was found, or the protocol's listener errored during
/// initialisation.</exception>
int BindRandomPort([NotNull] string address);
int BindRandomPort(string address);

/// <summary>
/// Connect the socket to <paramref name="address"/>.
Expand All @@ -74,7 +75,7 @@ public interface INetMQSocket : IOutgoingSocket, IReceivingSocket, ISocketPollab
/// <exception cref="TerminatingException">The socket has been stopped.</exception>
/// <exception cref="NetMQException">No IO thread was found.</exception>
/// <exception cref="AddressAlreadyInUseException">The specified address is already in use.</exception>
void Connect([NotNull] string address);
void Connect(string address);

/// <summary>
/// Disconnect this socket from <paramref name="address"/>.
Expand All @@ -83,7 +84,7 @@ public interface INetMQSocket : IOutgoingSocket, IReceivingSocket, ISocketPollab
/// <exception cref="ObjectDisposedException">thrown if the socket was already disposed</exception>
/// <exception cref="TerminatingException">The socket has been stopped.</exception>
/// <exception cref="EndpointNotFoundException">Endpoint was not found and cannot be disconnected.</exception>
void Disconnect([NotNull] string address);
void Disconnect(string address);

/// <summary>
/// Unbind this socket from <paramref name="address"/>.
Expand All @@ -92,7 +93,7 @@ public interface INetMQSocket : IOutgoingSocket, IReceivingSocket, ISocketPollab
/// <exception cref="ObjectDisposedException">thrown if the socket was already disposed</exception>
/// <exception cref="TerminatingException">The socket has been stopped.</exception>
/// <exception cref="EndpointNotFoundException">Endpoint was not found and cannot be disconnected.</exception>
void Unbind([NotNull] string address);
void Unbind(string address);

/// <summary>Closes this socket, rendering it unusable. Equivalent to calling <see cref="NetMQSocket.Dispose()"/>.</summary>
void Close();
Expand Down Expand Up @@ -137,6 +138,6 @@ public interface INetMQSocket : IOutgoingSocket, IReceivingSocket, ISocketPollab
/// <exception cref="ProtocolNotSupportedException">The protocol of <paramref name="endpoint"/> is not supported.</exception>
/// <exception cref="TerminatingException">The socket has been stopped.</exception>
/// <exception cref="NetMQException">Maximum number of sockets reached.</exception>
void Monitor([NotNull] string endpoint, SocketEvents events = SocketEvents.All);
void Monitor(string endpoint, SocketEvents events = SocketEvents.All);
}
}
4 changes: 3 additions & 1 deletion src/NetMQ/IOutgoingSocket.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
#nullable enable

using System;

namespace NetMQ
{
Expand Down
4 changes: 3 additions & 1 deletion src/NetMQ/IReceivingSocket.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
#nullable enable

using System;

namespace NetMQ
{
Expand Down
3 changes: 1 addition & 2 deletions src/NetMQ/ISocketPollable.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using JetBrains.Annotations;
#nullable enable

namespace NetMQ
{
Expand All @@ -10,7 +10,6 @@ public interface ISocketPollable
/// <summary>
/// Gets a <see cref="NetMQSocket"/> instance.
/// </summary>
[NotNull]
NetMQSocket Socket { get; }

/// <summary>
Expand Down
7 changes: 4 additions & 3 deletions src/NetMQ/ISocketPollableCollection.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable enable

using System;
using JetBrains.Annotations;
using NetMQ.Monitoring;

namespace NetMQ
Expand All @@ -17,13 +18,13 @@ public interface ISocketPollableCollection
/// Add a socket to a poller
/// </summary>
/// <param name="socket"></param>
void Add([NotNull] ISocketPollable socket);
void Add(ISocketPollable socket);

/// <summary>
/// Remove a socket from poller
/// </summary>
/// <param name="socket"></param>
void Remove([NotNull] ISocketPollable socket);
void Remove(ISocketPollable socket);

/// <summary>
/// Remove a socket and dispose it
Expand Down
Loading

0 comments on commit f74c15a

Please sign in to comment.