mirror of
https://github.com/deavminet/dnetd
synced 2024-09-21 17:53:39 +02:00
Removed sockets from dserver.d, sockets are now per each DListener
This commit is contained in:
parent
40cb881816
commit
9e3da7d09f
@ -25,13 +25,6 @@ import gogga;
|
|||||||
|
|
||||||
public class DServer : Thread
|
public class DServer : Thread
|
||||||
{
|
{
|
||||||
/* The server's socket to bind, listen and accept connections from */
|
|
||||||
private Socket serverSocket;
|
|
||||||
|
|
||||||
/* Bind address */
|
|
||||||
private Address sockAddress;
|
|
||||||
|
|
||||||
|
|
||||||
/* Server configuration */
|
/* Server configuration */
|
||||||
private DConfig config;
|
private DConfig config;
|
||||||
|
|
||||||
@ -67,7 +60,7 @@ public class DServer : Thread
|
|||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
/* Construct the listeners */
|
/* Construct the listeners */
|
||||||
constructListeners(config.getGeneral().getAddresses());
|
initListeners(config.getGeneral().getAddresses());
|
||||||
|
|
||||||
/* Initialize the server */
|
/* Initialize the server */
|
||||||
init();
|
init();
|
||||||
@ -76,7 +69,12 @@ public class DServer : Thread
|
|||||||
startServer();
|
startServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void constructListeners(Address[] listenAddresses)
|
/**
|
||||||
|
* Given an array of Address(es) this will construct all
|
||||||
|
* the corresponding listsners (DListener) and append them
|
||||||
|
* to the array
|
||||||
|
*/
|
||||||
|
private void initListeners(Address[] listenAddresses)
|
||||||
{
|
{
|
||||||
gprintln("Constructing "~to!(string)(listenAddresses.length)~" listsners...");
|
gprintln("Constructing "~to!(string)(listenAddresses.length)~" listsners...");
|
||||||
|
|
||||||
@ -110,9 +108,6 @@ public class DServer : Thread
|
|||||||
|
|
||||||
private void init()
|
private void init()
|
||||||
{
|
{
|
||||||
/* Setup socket */
|
|
||||||
initNetwork();
|
|
||||||
|
|
||||||
/* Setup queues */
|
/* Setup queues */
|
||||||
initQueues();
|
initQueues();
|
||||||
|
|
||||||
@ -120,19 +115,6 @@ public class DServer : Thread
|
|||||||
initLocks();
|
initLocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the socket, binds it
|
|
||||||
* to the given address
|
|
||||||
*/
|
|
||||||
private void initNetwork()
|
|
||||||
{
|
|
||||||
/* Create the socket */
|
|
||||||
serverSocket = new Socket(AddressFamily.INET, SocketType.STREAM, ProtocolType.TCP);
|
|
||||||
|
|
||||||
/* Bind the socket to the given address */
|
|
||||||
serverSocket.bind(sockAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates all needed queues
|
* Creates all needed queues
|
||||||
* and their mutexes
|
* and their mutexes
|
||||||
@ -165,24 +147,6 @@ public class DServer : Thread
|
|||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dequeueLoop()
|
|
||||||
{
|
|
||||||
/* Start accepting-and-enqueuing connections */
|
|
||||||
serverSocket.listen(0); /* TODO: Linux be lile, hehahahhahahah who gives one - I give zero */
|
|
||||||
|
|
||||||
while(true)
|
|
||||||
{
|
|
||||||
/* Dequeue a connection */
|
|
||||||
Socket socket = serverSocket.accept();
|
|
||||||
|
|
||||||
/* Spawn a connection handler */
|
|
||||||
DConnection connection = new DConnection(this, socket);
|
|
||||||
|
|
||||||
/* Add to the connection queue */
|
|
||||||
addConnection(connection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addChannel(DConnection causer, DChannel channel)
|
public void addChannel(DConnection causer, DChannel channel)
|
||||||
{
|
{
|
||||||
/* Lock the channels list */
|
/* Lock the channels list */
|
||||||
|
Loading…
Reference in New Issue
Block a user