Skip to content

Commit 68b4598

Browse files
authored
Merge pull request #887 from drewnoakes/more-annotations
Annotate internal patterns, utils and some public API
2 parents beea615 + 27c1f7c commit 68b4598

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+430
-551
lines changed

src/NetMQ.Tests/MsgTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void Constructor()
2525
Assert.False(msg.IsDelimiter);
2626
Assert.False(msg.IsIdentity);
2727
Assert.False(msg.IsInitialised);
28-
Assert.Throws<NullReferenceException>(() => msg[0] = 1);
28+
Assert.ThrowsAny<Exception>(() => msg[0] = 1);
2929
Assert.Throws<FaultException>((Action)msg.Close);
3030
}
3131

src/NetMQ/Core/Address.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ You should have received a copy of the GNU Lesser General Public License
1818
along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
2020

21-
#nullable disable
22-
2321
using System.Net;
24-
using JetBrains.Annotations;
2522

2623
namespace NetMQ.Core
2724
{
@@ -65,18 +62,18 @@ internal sealed class Address
6562
/// </summary>
6663
public interface IZAddress
6764
{
68-
void Resolve([NotNull] string name, bool ip4Only);
65+
void Resolve(string name, bool ip4Only);
6966

70-
[CanBeNull] IPEndPoint Address { get; }
71-
[NotNull] string Protocol { get; }
67+
IPEndPoint? Address { get; }
68+
string Protocol { get; }
7269
}
7370

7471
/// <summary>
7572
/// Create a new Address instance with the given protocol and text expression of an address.
7673
/// </summary>
7774
/// <param name="protocol">the protocol of this Address - as in tcp, ipc, pgm</param>
7875
/// <param name="address">a text representation of the address</param>
79-
public Address([NotNull] string protocol, [NotNull] string address)
76+
public Address(string protocol, string address)
8077
{
8178
Protocol = protocol;
8279
AddressString = address;
@@ -87,7 +84,7 @@ public Address([NotNull] string protocol, [NotNull] string address)
8784
/// Create a new Address instance based upon the given endpoint, assuming a protocol of tcp.
8885
/// </summary>
8986
/// <param name="endpoint">the subclass of EndPoint to base this Address upon</param>
90-
public Address([NotNull] EndPoint endpoint)
87+
public Address(EndPoint endpoint)
9188
{
9289
Protocol = TcpProtocol;
9390

@@ -126,16 +123,13 @@ public override string ToString()
126123
return Protocol + "://" + AddressString;
127124
}
128125

129-
return null; //TODO: REVIEW - Although not explicitly prohibited, returning null from ToString seems sketchy; return string.Empty?
126+
return base.ToString();
130127
}
131128

132-
[NotNull]
133129
public string Protocol { get; }
134130

135-
[NotNull]
136131
public string AddressString { get; }
137132

138-
[CanBeNull]
139-
public IZAddress Resolved { get; set; }
133+
public IZAddress? Resolved { get; set; }
140134
}
141135
}

src/NetMQ/Core/Command.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ You should have received a copy of the GNU Lesser General Public License
1919
along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*/
2121

22-
#nullable disable
23-
24-
using JetBrains.Annotations;
25-
2622
namespace NetMQ.Core
2723
{
2824
/// <summary>
@@ -36,25 +32,23 @@ internal struct Command
3632
/// <param name="destination">a ZObject that denotes the destination for this command</param>
3733
/// <param name="type">the CommandType of the new command</param>
3834
/// <param name="arg">an Object to comprise the argument for the command (optional)</param>
39-
public Command([CanBeNull] ZObject destination, CommandType type, [CanBeNull] object arg = null) : this()
35+
public Command(ZObject? destination, CommandType type, object? arg = null) : this()
4036
{
4137
Destination = destination;
4238
CommandType = type;
4339
Arg = arg;
4440
}
4541

4642
/// <summary>The destination to which the command should be applied.</summary>
47-
[CanBeNull]
48-
public ZObject Destination { get; }
43+
public ZObject? Destination { get; }
4944

5045
/// <summary>The type of this command.</summary>
5146
public CommandType CommandType { get; }
5247

5348
/// <summary>
5449
/// Get the argument to this command.
5550
/// </summary>
56-
[CanBeNull]
57-
public object Arg { get; }
51+
public object? Arg { get; }
5852

5953
/// <summary>
6054
/// Override of ToString, which returns a string in the form [ command-type, destination ].

src/NetMQ/Core/CommandType.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
namespace NetMQ.Core
42
{
53
/// <summary>

src/NetMQ/Core/Config.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ You should have received a copy of the GNU Lesser General Public License
1919
along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*/
2121

22-
#nullable disable
23-
2422
namespace NetMQ.Core
2523
{
2624
/// <summary>

src/NetMQ/Core/ErrorHelper.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#nullable disable
2-
3-
using System.Diagnostics;
1+
using System.Diagnostics;
42
using System.Net.Sockets;
53

64
namespace NetMQ.Core

src/NetMQ/Core/HellloMsgSession.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
#nullable disable
2-
3-
using JetBrains.Annotations;
4-
51
namespace NetMQ.Core
62
{
73
class HelloMsgSession : SessionBase
84
{
95
bool m_newPipe;
106

11-
public HelloMsgSession([NotNull] IOThread ioThread, bool connect, [NotNull] SocketBase socket, [NotNull] Options options, [NotNull] Address addr) :
7+
public HelloMsgSession(IOThread ioThread, bool connect, SocketBase socket, Options options, Address addr) :
128
base(ioThread, connect, socket, options, addr)
139
{
1410
m_newPipe = true;
@@ -18,6 +14,8 @@ public override PullMsgResult PullMsg(ref Msg msg)
1814
{
1915
if (m_newPipe)
2016
{
17+
Assumes.NotNull(m_options.HelloMsg);
18+
2119
m_newPipe = false;
2220
msg.InitPool(m_options.HelloMsg.Length);
2321
msg.Put(m_options.HelloMsg, 0, m_options.HelloMsg.Length);

src/NetMQ/Core/IMailbox.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
#nullable disable
2-
3-
using JetBrains.Annotations;
4-
51
namespace NetMQ.Core
62
{
73
internal interface IMailbox
84
{
9-
void Send([NotNull] Command command);
5+
void Send(Command command);
106

117
bool TryRecv(int timeout, out Command command);
128

src/NetMQ/Core/IOObject.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@ You should have received a copy of the GNU Lesser General Public License
1919
along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*/
2121

22-
#nullable disable
23-
2422
using System.Diagnostics;
2523
using System.Net.Sockets;
2624
using AsyncIO;
27-
using JetBrains.Annotations;
2825

2926
namespace NetMQ.Core
3027
{
@@ -35,16 +32,14 @@ namespace NetMQ.Core
3532
/// </summary>
3633
internal class IOObject : IProactorEvents
3734
{
38-
[CanBeNull]
39-
private IOThread m_ioThread;
40-
[CanBeNull]
41-
private IProactorEvents m_handler;
35+
private IOThread? m_ioThread;
36+
private IProactorEvents? m_handler;
4237

4338
/// <summary>
4439
/// Create a new IOObject object and plug it into the given IOThread.
4540
/// </summary>
4641
/// <param name="ioThread">the IOThread to plug this new IOObject into.</param>
47-
public IOObject([CanBeNull] IOThread ioThread)
42+
public IOObject(IOThread? ioThread)
4843
{
4944
if (ioThread != null)
5045
Plug(ioThread);
@@ -58,7 +53,7 @@ public IOObject([CanBeNull] IOThread ioThread)
5853
/// When migrating an object from one I/O thread to another, first
5954
/// unplug it, then migrate it, then plug it to the new thread.
6055
/// </remarks>
61-
public void Plug([NotNull] IOThread ioThread)
56+
public void Plug(IOThread ioThread)
6257
{
6358
Debug.Assert(ioThread != null);
6459

@@ -74,7 +69,7 @@ public void Plug([NotNull] IOThread ioThread)
7469
/// </remarks>
7570
public void Unplug()
7671
{
77-
Debug.Assert(m_ioThread != null);
72+
Assumes.NotNull(m_ioThread);
7873

7974
// Forget about old poller in preparation to be migrated
8075
// to a different I/O thread.
@@ -86,17 +81,19 @@ public void Unplug()
8681
/// Add the given socket to the Proactor.
8782
/// </summary>
8883
/// <param name="socket">the AsyncSocket to add</param>
89-
public void AddSocket([NotNull] AsyncSocket socket)
84+
public void AddSocket(AsyncSocket socket)
9085
{
86+
Assumes.NotNull(m_ioThread);
9187
m_ioThread.Proactor.AddSocket(socket, this);
9288
}
9389

9490
/// <summary>
9591
/// Remove the given socket from the Proactor.
9692
/// </summary>
9793
/// <param name="socket">the AsyncSocket to remove</param>
98-
public void RemoveSocket([NotNull] AsyncSocket socket)
94+
public void RemoveSocket(AsyncSocket socket)
9995
{
96+
Assumes.NotNull(m_ioThread);
10097
m_ioThread.Proactor.RemoveSocket(socket);
10198
}
10299

@@ -107,6 +104,7 @@ public void RemoveSocket([NotNull] AsyncSocket socket)
107104
/// <param name="bytesTransferred">the number of bytes that were transferred</param>
108105
public virtual void InCompleted(SocketError socketError, int bytesTransferred)
109106
{
107+
Assumes.NotNull(m_handler);
110108
m_handler.InCompleted(socketError, bytesTransferred);
111109
}
112110

@@ -117,6 +115,7 @@ public virtual void InCompleted(SocketError socketError, int bytesTransferred)
117115
/// <param name="bytesTransferred">the number of bytes that were transferred</param>
118116
public virtual void OutCompleted(SocketError socketError, int bytesTransferred)
119117
{
118+
Assumes.NotNull(m_handler);
120119
m_handler.OutCompleted(socketError, bytesTransferred);
121120
}
122121

@@ -126,21 +125,24 @@ public virtual void OutCompleted(SocketError socketError, int bytesTransferred)
126125
/// <param name="id">an integer used to identify the timer</param>
127126
public virtual void TimerEvent(int id)
128127
{
128+
Assumes.NotNull(m_handler);
129129
m_handler.TimerEvent(id);
130130
}
131131

132132
public void AddTimer(long timeout, int id)
133133
{
134+
Assumes.NotNull(m_ioThread);
134135
m_ioThread.Proactor.AddTimer(timeout, this, id);
135136
}
136137

137-
public void SetHandler([NotNull] IProactorEvents handler)
138+
public void SetHandler(IProactorEvents handler)
138139
{
139140
m_handler = handler;
140141
}
141142

142143
public void CancelTimer(int id)
143144
{
145+
Assumes.NotNull(m_ioThread);
144146
m_ioThread.Proactor.CancelTimer(this, id);
145147
}
146148
}

src/NetMQ/Core/IOThread.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ You should have received a copy of the GNU Lesser General Public License
1919
along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*/
2121

22-
#nullable disable
23-
24-
using JetBrains.Annotations;
2522
using NetMQ.Core.Utils;
2623

2724
namespace NetMQ.Core
@@ -50,7 +47,7 @@ internal sealed class IOThread : ZObject, IMailboxEvent
5047
/// </summary>
5148
/// <param name="ctx">the Ctx (context) for this thread to live within</param>
5249
/// <param name="threadId">the integer thread-id for this new IOThread</param>
53-
public IOThread([NotNull] Ctx ctx, int threadId)
50+
public IOThread(Ctx ctx, int threadId)
5451
: base(ctx, threadId)
5552
{
5653
var name = "iothread-" + threadId;
@@ -62,7 +59,6 @@ public IOThread([NotNull] Ctx ctx, int threadId)
6259
#endif
6360
}
6461

65-
[NotNull]
6662
internal Proactor Proactor => m_proactor;
6763

6864
public void Start()
@@ -81,7 +77,6 @@ public void Stop()
8177
SendStop();
8278
}
8379

84-
[NotNull]
8580
public IMailbox Mailbox => m_mailbox;
8681

8782
public int Load => m_proactor.Load;
@@ -95,7 +90,10 @@ public void Ready()
9590
{
9691
// Process all available commands.
9792
while (m_mailbox.TryRecv(out Command command))
93+
{
94+
Assumes.NotNull(command.Destination);
9895
command.Destination.ProcessCommand(command);
96+
}
9997
}
10098

10199
#if DEBUG

0 commit comments

Comments
 (0)