Skip to content

Commit

Permalink
fix: Telepathy works on .net core again
Browse files Browse the repository at this point in the history
  • Loading branch information
miwarnec committed Jan 13, 2020
1 parent 078b7dd commit cb3d9f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
13 changes: 6 additions & 7 deletions Assets/Mirror/Runtime/Transport/Telepathy/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ void ReceiveThreadFunction(string ip, int port)
// otherwise the send thread would only end if it's
// actually sending data while the connection is
// closed.
// => AbortAndJoin is the safest way and avoids race conditions!
sendThread?.AbortAndJoin();
sendThread?.Interrupt();

// Connect might have failed. thread might have been closed.
// let's reset connecting state no matter what.
Expand Down Expand Up @@ -162,11 +161,11 @@ public void Disconnect()
// close client
client.Close();

// kill the receive thread
// => AbortAndJoin is the safest way and avoids race conditions!
// this way we can guarantee that when Disconnect() returns,
// we are 100% ready for the next Connect!
receiveThread?.AbortAndJoin();
// wait until thread finished. this is the only way to guarantee
// that we can call Connect() again immediately after Disconnect
// -> calling .Join would sometimes wait forever, e.g. when
// calling Disconnect while trying to connect to a dead end
receiveThread?.Interrupt();

// we interrupted the receive Thread, so we can't guarantee that
// connecting was reset. let's do it manually.
Expand Down
17 changes: 3 additions & 14 deletions Assets/Mirror/Runtime/Transport/Telepathy/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ void Listen(int port)
// otherwise the send thread would only end if it's
// actually sending data while the connection is
// closed.
// => AbortAndJoin is the safest way and avoids race conditions!
sendThread.AbortAndJoin();
sendThread.Interrupt();
}
catch (Exception exception)
{
Expand Down Expand Up @@ -215,18 +214,8 @@ public void Stop()

// kill listener thread at all costs. only way to guarantee that
// .Active is immediately false after Stop.
// => AbortAndJoin is the safest way and avoids race conditions!
listenerThread?.AbortAndJoin();

// wait until thread is TRULY finished. this is the only way
// to guarantee that everything was properly cleaned up before
// returning.
// => this means that calling Stop() may sometimes block
// for a while, but there is no other way to guarantee that
// everything is cleaned up properly by the time Stop() returns.
// we have to live with the wait time.
listenerThread?.Join();

// -> calling .Join would sometimes wait forever
listenerThread?.Interrupt();
listenerThread = null;

// close all client connections
Expand Down

0 comments on commit cb3d9f0

Please sign in to comment.