From 9c853b22c37d871302156358ab275f9014cbac8b Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Sat, 9 May 2020 15:19:57 +0200 Subject: [PATCH] Added `toString`s for all the listeners. --- source/listeners/listener.d | 6 ++++++ source/listeners/types.d | 18 ++++++++++++++++++ source/server/informer/client.d | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/source/listeners/listener.d b/source/listeners/listener.d index 8a33e19..8c5e48d 100644 --- a/source/listeners/listener.d +++ b/source/listeners/listener.d @@ -27,6 +27,9 @@ public class BesterListener : Thread /* Whether or not the listener is active */ private bool active = true; + /* the address of this listener */ + protected Address address; + this(BesterServer besterServer) { /* Set the function address to be called as the worker function */ @@ -43,6 +46,9 @@ public class BesterListener : Thread { /* Set the server socket */ this.serverSocket = serverSocket; + + /* Set the address */ + address = serverSocket.localAddress(); } /** diff --git a/source/listeners/types.d b/source/listeners/types.d index 2d31e5c..bac2ef7 100644 --- a/source/listeners/types.d +++ b/source/listeners/types.d @@ -19,6 +19,12 @@ public final class UNIXListener : BesterListener unixSocket.bind(address); return unixSocket; } + + override public string toString() + { + string address = "unix://"~super.address.toAddrString(); + return address; + } } public final class TCP4Listener : BesterListener @@ -35,6 +41,12 @@ public final class TCP4Listener : BesterListener tcp4Socket.bind(address); return tcp4Socket; } + + override public string toString() + { + string address = "tcp4://"~super.address.toAddrString(); + return address; + } } public final class TCP6Listener : BesterListener @@ -51,5 +63,11 @@ public final class TCP6Listener : BesterListener tcp6Socket.bind(address); return tcp6Socket; } + + override public string toString() + { + string address = "tcp6://"~super.address.toAddrString(); + return address; + } } diff --git a/source/server/informer/client.d b/source/server/informer/client.d index 070e472..bcb0750 100644 --- a/source/server/informer/client.d +++ b/source/server/informer/client.d @@ -201,7 +201,7 @@ public final class BesterInformerClient : Thread for(ulong i = 0; i < server.listeners.length; i++) { JSONValue listener; - listener["address"] = server.listeners[i].getServerSocket().localAddress().toAddrString(); + listener["address"] = server.listeners[i].toString(); listenersBlock["listener"~to!(string)(i)] = listener; }