Mixes for Privacy and Anonymity in the Internet
Public Member Functions | Static Public Member Functions | Private Attributes
CAQueue Class Reference

This is a simple FIFO-Queue. More...

List of all members.

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

QUEUEm_Queue
QUEUEm_lastElem
volatile UINT32 m_nQueueSize
volatile bool m_bClosed
UINT32 m_nExpectedElementSize
CAMutexm_pcsQueue
CAConditionVariablem_pconvarSize

Detailed Description

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....


Constructor & Destructor Documentation

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.


Member Function Documentation

SINT32 CAQueue::add ( const void *  buff,
UINT32  size 
)

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.

Parameters:
pbuffpointer to a buffer, there the data should be stored
psizeon call contains the size of pbuff, on return contains the size of returned data
Return values:
E_SUCCESSif succesful
E_UNKNOWNin 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.

Parameters:
pbuffpointer to a buffer, there the data should be stored
psizeon call contains the size of pbuff, on return contains the size of returned data
Return values:
E_SUCCESSif succesful
E_UNKNOWNin 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.

Parameters:
pbuffpointer to a buffer, there the data should be stored
psizeon call contains the size of pbuff, on return contains the size of returned data
msTimeouttimeout in milli seconds
Return values:
E_SUCCESSif succesful
E_TIMEDOUTif timeout was reached
E_UNKNOWNin case of an error

References E_TIMEDOUT, CAMutex::lock(), m_pconvarSize, m_Queue, CAMutex::unlock(), and CAConditionVariable::wait().

Returns true, if the Queue is closed.

Return values:
true,ifQueue is closed
false,otherwise

References m_bClosed.

Referenced by CALastMixA::loop().

bool CAQueue::isEmpty ( )

Returns true, if the Queue is empty.

Return values:
true,ifQueue is empty
false,ifQueue 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.

Parameters:
pbuffpointer to a buffer, where the data should be stored
psizeon call contains the size of pbuff, on return contains the size of returned data
Return values:
E_SUCCESSif succesful
E_CLOSEDif the queue is already empty AND closed
E_UNKNOWNin 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.

Parameters:
psizeon call contains the size of data to remove, on return contains the size of removed data
Return values:
E_SUCCESSif succesful
E_UNKNOWNin 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.

Return values:
E_SUCCESS,ifQueue 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().


Member Data Documentation

volatile bool CAQueue::m_bClosed [private]

Referenced by CAQueue(), close(), isClosed(), and peek().

Referenced by add(), CAQueue(), and clean().

Referenced by CAQueue().

volatile UINT32 CAQueue::m_nQueueSize [private]

Referenced by add(), CAQueue(), clean(), get(), getSize(), and remove().

Referenced by add(), CAQueue(), getOrWait(), and ~CAQueue().

QUEUE* CAQueue::m_Queue [private]