From a8cee217f758b38e141719bb77064cfb0c52c0ac Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Fri, 22 Sep 2023 17:55:52 +0200 Subject: [PATCH] CoapMessagingLayer - Using a composed `Thread` instead of inheriting from `Thread` --- source/doap/client/messaging.d | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/source/doap/client/messaging.d b/source/doap/client/messaging.d index cbf1890..6847e4e 100644 --- a/source/doap/client/messaging.d +++ b/source/doap/client/messaging.d @@ -25,13 +25,18 @@ import std.socket : Socket, Address, SocketType, ProtocolType, getAddress, parse * Handles the actual sending and receiving * of datagrams and fulfilling of requests */ -class CoapMessagingLayer : Thread +class CoapMessagingLayer { /** * The client */ private CoapClient client; + /** + * Reading-loop thread + */ + private Thread readingThread; + /** * Running status */ @@ -51,7 +56,6 @@ class CoapMessagingLayer : Thread */ this(CoapClient client) { - super(&loop); this.client = client; } @@ -84,9 +88,9 @@ class CoapMessagingLayer : Thread // this.socket.blocking(true); this.socket.connect(getEndpointAddress()); - - // Start the thread (TODO: In future hide threading) - this.start(); + // Create the reading-loop thread and start it + this.readingThread = new Thread(&loop); + this.readingThread.start(); } /** @@ -124,7 +128,7 @@ class CoapMessagingLayer : Thread this.socket.close(); // Wait till the reading-loop thread exits - this.join(); + this.readingThread.join(); } /**