Skip to content

Commit

Permalink
fix reliable channel (fix #129)
Browse files Browse the repository at this point in the history
  • Loading branch information
RevenantX committed Jan 14, 2018
1 parent 2d0defb commit 2050858
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
4 changes: 4 additions & 0 deletions LibSample/EchoMessagesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public void Run()
_serverListener = new ServerListener();

NetManager server = new NetManager(_serverListener, 2, "myapp1");
server.SimulatePacketLoss = true;
server.SimulationPacketLossChance = 70;
//server.ReuseAddress = true;
if (!server.Start(9050))
{
Expand All @@ -152,6 +154,8 @@ public void Run()

NetManager client1 = new NetManager(_clientListener, "myapp1");
//client1.SimulateLatency = true;
client1.SimulatePacketLoss = true;
client1.SimulationPacketLossChance = 70;
client1.SimulationMaxLatency = 1500;
client1.MergeEnabled = true;
if (!client1.Start())
Expand Down
32 changes: 17 additions & 15 deletions LibSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
using System;
using LibSample;
using LiteNetLib;

class Program
namespace LibSample
{
static void Main(string[] args)
class Program
{
//Test ntp
NetUtils.RequestTimeFromNTP("pool.ntp.org", 123, dateTime =>
static void Main(string[] args)
{
if (dateTime.HasValue)
//Test ntp
NetUtils.RequestTimeFromNTP("pool.ntp.org", 123, dateTime =>
{
Console.WriteLine("[MAIN] Synced time test: " + dateTime.Value);
}
});
if (dateTime.HasValue)
{
Console.WriteLine("[MAIN] Synced time test: " + dateTime.Value);
}
});

//new EchoMessagesTest().Run();
//new HolePunchServerTest().Run();
//new BroadcastTest().Run();
new EchoMessagesTest().Run();
//new HolePunchServerTest().Run();
//new BroadcastTest().Run();

//new BenchmarkTest.TestHost().Run();
new SpeedBecnh().Run();
//new SerializerTest().Run();
//new BenchmarkTest.TestHost().Run();
//new SpeedBecnh().Run();
//new SerializerTest().Run();
}
}
}
13 changes: 5 additions & 8 deletions LiteNetLib/ReliableChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ private sealed class PendingPacket
public PendingPacket Next;
public PendingPacket Prev;

public NetPacket GetAndClear()
public void Clear()
{
if (Prev != null)
{
Expand All @@ -25,11 +25,8 @@ public NetPacket GetAndClear()
}
Prev = null;
Next = null;

var packet = Packet;
Packet = null;
TimeStamp = null;
return packet;
}
}

Expand Down Expand Up @@ -143,14 +140,14 @@ public void ProcessAck(NetPacket packet)
}

PendingPacket pendingPacket = _pendingPackets[ackSequence % _windowSize];
NetPacket removed = pendingPacket.GetAndClear();
if (removed != null)
if (pendingPacket.Packet != null)
{
if (pendingPacket == _headPendingPacket)
{
_headPendingPacket = null;
_headPendingPacket = _headPendingPacket.Prev;
}
_peer.Recycle(removed);
_peer.Recycle(pendingPacket.Packet);
pendingPacket.Clear();
NetUtils.DebugWrite("[PA]Removing reliableInOrder ack: {0} - true", ackSequence);
}
else
Expand Down

0 comments on commit 2050858

Please sign in to comment.