Mixe for Privacy and Anonymity in the Internet
|
This is a simple FIFO-Queue. More...
#include <CAQueue.hpp>
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....
Definition at line 49 of file CAQueue.hpp.
|
inline |
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().
Definition at line 57 of file CAQueue.hpp.
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.
Definition at line 36 of file CAQueue.cpp.
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 |
Definition at line 76 of file CAQueue.cpp.
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.
Definition at line 47 of file CAQueue.cpp.
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().
|
inline |
Closes the Queue (for writing).
One can still read the remaing bytes out of the queue.
Definition at line 77 of file CAQueue.hpp.
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 |
Definition at line 148 of file CAQueue.cpp.
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 |
Definition at line 209 of file CAQueue.cpp.
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 |
Definition at line 232 of file CAQueue.cpp.
References E_TIMEDOUT, get(), CAMutex::lock(), m_pconvarSize, m_Queue, CAMutex::unlock(), and CAConditionVariable::wait().
|
inline |
Returns the size of stored data in byte.
Definition at line 101 of file CAQueue.hpp.
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().
|
inline |
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.
Definition at line 116 of file CAQueue.hpp.
References m_nQueueSize.
Referenced by CALastMixA::loop().
|
inline |
Returns true, if the Queue is closed.
true,if | Queue is closed |
false,otherwise |
Definition at line 134 of file CAQueue.hpp.
References m_bClosed.
Referenced by CALastMixA::loop().
|
inline |
Returns true, if the Queue is empty.
true,if | Queue is empty |
false,if | Queue contains data |
Definition at line 125 of file CAQueue.hpp.
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 |
Definition at line 258 of file CAQueue.cpp.
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 |
Definition at line 302 of file CAQueue.cpp.
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 |
Definition at line 437 of file CAQueue.cpp.
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 |
Definition at line 155 of file CAQueue.hpp.
Referenced by add(), CAQueue(), close(), get(), getOrWait(), isClosed(), and peek().
|
private |
Definition at line 153 of file CAQueue.hpp.
|
private |
Definition at line 156 of file CAQueue.hpp.
Referenced by CAQueue().
|
private |
Definition at line 154 of file CAQueue.hpp.
Referenced by add(), CAQueue(), clean(), get(), getSize(), getSizeLookFree(), and remove().
|
private |
Definition at line 159 of file CAQueue.hpp.
Referenced by add(), CAQueue(), close(), getOrWait(), and ~CAQueue().
|
private |
|
private |