Added mutexes to 'join' command, added toString to DChannel

This commit is contained in:
Tristan 🅱. Kildaire 2020-09-23 19:12:12 +02:00
parent 7e1e361c21
commit c55a9b9419
1 changed files with 26 additions and 1 deletions

View File

@ -9,6 +9,7 @@
module dnetd.dchannel;
import dnetd.dconnection : DConnection;
import core.sync.mutex : Mutex;
public class DChannel
{
@ -22,10 +23,12 @@ public class DChannel
* Users in this channel
*/
private DConnection[] members;
private Mutex memberLock;
this(string name)
{
/* Initialize the lock */
memberLock = new Mutex();
}
public string getName()
@ -34,8 +37,30 @@ public class DChannel
}
public void join(DConnection client)
{
/* Lock the members list */
memberLock.lock();
/**
* TODO: Error handling if the calling DConnection fails midway
* and doesn't unlock it
*/
/* Add the client */
members ~= client;
/* Unlock the members list */
memberLock.unlock();
}
public void leave(DConnection client)
{
}
public override string toString()
{
return "DChannel [Name: "~name~", Members: "~members~"]";
}
}