|
Mixes for Privacy and Anonymity in the Internet
|
This is a simple FIFO-Queue. More...
Public Member Functions | |
| CAQueue (UINT32 expectedElementSize=0) | |
| Give the size of the amount of data what you will add in one step. | |
| ~CAQueue () | |
| Deletes this Queue and all stored data. | |
| SINT32 | add (const void *buff, UINT32 size) |
| Adds data to the Queue. | |
| SINT32 | close () |
| Closes the Queue (for writing). | |
| SINT32 | get (UINT8 *pbuff, UINT32 *psize) |
| Gets up to psize number of bytes from the Queue. | |
| SINT32 | getOrWait (UINT8 *pbuff, UINT32 *psize) |
| Gets data from the Queue or waits until some data is available, if the Queue is empty. | |
| SINT32 | getOrWait (UINT8 *pbuff, UINT32 *psize, UINT32 msTimeOut) |
| Gets data from the Queue or waits until some data is available, if the Queue is empty or a timeout is reached. | |
| SINT32 | peek (UINT8 *pbuff, UINT32 *psize) |
| Peeks data from the Queue. | |
| SINT32 | remove (UINT32 *psize) |
| Removes data from the Queue. | |
| SINT32 | clean () |
| Removes any stored data from the Queue. | |
| UINT32 | getSize () |
| Returns the size of stored data in byte. | |
| bool | isEmpty () |
| Returns true, if the Queue is empty. | |
| bool | isClosed () |
| Returns true, if the Queue is closed. | |
Static Public Member Functions | |
| static SINT32 | test () |
| Method to test the Queue. | |
Private Attributes | |
| QUEUE * | m_Queue |
| QUEUE * | m_lastElem |
| volatile UINT32 | m_nQueueSize |
| volatile bool | m_bClosed |
| UINT32 | m_nExpectedElementSize |
| CAMutex * | m_pcsQueue |
| CAConditionVariable * | m_pconvarSize |
This is a simple FIFO-Queue.
You can add data and get them back. This class is thread safe. TODO: The handling of getAndWait is not correct because remove could intercept.... Maybe we do not neeed an other Mutex other than then ConVar....
| CAQueue::CAQueue | ( | UINT32 | expectedElementSize = 0 | ) |
Give the size of the amount of data what you will add in one step.
Used for optimizations. Use expectedElementSize=0, if you have no idea about the typicall amount of data added in one call to add().
References m_bClosed, m_lastElem, m_nExpectedElementSize, m_nQueueSize, m_pconvarSize, m_pcsQueue, and m_Queue.
Referenced by test().
Deletes this Queue and all stored data.
References clean(), m_pconvarSize, and m_pcsQueue.
| SINT32 CAQueue::add | ( | const void * | buff, |
| UINT32 | size | ||
| ) |
Adds data to the Queue.
| buff | pointer to the data buffer |
| size | size of data to add |
| E_UNKNOWN | in case of an error |
| E_SUCCESS | if succesful |
References E_SUCCESS, E_UNKNOWN, _t_queue::index, CAMutex::lock(), m_lastElem, m_nQueueSize, m_pconvarSize, m_pcsQueue, m_Queue, _t_queue::next, _t_queue::pBuff, CAMsg::printMsg(), CAConditionVariable::signal(), _t_queue::size, and CAMutex::unlock().
Referenced by CAChain::addDataToUpstreamQueue(), CALastMix::clean(), CAFirstMix::clean(), CAFirstMixA::closeConnection(), MemFormatTarget::dumpMem(), fm_loopReadFromMix(), lm_loopReadFromMix(), CALastMixA::loop(), CAFirstMixB::loop(), CAFirstMixA::loop(), CALastMixB::loop(), mm_loopReadFromMixAfter(), mm_loopReadFromMixBefore(), CAFirstMixA::notifyAllUserChannels(), producer(), CAControlChannelDispatcher::sendMessages(), test(), and MemFormatTarget::writeChars().
| SINT32 CAQueue::clean | ( | ) |
Removes any stored data from the Queue.
References E_SUCCESS, CAMutex::lock(), m_lastElem, m_nQueueSize, m_pcsQueue, m_Queue, _t_queue::next, _t_queue::pBuff, and CAMutex::unlock().
Referenced by CAFirstMixA::checkUserConnections(), CAChain::closeChainInternal(), CAChain::~CAChain(), and ~CAQueue().
| SINT32 CAQueue::close | ( | ) |
Closes the Queue (for writing).
One can still read the remaing bytes out of the queue.
References E_SUCCESS, CAMutex::lock(), m_bClosed, m_pcsQueue, and CAMutex::unlock().
Referenced by CALastMixA::loop().
| SINT32 CAQueue::get | ( | UINT8 * | pbuff, |
| UINT32 * | psize | ||
| ) |
Gets up to psize number of bytes from the Queue.
The data is removed from the Queue.
| pbuff | pointer to a buffer, there the data should be stored |
| psize | on call contains the size of pbuff, on return contains the size of returned data |
| E_SUCCESS | if succesful |
| E_UNKNOWN | in case of an error |
References E_SUCCESS, E_UNKNOWN, _t_queue::index, CAMutex::lock(), m_nQueueSize, m_pcsQueue, m_Queue, _t_queue::next, _t_queue::pBuff, _t_queue::size, and CAMutex::unlock().
Referenced by CAFirstMix::doUserLogin_internal(), CALastMixA::loop(), CAFirstMixB::loop(), CAFirstMixA::loop(), CALastMixB::loop(), CAFirstMixA::sendToUsers(), and test().
| SINT32 CAQueue::getOrWait | ( | UINT8 * | pbuff, |
| UINT32 * | psize | ||
| ) |
Gets data from the Queue or waits until some data is available, if the Queue is empty.
The data is removed from the Queue.
| pbuff | pointer to a buffer, there the data should be stored |
| psize | on call contains the size of pbuff, on return contains the size of returned data |
| E_SUCCESS | if succesful |
| E_UNKNOWN | in case of an error |
References CAMutex::lock(), m_pconvarSize, m_Queue, CAMutex::unlock(), and CAConditionVariable::wait().
Referenced by consumer(), fm_loopSendToMix(), lm_loopSendToMix(), mm_loopSendToMixAfter(), and mm_loopSendToMixBefore().
| SINT32 CAQueue::getOrWait | ( | UINT8 * | pbuff, |
| UINT32 * | psize, | ||
| UINT32 | msTimeout | ||
| ) |
Gets data from the Queue or waits until some data is available, if the Queue is empty or a timeout is reached.
The data is removed from the Queue.
| pbuff | pointer to a buffer, there the data should be stored |
| psize | on call contains the size of pbuff, on return contains the size of returned data |
| msTimeout | timeout in milli seconds |
| E_SUCCESS | if succesful |
| E_TIMEDOUT | if timeout was reached |
| E_UNKNOWN | in case of an error |
References E_TIMEDOUT, CAMutex::lock(), m_pconvarSize, m_Queue, CAMutex::unlock(), and CAConditionVariable::wait().
Returns the size of stored data in byte.
References CAMutex::lock(), m_nQueueSize, m_pcsQueue, and CAMutex::unlock().
Referenced by CAFirstMixA::checkUserConnections(), CAFirstMix::doUserLogin_internal(), MemFormatTarget::dumpMem(), fm_loopReadFromMix(), lm_loopReadFromMix(), CALastMixA::loop(), CAFirstMixB::loop(), CAFirstMixA::loop(), CALastMixB::loop(), mm_loopReadFromMixAfter(), mm_loopReadFromMixBefore(), CAFirstMixA::sendToUsers(), and test().
| bool CAQueue::isClosed | ( | ) |
Returns true, if the Queue is closed.
| true,if | Queue is closed |
| false,otherwise |
References m_bClosed.
Referenced by CALastMixA::loop().
| bool CAQueue::isEmpty | ( | ) |
Returns true, if the Queue is empty.
| true,if | Queue is empty |
| false,if | Queue contains data |
References m_Queue.
Referenced by CALastMixA::loop(), CAChain::sendUpstreamData(), and test().
| SINT32 CAQueue::peek | ( | UINT8 * | pbuff, |
| UINT32 * | psize | ||
| ) |
Peeks data from the Queue.
The data is NOT removed from the Queue.
| pbuff | pointer to a buffer, where the data should be stored |
| psize | on call contains the size of pbuff, on return contains the size of returned data |
| E_SUCCESS | if succesful |
| E_CLOSED | if the queue is already empty AND closed |
| E_UNKNOWN | in case of an error |
References E_CLOSED, E_SUCCESS, E_UNKNOWN, _t_queue::index, CAMutex::lock(), m_bClosed, m_pcsQueue, m_Queue, _t_queue::next, _t_queue::pBuff, _t_queue::size, and CAMutex::unlock().
Referenced by MemFormatTarget::dumpMem(), CALastMixA::loop(), and CAChain::sendUpstreamDataInternal().
| SINT32 CAQueue::remove | ( | UINT32 * | psize | ) |
Removes data from the Queue.
| psize | on call contains the size of data to remove, on return contains the size of removed data |
| E_SUCCESS | if succesful |
| E_UNKNOWN | in case of an error |
References E_SUCCESS, E_UNKNOWN, _t_queue::index, CAMutex::lock(), m_nQueueSize, m_pcsQueue, m_Queue, _t_queue::next, _t_queue::pBuff, _t_queue::size, and CAMutex::unlock().
Referenced by CALastMixA::loop(), and CAChain::sendUpstreamDataInternal().
| SINT32 CAQueue::test | ( | ) | [static] |
Method to test the Queue.
| E_SUCCESS,if | Queue implementation seams to be ok |
References add(), __queue_test::buff, CAQueue(), consumer(), E_SUCCESS, E_UNKNOWN, get(), getRandom(), getSize(), isEmpty(), CAThread::join(), __queue_test::len, __queue_test::pQueue, producer(), CAThread::setMainLoop(), CAThread::start(), and TEST_SIZE.
Referenced by main().
volatile bool CAQueue::m_bClosed [private] |
Referenced by CAQueue(), close(), isClosed(), and peek().
QUEUE* CAQueue::m_lastElem [private] |
UINT32 CAQueue::m_nExpectedElementSize [private] |
Referenced by CAQueue().
volatile UINT32 CAQueue::m_nQueueSize [private] |
CAConditionVariable* CAQueue::m_pconvarSize [private] |
Referenced by add(), CAQueue(), getOrWait(), and ~CAQueue().
CAMutex* CAQueue::m_pcsQueue [private] |
QUEUE* CAQueue::m_Queue [private] |
1.7.6.1