From aec29f0fd1d000cb09d79e006887921aac792aed Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Sun, 20 Dec 2020 17:39:56 +0200 Subject: [PATCH] Added method, `construcListeners()`, to instantiate listeners --- source/dnetd/dlistener.d | 2 +- source/dnetd/dserver.d | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/source/dnetd/dlistener.d b/source/dnetd/dlistener.d index b952523..ee12eaa 100644 --- a/source/dnetd/dlistener.d +++ b/source/dnetd/dlistener.d @@ -27,7 +27,7 @@ public final class DListener : Thread this.server = server; // /* Get the Address */ - // Address address = addressInfo.address; + Address address = addressInfo.address; diff --git a/source/dnetd/dserver.d b/source/dnetd/dserver.d index e6ad0cc..8fd3b4a 100644 --- a/source/dnetd/dserver.d +++ b/source/dnetd/dserver.d @@ -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;