Skip to content

Commit

Permalink
Fix nullability for NetConnection send/receive channel arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
PJB3005 committed Jan 23, 2024
1 parent e330eae commit 9811c5f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Lidgren.Network/NetConnection.Handshake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ internal void ExecuteDisconnect(string? reason, bool sendByeMessage)
// clear send queues
for (int i = 0; i < m_sendChannels.Length; i++)
{
NetSenderChannelBase channel = m_sendChannels[i];
NetSenderChannelBase? channel = m_sendChannels[i];
if (channel != null)
channel.Reset();
}
Expand Down
12 changes: 6 additions & 6 deletions Lidgren.Network/NetConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public partial class NetConnection
internal NetConnectionStatus m_outputtedStatus; // status that has been sent as StatusChanged message
internal NetConnectionStatus m_visibleStatus; // status visible by querying the Status property
internal NetEndPoint m_remoteEndPoint;
internal NetSenderChannelBase[] m_sendChannels;
internal NetReceiverChannelBase[] m_receiveChannels;
internal NetSenderChannelBase?[] m_sendChannels;
internal NetReceiverChannelBase?[] m_receiveChannels;
internal NetOutgoingMessage? m_localHailMessage;
internal long m_remoteUniqueIdentifier;
internal NetQueue<NetTuple<NetMessageType, int>> m_queuedOutgoingAcks;
Expand Down Expand Up @@ -243,7 +243,7 @@ internal void Heartbeat(double now, uint frameCounter)
while (m_queuedIncomingAcks.TryDequeue(out NetTuple<NetMessageType, int> incAck))
{
//m_peer.LogVerbose("Received ack for " + acktp + "#" + seqNr);
NetSenderChannelBase chan = m_sendChannels[(int)incAck.Item1 - 1];
NetSenderChannelBase? chan = m_sendChannels[(int)incAck.Item1 - 1];

// If we haven't sent a message on this channel there is no reason to ack it
if (chan == null)
Expand Down Expand Up @@ -351,7 +351,7 @@ internal NetSendResult EnqueueMessage(NetOutgoingMessage msg, NetDeliveryMethod

// TODO: do we need to make this more thread safe?
int channelSlot = (int)method - 1 + sequenceChannel;
NetSenderChannelBase chan = m_sendChannels[channelSlot];
NetSenderChannelBase? chan = m_sendChannels[channelSlot];
if (chan == null)
chan = CreateSenderChannel(tp);

Expand All @@ -377,7 +377,7 @@ private NetSenderChannelBase CreateSenderChannel(NetMessageType tp)
if (m_sendChannels[channelSlot] != null)
{
// we were pre-empted by another call to this method
chan = m_sendChannels[channelSlot];
chan = m_sendChannels[channelSlot]!;
}
else
{
Expand Down Expand Up @@ -488,7 +488,7 @@ internal void ReceivedMessage(NetIncomingMessage msg)
NetMessageType tp = msg.m_receivedMessageType;

int channelSlot = (int)tp - 1;
NetReceiverChannelBase chan = m_receiveChannels[channelSlot];
NetReceiverChannelBase? chan = m_receiveChannels[channelSlot];
if (chan == null)
chan = CreateReceiverChannel(tp);

Expand Down
4 changes: 2 additions & 2 deletions Lidgren.Network/NetConnectionStatistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ internal void Reset()
private int GetWithheldMessages()
{
int numWithheld = 0;
foreach (NetReceiverChannelBase recChan in m_connection.m_receiveChannels)
foreach (NetReceiverChannelBase? recChan in m_connection.m_receiveChannels)
{
var relRecChan = recChan as NetReliableOrderedReceiver;
if (relRecChan == null)
Expand All @@ -154,7 +154,7 @@ private void CalculateUnsentAndStoredMessages(out int numUnsent, out int numStor
{
numUnsent = 0;
numStored = 0;
foreach (NetSenderChannelBase sendChan in m_connection.m_sendChannels)
foreach (NetSenderChannelBase? sendChan in m_connection.m_sendChannels)
{
if (sendChan == null)
continue;
Expand Down

0 comments on commit 9811c5f

Please sign in to comment.