mirror of
https://github.com/deavmi/birchwood
synced 2024-09-20 14:43:23 +02:00
Client
- 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:
parent
f30fc6b18c
commit
269aaf0018
@ -11,7 +11,7 @@ import eventy : EventyEvent = Event, Engine, EventType, Signal;
|
|||||||
import birchwood.config : ConnectionInfo;
|
import birchwood.config : ConnectionInfo;
|
||||||
import birchwood.client.exceptions : BirchwoodException;
|
import birchwood.client.exceptions : BirchwoodException;
|
||||||
import birchwood.protocol.messages : Message, encodeMessage, decodeMessage, isValidText;
|
import birchwood.protocol.messages : Message, encodeMessage, decodeMessage, isValidText;
|
||||||
// import birchwood.protocol.constants : ReplyType;
|
|
||||||
import birchwood.client.receiver : ReceiverThread;
|
import birchwood.client.receiver : ReceiverThread;
|
||||||
import birchwood.client.sender : SenderThread;
|
import birchwood.client.sender : SenderThread;
|
||||||
import birchwood.client.events;
|
import birchwood.client.events;
|
||||||
@ -570,13 +570,19 @@ public class Client : Thread
|
|||||||
/* Register default handler */
|
/* Register default handler */
|
||||||
initEvents();
|
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.receiver.start();
|
||||||
this.sender.start();
|
this.sender.start();
|
||||||
|
// while(!receiver.isReady() || !sender.isReady()) {}
|
||||||
|
|
||||||
/* Set running sttaus to true */
|
/* Set running status to true */
|
||||||
running = true;
|
running = true;
|
||||||
|
|
||||||
/* Start socket loop */
|
/* Start socket loop */
|
||||||
@ -587,6 +593,7 @@ public class Client : Thread
|
|||||||
throw new BirchwoodException(BirchwoodException.ErrorType.CONNECT_ERROR);
|
throw new BirchwoodException(BirchwoodException.ErrorType.CONNECT_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// TODO: Do actual liveliness check here
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new BirchwoodException(BirchwoodException.ErrorType.ALREADY_CONNECTED);
|
throw new BirchwoodException(BirchwoodException.ErrorType.ALREADY_CONNECTED);
|
||||||
|
@ -30,6 +30,7 @@ public final class ReceiverThread : Thread
|
|||||||
* to be processed and received
|
* to be processed and received
|
||||||
*/
|
*/
|
||||||
private Event receiveEvent;
|
private Event receiveEvent;
|
||||||
|
// private bool hasEnsured;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The associated IRC client
|
* The associated IRC client
|
||||||
@ -48,7 +49,7 @@ public final class ReceiverThread : Thread
|
|||||||
super(&recvHandlerFunc);
|
super(&recvHandlerFunc);
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.receiveEvent = new Event(); // TODO: Catch any libsnooze error here
|
this.receiveEvent = new Event(); // TODO: Catch any libsnooze error here
|
||||||
this.recvQueueLock = new Mutex();
|
this.recvQueueLock = new Mutex();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Rename to `receiveQ`
|
// TODO: Rename to `receiveQ`
|
||||||
@ -92,17 +93,27 @@ public final class ReceiverThread : Thread
|
|||||||
{
|
{
|
||||||
while(client.running)
|
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)
|
// 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
|
// TODO: See above notes about libsnooze behaviour due
|
||||||
// ... to usage in our context
|
// ... to usage in our context
|
||||||
receiveEvent.wait(); // TODO: Catch any exceptions from libsnooze
|
receiveEvent.wait(); // TODO: Catch any exceptions from libsnooze
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Lock the receieve queue */
|
/* Lock the receieve queue */
|
||||||
recvQueueLock.lock();
|
recvQueueLock.lock();
|
||||||
|
|
||||||
@ -208,4 +219,9 @@ public final class ReceiverThread : Thread
|
|||||||
// ... to usage in our context
|
// ... to usage in our context
|
||||||
receiveEvent.notifyAll();
|
receiveEvent.notifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public bool isReady()
|
||||||
|
// {
|
||||||
|
// return hasEnsured;
|
||||||
|
// }
|
||||||
}
|
}
|
@ -25,6 +25,7 @@ public final class SenderThread : Thread
|
|||||||
* to be processed and sent
|
* to be processed and sent
|
||||||
*/
|
*/
|
||||||
private Event sendEvent;
|
private Event sendEvent;
|
||||||
|
// private bool hasEnsured;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The associated IRC client
|
* The associated IRC client
|
||||||
@ -83,10 +84,17 @@ public final class SenderThread : Thread
|
|||||||
|
|
||||||
while(client.running)
|
while(client.running)
|
||||||
{
|
{
|
||||||
// TODO: Insert libsnooze wait here
|
// // 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
|
||||||
// TODO: Add a for-loop here which one can configure which is
|
// // ... when the first sent messages will be able to cause a wait
|
||||||
// ... a "per iteration" how much to process and act on
|
// // ... 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: 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
|
// ... to usage in our context
|
||||||
sendEvent.wait(); // TODO: Catch any exceptions from libsnooze
|
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 */
|
/* Lock queue */
|
||||||
sendQueueLock.lock();
|
sendQueueLock.lock();
|
||||||
@ -120,4 +132,9 @@ public final class SenderThread : Thread
|
|||||||
// ... to usage in our context
|
// ... to usage in our context
|
||||||
sendEvent.notifyAll();
|
sendEvent.notifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public bool isReady()
|
||||||
|
// {
|
||||||
|
// return hasEnsured;
|
||||||
|
// }
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user