From 98700f3067180032ef96dbb176300cf3fea56c59 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Mon, 28 Sep 2020 12:50:40 +0200 Subject: [PATCH] Fixed compilation error --- source/dnetd/dconnection.d | 2 +- source/dnetd/dserver.d | 27 ++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/source/dnetd/dconnection.d b/source/dnetd/dconnection.d index 3b2f84d..2ef6cfa 100644 --- a/source/dnetd/dconnection.d +++ b/source/dnetd/dconnection.d @@ -154,7 +154,7 @@ public class DConnection : Thread } /* Remove this user from the connection queue */ - /* TODO: Implement me */ + server.removeConnection(this); } /* TODO: add mutex for writing with message and funciton for doing so */ diff --git a/source/dnetd/dserver.d b/source/dnetd/dserver.d index 8e97b08..77b95f8 100644 --- a/source/dnetd/dserver.d +++ b/source/dnetd/dserver.d @@ -142,16 +142,37 @@ public class DServer : Thread /* Add to the connection queue */ connectionQueue ~= connection; - writeln("Added new connection to queue "~to!(string)(connection)); + writeln("Added connection to queue "~to!(string)(connection)); /* Unlock the connections list */ connectionLock.unlock(); } /* TODO Remove connection */ - public void removeConnection(DConnection client) + public void removeConnection(DConnection connection) { - + /* Lock the connections list */ + connectionLock.lock(); + + /* The new connection queue */ + DConnection[] connectionQueueNew; + + foreach(DConnection currentConnection; connectionQueue) + { + if(!(currentConnection is connection)) + { + connectionQueueNew ~= currentConnection; + } + } + + /* Set this as the new queue */ + connectionQueue = connectionQueueNew; + + /* TODO: Implement removal */ + writeln("Remove connection from queue "~to!(string)(connection)); + + /* Unlock the connections list */ + connectionLock.unlock(); } public DChannel getChannelByName(string channelName)