1
0
mirror of https://github.com/deavmi/birchwood synced 2024-09-19 23:23:25 +02:00
- Fixed conflicting symbol name `Event` arising from the use of `Eventy` and `libsnooze`
- Initialize the libsnooze event
- Initialize the queue mutex
- Set the thread's worker function

Sender

- Fixed conflicting symbol name `Event` arising from the use of `Eventy` and `libsnooze`
- Initialize the libsnooze event
- Initialize the queue mutex
- Set the thread's worker function

Protocol

- Moved module `message` to new package `protocol`
- Moved module `constants` to new package `protocol`
This commit is contained in:
Tristan B. Velloza Kildaire 2023-03-09 15:31:30 +02:00
parent a006057c7f
commit 32817d4134
5 changed files with 23 additions and 10 deletions

View File

@ -5,11 +5,15 @@ import core.thread : Thread, dur;
import std.container.slist : SList;
import core.sync.mutex : Mutex;
import eventy : EventyEvent = Event;
// TODO: Examine the below import which seemingly fixes stuff for libsnooze
import libsnooze.clib;
import libsnooze;
import birchwood.client;
import birchwood.protocol.messages : Message, decodeMessage;
import std.string : indexOf;
public final class ReceiverThread : Thread
{
@ -40,7 +44,10 @@ public final class ReceiverThread : Thread
*/
this(Client client)
{
super(&recvHandlerFunc);
this.client = client;
this.receiveEvent = new Event(); // TODO: Catch any libsnooze error here
this.recvQueueLock = new Mutex();
}
/**
@ -59,7 +66,7 @@ public final class ReceiverThread : Thread
*/
private void recvHandlerFunc()
{
while(running)
while(client.running)
{
// TODO: Insert libsnooze wait here
@ -137,8 +144,8 @@ public final class ReceiverThread : Thread
/* TODO: Implement */
// TODO: Remove the Eventy push and replace with a handler call (on second thought no)
Event pongEvent = new PongEvent(pingID);
engine.push(pongEvent);
EventyEvent pongEvent = new PongEvent(pingID);
client.engine.push(pongEvent);
}
/* Now let's go message by message */
@ -159,8 +166,8 @@ public final class ReceiverThread : Thread
curMsg = Message.parseReceivedMessage(messageNormal);
// TODO: Remove the Eventy push and replace with a handler call (on second thought no)
Event ircEvent = new IRCEvent(curMsg);
engine.push(ircEvent);
EventyEvent ircEvent = new IRCEvent(curMsg);
client.engine.push(ircEvent);
}

View File

@ -40,7 +40,10 @@ public final class SenderThread : Thread
*/
this(Client client)
{
super(&sendHandlerFunc);
this.client = client;
this.sendEvent = new Event(); // TODO: Catch any libsnooze error here
this.sendQueueLock = new Mutex();
}
/**
@ -54,7 +57,7 @@ public final class SenderThread : Thread
/* TODO: Hoist up into ConnInfo */
ulong fakeLagInBetween = 1;
while(running)
while(client.running)
{
// TODO: Insert libsnooze wait here
@ -70,7 +73,7 @@ public final class SenderThread : Thread
foreach(ubyte[] message; sendQueue[])
{
this.socket.send(message);
client.socket.send(message);
Thread.sleep(dur!("seconds")(fakeLagInBetween));
}

View File

@ -1,4 +1,4 @@
module birchwood.constants;
module birchwood.protocol.constants;
/* Reply object */
public enum ReplyType : ulong

View File

@ -1,10 +1,10 @@
module birchwood.messages;
module birchwood.protocol.messages;
import dlog;
import std.string;
import std.conv : to, ConvException;
import birchwood.constants : ReplyType;
import birchwood.protocol.constants : ReplyType;
// TODO: Before release we should remove this import
import std.stdio : writeln;

View File

@ -0,0 +1,3 @@
module birchwood.protocol;
public import birchwood.protocol.messages : Message;