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. More... | |
~CAQueue () | |
Deletes this Queue and all stored data. More... | |
SINT32 | add (const void *buff, UINT32 size) |
Adds data to the Queue. More... | |
SINT32 | close () |
Closes the Queue (for writing). More... | |
SINT32 | get (UINT8 *pbuff, UINT32 *psize) |
Gets up to psize number of bytes from the Queue. More... | |
SINT32 | getOrWait (UINT8 *pbuff, UINT32 *psize) |
Gets data from the Queue or waits until some data is available, if the Queue is empty. More... | |
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. More... | |
SINT32 | peek (UINT8 *pbuff, UINT32 *psize) |
Peeks data from the Queue. More... | |
SINT32 | remove (UINT32 *psize) |
Removes data from the Queue. More... | |
SINT32 | clean () |
Removes any stored data from the Queue. More... | |
UINT32 | getSize () |
Returns the size of stored data in byte. More... | |
UINT32 | getSizeLookFree () |
Returns the size of stored data in byte. More... | |
bool | isEmpty () |
Returns true, if the Queue is empty. More... | |
bool | isClosed () |
Returns true, if the Queue is closed. More... | |
Static Public Member Functions | |
static SINT32 | test () |
Method to test the Queue. More... | |
Private Attributes | |
volatile QUEUE * | m_Queue |
volatile 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().
CAQueue::~CAQueue | ( | ) |
Deletes this Queue and all stored data.
References clean(), m_pconvarSize, and m_pcsQueue.
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_bClosed, 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(), CAFirstMix::clean(), CALastMix::clean(), CAFirstMixA::closeConnection(), MemFormatTarget::dumpMem(), CAFirstMixA::loop(), CALastMixA::loop(), CAFirstMixB::loop(), CALastMixB::loop(), CAFirstMixA::notifyAllUserChannels(), producer(), CAMiddleMix::putMixPacketIntoQueueSendToMixBefore(), 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_pconvarSize, m_pcsQueue, m_Queue, CAConditionVariable::signal(), and CAMutex::unlock().
Referenced by CALastMixA::loop().
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_CLOSED | if the queue is 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_nQueueSize, m_pcsQueue, m_Queue, _t_queue::next, _t_queue::pBuff, _t_queue::size, and CAMutex::unlock().
Referenced by CAFirstMix::doUserLogin_internal(), getOrWait(), CAFirstMixA::loop(), CALastMixA::loop(), CAFirstMixB::loop(), CALastMixB::loop(), CAFirstMixA::sendToUsers(), and test().
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_CLOSED | if the queue is empty and closed |
E_UNKNOWN | in case of an error |
References get(), CAMutex::lock(), m_bClosed, m_pconvarSize, m_Queue, CAMutex::unlock(), and CAConditionVariable::wait().
Referenced by consumer().
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, get(), CAMutex::lock(), m_pconvarSize, m_Queue, CAMutex::unlock(), and CAConditionVariable::wait().
UINT32 CAQueue::getSize | ( | ) |
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(), CAFirstMixA::loop(), CALastMixA::loop(), CAFirstMixB::loop(), CALastMixB::loop(), CAFirstMixA::sendToUsers(), and test().
UINT32 CAQueue::getSizeLookFree | ( | ) |
Returns the size of stored data in byte.
This is the look free version which might return a slighty wrong result due to concurrent changes in the queue.
References m_nQueueSize.
Referenced by CALastMixA::loop().
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().
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().
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().
|
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.
|
private |
Referenced by add(), CAQueue(), close(), get(), getOrWait(), isClosed(), and peek().
|
private |
|
private |
Referenced by add(), CAQueue(), close(), getOrWait(), and ~CAQueue().
|
private |