Updated Telepathy to latest version

This commit is contained in:
vis2k 2018-08-17 13:20:44 +02:00
parent 23acffbe12
commit 437fb06728
2 changed files with 15 additions and 7 deletions

View File

@ -7,12 +7,6 @@ namespace Telepathy
public abstract class Common public abstract class Common
{ {
// common code ///////////////////////////////////////////////////////// // common code /////////////////////////////////////////////////////////
// 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.
protected static SafeCounter counter = new SafeCounter();
// incoming message queue of <connectionId, message> // incoming message queue of <connectionId, message>
// (not a HashSet because one connection can have multiple new messages) // (not a HashSet because one connection can have multiple new messages)
protected SafeQueue<Message> messageQueue = new SafeQueue<Message>(); protected SafeQueue<Message> messageQueue = new SafeQueue<Message>();

View File

@ -15,6 +15,20 @@ public class Server : Common
// clients with <connectionId, TcpClient> // clients with <connectionId, TcpClient>
SafeDictionary<uint, TcpClient> clients = new SafeDictionary<uint, TcpClient>(); SafeDictionary<uint, TcpClient> clients = new SafeDictionary<uint, TcpClient>();
// 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 SafeCounter counter = new SafeCounter();
// 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 uint NextConnectionId()
{
return counter.Next();
}
// check if the server is running // check if the server is running
public bool Active public bool Active
{ {
@ -45,7 +59,7 @@ void Listen(int port)
TcpClient client = listener.AcceptTcpClient(); TcpClient client = listener.AcceptTcpClient();
// generate the next connection id (thread safely) // generate the next connection id (thread safely)
uint connectionId = counter.Next(); uint connectionId = NextConnectionId();
// spawn a thread for each client to listen to his // spawn a thread for each client to listen to his
// messages // messages