You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-17 07:36:32 +09:00
Bug in fragmentation fixed
This commit is contained in:
@@ -15,15 +15,17 @@ namespace Lidgren.Network
|
|||||||
{
|
{
|
||||||
private int m_lastUsedFragmentGroup;
|
private int m_lastUsedFragmentGroup;
|
||||||
|
|
||||||
private Dictionary<int, ReceivedFragmentGroup> m_receivedFragmentGroups;
|
private Dictionary<NetConnection, Dictionary<int, ReceivedFragmentGroup>> m_receivedFragmentGroups;
|
||||||
|
|
||||||
// on user thread
|
// on user thread
|
||||||
private void SendFragmentedMessage(NetOutgoingMessage msg, IList<NetConnection> recipients, NetDeliveryMethod method, int sequenceChannel)
|
private void SendFragmentedMessage(NetOutgoingMessage msg, IList<NetConnection> recipients, NetDeliveryMethod method, int sequenceChannel)
|
||||||
{
|
{
|
||||||
|
// Note: this group id is PER SENDING/NetPeer; ie. same id is sent to all recipients;
|
||||||
|
// this should be ok however; as long as recipients differentiate between same id but different sender
|
||||||
int group = Interlocked.Increment(ref m_lastUsedFragmentGroup);
|
int group = Interlocked.Increment(ref m_lastUsedFragmentGroup);
|
||||||
if (group >= NetConstants.MaxFragmentationGroups)
|
if (group >= NetConstants.MaxFragmentationGroups)
|
||||||
{
|
{
|
||||||
// TODO: not thread safe; but in practice probably not an issue
|
// @TODO: not thread safe; but in practice probably not an issue
|
||||||
m_lastUsedFragmentGroup = 1;
|
m_lastUsedFragmentGroup = 1;
|
||||||
group = 1;
|
group = 1;
|
||||||
}
|
}
|
||||||
@@ -69,8 +71,6 @@ namespace Lidgren.Network
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void HandleReleasedFragment(NetIncomingMessage im)
|
private void HandleReleasedFragment(NetIncomingMessage im)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -107,13 +107,20 @@ namespace Lidgren.Network
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Dictionary<int, ReceivedFragmentGroup> groups;
|
||||||
|
if (!m_receivedFragmentGroups.TryGetValue(im.SenderConnection, out groups))
|
||||||
|
{
|
||||||
|
groups = new Dictionary<int, ReceivedFragmentGroup>();
|
||||||
|
m_receivedFragmentGroups[im.SenderConnection] = groups;
|
||||||
|
}
|
||||||
|
|
||||||
ReceivedFragmentGroup info;
|
ReceivedFragmentGroup info;
|
||||||
if (!m_receivedFragmentGroups.TryGetValue(group, out info))
|
if (!groups.TryGetValue(group, out info))
|
||||||
{
|
{
|
||||||
info = new ReceivedFragmentGroup();
|
info = new ReceivedFragmentGroup();
|
||||||
info.Data = new byte[totalBytes];
|
info.Data = new byte[totalBytes];
|
||||||
info.ReceivedChunks = new NetBitVector(totalNumChunks);
|
info.ReceivedChunks = new NetBitVector(totalNumChunks);
|
||||||
m_receivedFragmentGroups[group] = info;
|
groups[group] = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
info.ReceivedChunks[chunkNumber] = true;
|
info.ReceivedChunks[chunkNumber] = true;
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ namespace Lidgren.Network
|
|||||||
m_handshakes = new Dictionary<IPEndPoint, NetConnection>();
|
m_handshakes = new Dictionary<IPEndPoint, NetConnection>();
|
||||||
m_senderRemote = (EndPoint)new IPEndPoint(IPAddress.Any, 0);
|
m_senderRemote = (EndPoint)new IPEndPoint(IPAddress.Any, 0);
|
||||||
m_status = NetPeerStatus.NotRunning;
|
m_status = NetPeerStatus.NotRunning;
|
||||||
m_receivedFragmentGroups = new Dictionary<int, ReceivedFragmentGroup>();
|
m_receivedFragmentGroups = new Dictionary<NetConnection, Dictionary<int, ReceivedFragmentGroup>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ namespace FileStreamClient
|
|||||||
{
|
{
|
||||||
s_length = inc.ReadUInt64();
|
s_length = inc.ReadUInt64();
|
||||||
string filename = inc.ReadString();
|
string filename = inc.ReadString();
|
||||||
|
s_form.Text = "Starting...";
|
||||||
s_writeStream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None);
|
s_writeStream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None);
|
||||||
s_timeStarted = Environment.TickCount;
|
s_timeStarted = Environment.TickCount;
|
||||||
break;
|
break;
|
||||||
@@ -91,6 +92,8 @@ namespace FileStreamClient
|
|||||||
|
|
||||||
internal static void Connect(string host, int port)
|
internal static void Connect(string host, int port)
|
||||||
{
|
{
|
||||||
|
s_length = 0;
|
||||||
|
s_received = 0;
|
||||||
s_client.Connect(host, port);
|
s_client.Connect(host, port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user