1
0
mirror of https://github.com/deavmi/birchwood synced 2024-09-20 14:03:05 +02:00
- Removed unused import
- Added comment for future work
- Fixed typo

Receiver

- Added commented out code for future work

Sender

- Added commented out code for future work
This commit is contained in:
Tristan B. Velloza Kildaire 2023-03-11 15:09:45 +02:00
parent f30fc6b18c
commit 269aaf0018
3 changed files with 55 additions and 15 deletions

View File

@ -11,7 +11,7 @@ import eventy : EventyEvent = Event, Engine, EventType, Signal;
import birchwood.config : ConnectionInfo;
import birchwood.client.exceptions : BirchwoodException;
import birchwood.protocol.messages : Message, encodeMessage, decodeMessage, isValidText;
// import birchwood.protocol.constants : ReplyType;
import birchwood.client.receiver : ReceiverThread;
import birchwood.client.sender : SenderThread;
import birchwood.client.events;
@ -570,13 +570,19 @@ public class Client : Thread
/* Register default handler */
initEvents();
/**
* Start the receive and send queue manager
*/
// /**
// * 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)
// */
this.receiver.start();
this.sender.start();
// while(!receiver.isReady() || !sender.isReady()) {}
/* Set running sttaus to true */
/* Set running status to true */
running = true;
/* Start socket loop */
@ -587,6 +593,7 @@ public class Client : Thread
throw new BirchwoodException(BirchwoodException.ErrorType.CONNECT_ERROR);
}
}
// TODO: Do actual liveliness check here
else
{
throw new BirchwoodException(BirchwoodException.ErrorType.ALREADY_CONNECTED);

View File

@ -30,6 +30,7 @@ public final class ReceiverThread : Thread
* to be processed and received
*/
private Event receiveEvent;
// private bool hasEnsured;
/**
* The associated IRC client
@ -92,17 +93,27 @@ public final class ReceiverThread : Thread
{
while(client.running)
{
// TODO: Insert libsnooze wait here
// TODO: Add a for-loop here which one can configure which is
// ... a "per iteration" how much to process and act on
// 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
receiveEvent.wait(); // TODO: Catch any exceptions from libsnooze
/* Lock the receieve queue */
recvQueueLock.lock();
@ -208,4 +219,9 @@ public final class ReceiverThread : Thread
// ... to usage in our context
receiveEvent.notifyAll();
}
// public bool isReady()
// {
// return hasEnsured;
// }
}

View File

@ -25,6 +25,7 @@ public final class SenderThread : Thread
* to be processed and sent
*/
private Event sendEvent;
// private bool hasEnsured;
/**
* The associated IRC client
@ -83,10 +84,17 @@ public final class SenderThread : Thread
while(client.running)
{
// TODO: Insert libsnooze wait here
// TODO: Add a for-loop here which one can configure which is
// ... a "per iteration" how much to process and act on
// // 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)
@ -96,6 +104,10 @@ public final class SenderThread : Thread
// ... to usage in our context
sendEvent.wait(); // TODO: Catch any exceptions from libsnooze
// 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();
@ -120,4 +132,9 @@ public final class SenderThread : Thread
// ... to usage in our context
sendEvent.notifyAll();
}
// public bool isReady()
// {
// return hasEnsured;
// }
}