Valhalla Legends Forums Archive | C/C++ Programming | std::queue - clearqueue command

AuthorMessageTime
Mephisto
When a command is called, it passes the std::queue data structure to the command function.  The command pushes the data it needs to onto the queue (Battle.net messages).  When the command returns to where it was called, it goes through a while loop poping the items off of the queue and sending message after message to Battle.net pausing as needed.  The way to clear the std::queue is simply to call the clearqueue command which goes through another loop and pops off the messages without sending them to Battle.net.  The problem is, this is all done synchronously.  The program sits in a while loop waiting to receive data.  When it receives data, it goes through a process of figuring out which packet it received and what to do with it.  On 0x0F packets it figures out which ID it is.  If it's 0x17, 0x04, or 0x05 it parses the message to determine if a command was called.  If called, it gets the appropriate arguments from the messages and calls the command.  After the command is returned it goes through the queue loop, so while it goes through the loop, and someone calls the clearqueue command, it won't clear the queue until the messages before its calling are sent.  How else might I implement using the std::queue to be able to just clear it even while it's going through it to send its messages to Battle.net?

(Sorry for redundancy in this post).
October 10, 2004, 12:34 AM
Zakath
Only pop one item off the queue at a time. Implement a WaitMsg-style loop with multiple possible terminating triggers, including the addition of a command to the queue and the presence of a command in the queue. Ensure that the command is always checked first (if present), so that then if a clearqueue command comes through, it is executed before any commands already in the queue are sent. If there is no command, the stuff in the queue will keep triggering the end of the wait until the queue is empty.

That's just off the top of my head; there are probably better ways.
October 10, 2004, 2:58 AM

Search