From bfa4364a9927aedcb8e99952f5338faf4dfef866 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Wed, 8 Sep 2021 11:19:05 +0200 Subject: [PATCH] Added shutdown capability --- source/tristanable/manager.d | 6 ++++++ source/tristanable/watcher.d | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/source/tristanable/manager.d b/source/tristanable/manager.d index 23f76c3..a3cc5db 100644 --- a/source/tristanable/manager.d +++ b/source/tristanable/manager.d @@ -115,5 +115,11 @@ public final class Manager public void shutdown() { /* TODO: Implement me */ + + /* Make the loop stop whenever it does */ + watcher.shutdown(); + + /* Wait for the thread to end */ + watcher.join(); } } \ No newline at end of file diff --git a/source/tristanable/watcher.d b/source/tristanable/watcher.d index 66d5638..7d99d1a 100644 --- a/source/tristanable/watcher.d +++ b/source/tristanable/watcher.d @@ -17,15 +17,24 @@ public final class Watcher : Thread /* The socket to read from */ private Socket socket; + // private bool running; + this(Manager manager, Socket endpoint) { super(&run); this.manager = manager; socket = endpoint; + // running = true; start(); } + public void shutdown() + { + /* Close the socket, causing an error, breaking the event loop */ + socket.close(); + } + private void run() { /* Continuously dequeue tristanable packets from socket */