1
0
mirror of https://github.com/deavminet/dnetd synced 2024-09-21 17:53:39 +02:00

Added method, construcListeners(), to instantiate listeners

This commit is contained in:
Tristan B. Kildaire 2020-12-20 17:39:56 +02:00
parent b9513bae96
commit aec29f0fd1
2 changed files with 31 additions and 3 deletions

View File

@ -27,7 +27,7 @@ public final class DListener : Thread
this.server = server; this.server = server;
// /* Get the Address */ // /* Get the Address */
// Address address = addressInfo.address; Address address = addressInfo.address;

View File

@ -66,8 +66,8 @@ public class DServer : Thread
/* Set the server's config */ /* Set the server's config */
this.config = config; this.config = config;
/* Set the listening address */ /* Construct the listeners */
this.sockAddress = config.getGeneral().getAddress(); constructListeners(config.getGeneral().getAddresses());
/* Initialize the server */ /* Initialize the server */
init(); init();
@ -76,6 +76,34 @@ public class DServer : Thread
startServer(); startServer();
} }
private void constructListeners(Address[] listenAddresses)
{
gprintln("Constructing "~to!(string)(listenAddresses.length)~" listsners...");
foreach(Address listenAddress; listenAddresses)
{
gprintln("Constructing listener for address '"~to!(string)(listenAddress)~"'");
import std.socket : AddressInfo;
AddressInfo addrInfo;
/* Set the address (and port) to the current one along with address family */
addrInfo.address = listenAddress;
addrInfo.family = listenAddress.addressFamily;
/* Set standard stuff */
addrInfo.protocol = ProtocolType.TCP;
addrInfo.type = SocketType.STREAM;
/* Construct the listener */
listeners ~= new DListener(this, addrInfo);
gprintln("Listener for '"~to!(string)(listenAddress)~"' constructed");
}
gprintln("Listener construction complete.");
}
public DConfig getConfig() public DConfig getConfig()
{ {
return config; return config;