Skip to content

Commit

Permalink
Merge pull request lcm-proj#18 from simbaforrest/master
Browse files Browse the repository at this point in the history
Fixed lcm-dotnet Close() issue
  • Loading branch information
ashuang committed Feb 22, 2015
2 parents a2443ec + ffabc77 commit 6780ede
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lcm-dotnet/lcm/lcm/UDPMulticastProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class UDPMulticastProvider : Provider
private const int FRAGMENTATION_THRESHOLD = 64000;

private Thread reader;
private volatile bool readerDone = false;

private int msgSeqNumber = 0;

Expand Down Expand Up @@ -148,6 +149,8 @@ public void Close()
if (reader != null)
{
reader.Interrupt();
readerDone = true;
sock.Close(); // close early to interrupt the blocking call: sock.Receive
try
{
reader.Join();
Expand Down Expand Up @@ -266,16 +269,24 @@ private void ReaderThreadRun()
byte[] packetData;
IPEndPoint from = new IPEndPoint(IPAddress.Any, 0);

while (true)
readerDone = false;
while (!readerDone)
{
try
{
packetData = sock.Receive(ref from);
HandlePacket(packetData, from);
}
catch(SocketException ex)
{
if (readerDone) break; // finish if readerDone is true
Console.Error.WriteLine("Ex: " + ex);
continue;
}
catch (Exception ex)
{
Console.Error.WriteLine("Ex: " + ex);
if (readerDone) break;
continue;
}
}
Expand Down

0 comments on commit 6780ede

Please sign in to comment.