fix: Telepathy updated to latest version. connectionId counter is properly reset after stopping server.

This commit is contained in:
vis2k 2019-07-29 14:36:15 +02:00
parent c80fe05d50
commit abf06df25d
2 changed files with 6 additions and 8 deletions

View File

@ -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.
@ -42,7 +42,7 @@ public bool TryDequeue(out T result)
{
lock(queue)
{
result = default(T);
result = default;
if (queue.Count > 0)
{
result = queue.Dequeue();

View File

@ -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);