1
0
mirror of https://github.com/deavmi/birchwood synced 2024-09-20 11:22:53 +02:00

Merge pull request #34 from deavmi/bugfix/improve_snoosy

Bugfix/improve snoosy
This commit is contained in:
Tristan B. Velloza Kildaire 2023-06-26 19:05:53 +02:00 committed by GitHub
commit 7848e892b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 68 deletions

View File

@ -23,9 +23,9 @@ dub add birchwood
Birchwood depends on the following D libraries:
* `libsnooze` (atleast 1.0.0-beta)
* `eventy` (atleast 0.4.0)
* `dlog` (atleast 0.3.19)
* `libsnooze` (at least 1.2.0-beta)
* `eventy` (at least 0.4.0)
* `dlog` (at least 0.3.19)
## Usage

View File

@ -7,7 +7,7 @@
"dependencies": {
"dlog": ">=0.3.19",
"eventy": ">=0.4.0",
"libsnooze": ">=1.0.0-beta"
"libsnooze": ">=1.2.0-beta"
},
"description": "A sane IRC framework for the D language",
"license": "LGPL-3.0",

View File

@ -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;
@ -807,22 +809,12 @@ public class Client : Thread
/* Register default handler */
initEvents();
// /**
// * Initialize the ready events for both the
// * receive and send queue managers, then after
// * doing so start both managers and spin for
// * both of them to enter a ready state (i.e.
// * they have ensured a waiting-pipe pair for
// * libsnooze exists)
// */
/* Set the running status to true */
running = true;
/* Start the receive queue and send queue managers */
this.receiver.start();
this.sender.start();
// while(!receiver.isReady() || !sender.isReady()) {}
/* Start the socket read-decode loop */
this.start();
@ -838,6 +830,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

View File

@ -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,

View File

@ -48,7 +48,6 @@ public final class ReceiverThread : Thread
* to be processed and received
*/
private Event receiveEvent;
// private bool hasEnsured;
/**
* The associated IRC client
@ -61,13 +60,17 @@ 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);
}
/**
@ -88,10 +91,6 @@ public final class ReceiverThread : Thread
/* Unlock queue */
recvQueueLock.unlock();
// TODO: Add a "register" function which can initialize pipes
// ... without needing a wait, we'd need a ready flag though
// ... for receiver's thread start
/**
* Wake up all threads waiting on this event
* (if any, and if so it would only be the receiver)
@ -115,21 +114,6 @@ public final class ReceiverThread : Thread
{
// TODO: We could look at libsnooze wait starvation or mutex racing (future thought)
// // Do a once-off call to `ensure()` here which then only runs once and
// // ... sets a `ready` flag for the Client to spin on. This ensures that
// // ... when the first received messages will be able to cause a wait
// // ... to immediately unblock rather than letting wait() register itself
// // ... and then require another receiveQ call to wake it up and process
// // ... the initial n messages + m new ones resulting in the second call
// if(hasEnsured == false)
// {
// receiveEvent.ensure();
// hasEnsured = true;
// }
// TODO: See above notes about libsnooze behaviour due
// ... to usage in our context
try
{
receiveEvent.wait();
@ -153,8 +137,6 @@ public final class ReceiverThread : Thread
}
/* Lock the receieve queue */
recvQueueLock.lock();

View File

@ -40,7 +40,6 @@ public final class SenderThread : Thread
* to be processed and sent
*/
private Event sendEvent;
// private bool hasEnsured;
/**
* The associated IRC client
@ -53,13 +52,17 @@ 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);
}
/**
@ -80,10 +83,6 @@ public final class SenderThread : Thread
/* Unlock queue */
sendQueueLock.unlock();
// TODO: Add a "register" function which can initialize pipes
// ... without needing a wait, we'd need a ready flag though
// ... for sender's thread start
/**
* Wake up all threads waiting on this event
* (if any, and if so it would only be the sender)
@ -91,7 +90,6 @@ public final class SenderThread : Thread
sendEvent.notifyAll();
}
/**
* The send queue worker function
*/
@ -99,24 +97,10 @@ public final class SenderThread : Thread
{
while(client.running)
{
// // Do a once-off call to `ensure()` here which then only runs once and
// // ... sets a `ready` flag for the Client to spin on. This ensures that
// // ... when the first sent messages will be able to cause a wait
// // ... to immediately unblock rather than letting wait() register itself
// // ... and then require another sendQ call to wake it up and process
// // ... the initial n messages + m new ones resulting in the second call
// if(hasEnsured == false)
// {
// sendEvent.ensure();
// hasEnsured = true;
// }
// TODO: We could look at libsnooze wait starvation or mutex racing (future thought)
/* TODO: handle normal messages (xCount with fakeLagInBetween) */
// TODO: See above notes about libsnooze behaviour due
// ... to usage in our context
try
{
sendEvent.wait();
@ -140,13 +124,6 @@ public final class SenderThread : Thread
}
// TODO: After the above call have a once-off call to `ensure()` here
// ... which then only runs once and sets a `ready` flag for the Client
// ... to spin on
/* Lock queue */
sendQueueLock.lock();