From b19a7a52d611c854ec5119daf65ba1f508f21df2 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 18 Mar 2023 11:47:06 +0200 Subject: [PATCH 1/4] Client - Added missing documentation for `Client` type --- source/birchwood/client/client.d | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index d78890e..762cad9 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -26,6 +26,10 @@ __gshared static this() // TODO: Make abstract and for unit tests make a `DefaultClient` // ... which logs outputs for the `onX()` handler functions + +/** + * IRC client + */ public class Client : Thread { /** From 2ab86df2c7860e102d43880c980f39f7fb465bd0 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 18 Mar 2023 11:47:54 +0200 Subject: [PATCH 2/4] Client - Documented the `sender` field --- source/birchwood/client/client.d | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index 762cad9..789bc6c 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -46,9 +46,13 @@ public class Client : Thread package Socket socket; /** - * Receive queue and send queue managers + * Receive queue meneger */ private ReceiverThread receiver; + + /** + * Send queue manager + */ private SenderThread sender; /** From aa83f1a1bbac3782276a8ff7b246a6419a3c74f5 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 18 Mar 2023 11:50:54 +0200 Subject: [PATCH 3/4] ConnInfo - Added `setBulkReadSize(ulong)` to `ConnectionInfo` --- source/birchwood/config/conninfo.d | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/source/birchwood/config/conninfo.d b/source/birchwood/config/conninfo.d index 5181e8f..d2b77f5 100644 --- a/source/birchwood/config/conninfo.d +++ b/source/birchwood/config/conninfo.d @@ -73,6 +73,17 @@ public struct ConnectionInfo return this.bulkReadSize; } + /** + * Sets the read-dequeue size + * + * Params: + * bytes = the number of bytes to dequeue at a time + */ + public void setBulkReadSize(ulong bytes) + { + this.bulkReadSize = bytes; + } + /** * Get the address of the endpoint server * From de35d611f76f99dfaf2c98dd792d8f88db63d440 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 18 Mar 2023 12:29:35 +0200 Subject: [PATCH 4/4] Client - Made the `connInfo` field `package` level - Made the `connInfo` field `shared` meaning access to teh variable (updating the "slot", a.k.a. what struct is stored there) will use a lock - Updating anything within the struct will use a lock (besides `addrInfo` after returning from `getAddr()`) - This ensures we can have runtime updates safely - Added documentation to the constructor - Added TODO for the destructor - Re-added `getConnInfo()` - This practice is good for cases we want to update the struct, as getting it via a function would return a copy ConnInfo - `ConnectionInfo` struct must now be marked as `shared` due to `Client.connInfo` being marked as such - We cast from `shared Address` to `Address` because I don't think there is a lot of mutable data in this anyways (subject to change) Sender - The `SenderThread` will now access the client's connection info via the field name (`connInfo`), rather than getting a copy of the struct and then fetching the fakelag --- source/birchwood/client/client.d | 20 ++++++++++++++++++-- source/birchwood/client/sender.d | 2 +- source/birchwood/config/conninfo.d | 7 ++++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index 789bc6c..28b120a 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -35,7 +35,7 @@ public class Client : Thread /** * Connection information */ - private ConnectionInfo connInfo; + package shared ConnectionInfo connInfo; /* TODO: We should learn some info in here (or do we put it in connInfo)? */ private string serverName; //TODO: Make use of @@ -62,6 +62,14 @@ public class Client : Thread package bool running = false; + + /** + * Constructs a new IRC client with the given configuration + * info + * + * Params: + * connInfo = the connection parameters + */ this(ConnectionInfo connInfo) { super(&loop); @@ -74,12 +82,20 @@ public class Client : Thread this.sender = new SenderThread(this); } + /** + * TODO: ANything worth callin on destruction? + */ ~this() { //TODO: Do something here, tare downs } - // TODO: Investigate + /** + * Retrieve the active configuration at this + * moment + * + * Returns: the ConnectionInfo struct + */ public ConnectionInfo getConnInfo() { return connInfo; diff --git a/source/birchwood/client/sender.d b/source/birchwood/client/sender.d index 5d7fbc0..c51c423 100644 --- a/source/birchwood/client/sender.d +++ b/source/birchwood/client/sender.d @@ -129,7 +129,7 @@ public final class SenderThread : Thread foreach(ubyte[] message; sendQueue[]) { client.socket.send(message); - Thread.sleep(dur!("seconds")(client.getConnInfo().getFakeLag())); + Thread.sleep(dur!("seconds")(client.connInfo.getFakeLag())); } /* Empty the send queue */ diff --git a/source/birchwood/config/conninfo.d b/source/birchwood/config/conninfo.d index d2b77f5..c9d01f0 100644 --- a/source/birchwood/config/conninfo.d +++ b/source/birchwood/config/conninfo.d @@ -10,7 +10,7 @@ import birchwood.client.exceptions; * Represents the connection details for a server * to connect to */ -public struct ConnectionInfo +public shared struct ConnectionInfo { /** * Server address @@ -54,7 +54,8 @@ public struct ConnectionInfo */ private this(Address addrInfo, string nickname, ulong bulkReadSize = 20, string quitMessage = "birchwood client disconnecting...") { - this.addrInfo = addrInfo; + // NOTE: Not sure if much mutable in Address anyways + this.addrInfo = cast(shared Address)addrInfo; this.nickname = nickname; this.bulkReadSize = bulkReadSize; this.quitMessage = quitMessage; @@ -91,7 +92,7 @@ public struct ConnectionInfo */ public Address getAddr() { - return addrInfo; + return cast(Address)addrInfo; } /**