1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-18 16:16:35 +09:00

Made CreateSenderChannel() reentrant

This commit is contained in:
lidgren
2012-02-09 14:56:42 +00:00
parent 66f4365103
commit 7be71a7873

View File

@@ -332,27 +332,38 @@ namespace Lidgren.Network
private NetSenderChannelBase CreateSenderChannel(NetMessageType tp) private NetSenderChannelBase CreateSenderChannel(NetMessageType tp)
{ {
NetSenderChannelBase chan; NetSenderChannelBase chan;
NetDeliveryMethod method = NetUtility.GetDeliveryMethod(tp); lock (m_sendChannels)
int sequenceChannel = (int)tp - (int)method;
switch (method)
{ {
case NetDeliveryMethod.Unreliable: NetDeliveryMethod method = NetUtility.GetDeliveryMethod(tp);
case NetDeliveryMethod.UnreliableSequenced: int sequenceChannel = (int)tp - (int)method;
chan = new NetUnreliableSenderChannel(this, NetUtility.GetWindowSize(method));
break;
case NetDeliveryMethod.ReliableOrdered:
chan = new NetReliableSenderChannel(this, NetUtility.GetWindowSize(method));
break;
case NetDeliveryMethod.ReliableSequenced:
case NetDeliveryMethod.ReliableUnordered:
default:
chan = new NetReliableSenderChannel(this, NetUtility.GetWindowSize(method));
break;
}
int channelSlot = (int)method - 1 + sequenceChannel; int channelSlot = (int)method - 1 + sequenceChannel;
NetException.Assert(m_sendChannels[channelSlot] == null); if (m_sendChannels[channelSlot] != null)
m_sendChannels[channelSlot] = chan; {
// we were pre-empted by another call to this method
chan = m_sendChannels[channelSlot];
}
else
{
switch (method)
{
case NetDeliveryMethod.Unreliable:
case NetDeliveryMethod.UnreliableSequenced:
chan = new NetUnreliableSenderChannel(this, NetUtility.GetWindowSize(method));
break;
case NetDeliveryMethod.ReliableOrdered:
chan = new NetReliableSenderChannel(this, NetUtility.GetWindowSize(method));
break;
case NetDeliveryMethod.ReliableSequenced:
case NetDeliveryMethod.ReliableUnordered:
default:
chan = new NetReliableSenderChannel(this, NetUtility.GetWindowSize(method));
break;
}
m_sendChannels[channelSlot] = chan;
}
}
return chan; return chan;
} }