From b79a3ad8ee37864211f2b81fc9c2717ecf5a9382 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sun, 25 Jun 2023 17:30:53 +0200 Subject: [PATCH] Client - Now catches `SnoozeError` if a the libsnooze `Event`'s failed to have their `ensure()` call succeed ErrorType - Updated description for enum member `INTERNAL_FAILURE` Sender - Removed now-completed TODO Receiver - Removed now-completed TODO --- source/birchwood/client/client.d | 6 ++++++ source/birchwood/client/exceptions.d | 5 ++++- source/birchwood/client/receiver.d | 5 ++++- source/birchwood/client/sender.d | 5 ++++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index 2eade5d..e06f5f3 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -19,6 +19,8 @@ import birchwood.client.receiver : ReceiverThread; import birchwood.client.sender : SenderThread; import birchwood.client.events; +import libsnooze.exceptions : SnoozeError; + import dlog; package __gshared Logger logger; @@ -819,6 +821,10 @@ public class Client : Thread { throw new BirchwoodException(ErrorType.INTERNAL_FAILURE, e.toString()); } + catch(SnoozeError e) + { + throw new BirchwoodException(ErrorType.INTERNAL_FAILURE, e.toString()); + } } // TODO: Do actual liveliness check here else diff --git a/source/birchwood/client/exceptions.d b/source/birchwood/client/exceptions.d index 5564f3d..36b7456 100644 --- a/source/birchwood/client/exceptions.d +++ b/source/birchwood/client/exceptions.d @@ -18,7 +18,10 @@ public enum ErrorType /** * This could occur from errors with `Eventy` * when setting up the signal handlers and - * event types + * event types. It can also occur if `libsnooze` + * has an error which would occur when calling + * `ensure(Thread)` for the `Receiver` and `Sender` + * threads */ INTERNAL_FAILURE, diff --git a/source/birchwood/client/receiver.d b/source/birchwood/client/receiver.d index cb1727f..a0bafa2 100644 --- a/source/birchwood/client/receiver.d +++ b/source/birchwood/client/receiver.d @@ -60,12 +60,15 @@ public final class ReceiverThread : Thread * * Params: * client = the Client to associate with + * Throws: + * `SnoozeError` on failure to construct an + * `Event` or ensure ourselves */ this(Client client) { super(&recvHandlerFunc); this.client = client; - this.receiveEvent = new Event(); // TODO: Catch any libsnooze error here + this.receiveEvent = new Event(); this.recvQueueLock = new Mutex(); this.receiveEvent.ensure(this); } diff --git a/source/birchwood/client/sender.d b/source/birchwood/client/sender.d index 4f90b23..2af5a1e 100644 --- a/source/birchwood/client/sender.d +++ b/source/birchwood/client/sender.d @@ -52,12 +52,15 @@ public final class SenderThread : Thread * * Params: * client = the Client to associate with + * Throws: + * `SnoozeError` on failure to construct an + * `Event` or ensure ourselves */ this(Client client) { super(&sendHandlerFunc); this.client = client; - this.sendEvent = new Event(); // TODO: Catch any libsnooze error here + this.sendEvent = new Event(); this.sendQueueLock = new Mutex(); this.sendEvent.ensure(this); }