Merge pull request #2 from deavmi/hotfix/composed_thread_for_udp

Composed thread
This commit is contained in:
Tristan B. Velloza Kildaire 2023-09-22 17:57:29 +02:00 committed by GitHub
commit 013886c79f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();
}
/**