Added `addConnection(Connection)` implementation

This commit is contained in:
Tristan B. Kildaire 2021-09-29 14:27:21 +02:00
parent a637082c00
commit 1e85b9e17e
1 changed files with 20 additions and 0 deletions

View File

@ -2,6 +2,8 @@ module dnetd.server;
import dnetd.listener;
import dnetd.connection;
import std.container.dlist;
import core.sync.mutex;
public struct ServerConfig
{
@ -20,6 +22,9 @@ public class Server
private Listener[] listeners;
/* TODO: Latwr add mutex for managing lusteners if we do multi thread removal */
private DList!(Connection) connQueue;
private Mutex connQueueLock;
this(ServerConfig config)
{
/* Set the listeners configured */
@ -30,6 +35,21 @@ public class Server
/* Configure all Connection's to use this Server */
Connection.server = this;
/* Initialize all mutexes */
connQueueLock = new Mutex();
}
public void addConnection(Connection connection)
{
/* Lock the queue */
connQueueLock.lock();
/* Append the connection to the queue */
connQueue ~= connection;
/* Unlock the queue */
connQueueLock.unlock();
}
public void run()