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;
// /* 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 */
this.config = config;
/* Set the listening address */
this.sockAddress = config.getGeneral().getAddress();
/* Construct the listeners */
constructListeners(config.getGeneral().getAddresses());
/* Initialize the server */
init();
@ -76,6 +76,34 @@ public class DServer : Thread
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()
{
return config;