mirror of
https://github.com/deavminet/dnetd
synced 2024-09-21 09:43:37 +02:00
Added mutexes to 'join' command, added toString to DChannel
This commit is contained in:
parent
7e1e361c21
commit
c55a9b9419
@ -9,6 +9,7 @@
|
|||||||
module dnetd.dchannel;
|
module dnetd.dchannel;
|
||||||
|
|
||||||
import dnetd.dconnection : DConnection;
|
import dnetd.dconnection : DConnection;
|
||||||
|
import core.sync.mutex : Mutex;
|
||||||
|
|
||||||
public class DChannel
|
public class DChannel
|
||||||
{
|
{
|
||||||
@ -22,10 +23,12 @@ public class DChannel
|
|||||||
* Users in this channel
|
* Users in this channel
|
||||||
*/
|
*/
|
||||||
private DConnection[] members;
|
private DConnection[] members;
|
||||||
|
private Mutex memberLock;
|
||||||
|
|
||||||
this(string name)
|
this(string name)
|
||||||
{
|
{
|
||||||
|
/* Initialize the lock */
|
||||||
|
memberLock = new Mutex();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string getName()
|
public string getName()
|
||||||
@ -34,8 +37,30 @@ public class DChannel
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void join(DConnection client)
|
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~"]";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user