Skip to content

Commit

Permalink
fix: Telepathy updated to latest version. connectionId counter is pro…
Browse files Browse the repository at this point in the history
…perly reset after stopping server.
  • Loading branch information
miwarnec committed Jul 29, 2019
1 parent c80fe05 commit abf06df
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Assets/Mirror/Runtime/Transport/Telepathy/SafeQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Telepathy
{
public class SafeQueue<T>
{
Queue<T> queue = new Queue<T>();
readonly Queue<T> queue = new Queue<T>();

// for statistics. don't call Count and assume that it's the same after the
// call.
Expand Down Expand Up @@ -42,7 +42,7 @@ public bool TryDequeue(out T result)
{
lock(queue)
{
result = default(T);
result = default;
if (queue.Count > 0)
{
result = queue.Dequeue();
Expand Down
10 changes: 4 additions & 6 deletions Assets/Mirror/Runtime/Transport/Telepathy/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,17 @@ public ClientToken(TcpClient client)
this.client = client;
}
}

// clients with <connectionId, ClientData>
ConcurrentDictionary<int, ClientToken> clients = new ConcurrentDictionary<int, ClientToken>();
readonly ConcurrentDictionary<int, ClientToken> clients = new ConcurrentDictionary<int, ClientToken>();

// connectionId counter
// (right now we only use it from one listener thread, but we might have
// multiple threads later in case of WebSockets etc.)
// -> static so that another server instance doesn't start at 0 again.
static int counter = 0;
int counter;

// public next id function in case someone needs to reserve an id
// (e.g. if hostMode should always have 0 connection and external
// connections should start at 1, etc.)
public static int NextConnectionId()
public int NextConnectionId()
{
int id = Interlocked.Increment(ref counter);

Expand Down

0 comments on commit abf06df

Please sign in to comment.