|
Mixe for Privacy and Anonymity in the Internet
|
00001 /* 00002 Copyright (c) 2000, The JAP-Team 00003 All rights reserved. 00004 Redistribution and use in source and binary forms, with or without modification, 00005 are permitted provided that the following conditions are met: 00006 00007 - Redistributions of source code must retain the above copyright notice, 00008 this list of conditions and the following disclaimer. 00009 00010 - Redistributions in binary form must reproduce the above copyright notice, 00011 this list of conditions and the following disclaimer in the documentation and/or 00012 other materials provided with the distribution. 00013 00014 - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors 00015 may be used to endorse or promote products derived from this software without specific 00016 prior written permission. 00017 00018 00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 00020 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00021 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS 00022 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00023 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00024 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00025 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00027 */ 00028 #ifndef __CAQUEUE__ 00029 #define __CAQUEUE__ 00030 #ifndef ONLY_LOCAL_PROXY 00031 #include "CAConditionVariable.hpp" 00032 #include "CAMsg.hpp" 00033 00034 struct _t_queue 00035 { 00036 UINT8* pBuff; 00037 struct _t_queue* next; 00038 UINT32 size; 00039 UINT32 index; 00040 }; 00041 00042 typedef struct _t_queue QUEUE; 00043 00049 class CAQueue 00050 { 00051 public: 00057 CAQueue(UINT32 expectedElementSize=0) 00058 { 00059 m_Queue=NULL; 00060 m_lastElem=NULL; 00061 m_nExpectedElementSize=expectedElementSize; 00062 m_nQueueSize=0; 00063 m_pcsQueue=new CAMutex(); 00064 m_pconvarSize=new CAConditionVariable(); 00065 m_bClosed=false; 00066 #ifdef QUEUE_SIZE_LOG 00067 m_nLogSize=0; 00068 #endif 00069 //m_pHeap=NULL; 00070 //incHeap(); 00071 } 00072 ~CAQueue(); 00073 SINT32 add(const void* buff,UINT32 size); 00074 00077 SINT32 close() 00078 { 00079 m_pcsQueue->lock(); 00080 m_bClosed=true; 00081 m_pcsQueue->unlock(); 00082 return E_SUCCESS; 00083 } 00084 00085 SINT32 get(UINT8* pbuff,UINT32* psize); 00086 SINT32 getOrWait(UINT8* pbuff,UINT32* psize); 00087 SINT32 getOrWait(UINT8* pbuff,UINT32* psize,UINT32 msTimeOut); 00088 SINT32 peek(UINT8* pbuff,UINT32* psize); 00089 SINT32 remove(UINT32* psize); 00090 SINT32 clean(); 00091 00095 UINT32 getSize() 00096 { 00097 if (m_pcsQueue) 00098 { 00099 m_pcsQueue->lock(); 00100 UINT32 s=m_nQueueSize; 00101 m_pcsQueue->unlock(); 00102 return s; 00103 } 00104 return 0; 00105 } 00106 00111 bool isEmpty() 00112 { 00113 return (m_Queue==NULL); 00114 } 00115 00120 bool isClosed() 00121 { 00122 return m_bClosed; 00123 } 00124 00128 static SINT32 test(); 00129 00130 #ifdef QUEUE_SIZE_LOG 00131 void logIfSizeGreaterThen(UINT32 size) 00132 { 00133 m_nLogSize=size; 00134 } 00135 #endif 00136 00137 private: 00138 QUEUE* m_Queue; 00139 QUEUE* m_lastElem; 00140 volatile UINT32 m_nQueueSize; 00141 volatile bool m_bClosed; 00142 UINT32 m_nExpectedElementSize; 00143 //QUEUE* m_pHeap; 00144 CAMutex* m_pcsQueue; 00145 CAConditionVariable* m_pconvarSize; 00146 00147 #ifdef QUEUE_SIZE_LOG 00148 UINT32 m_nLogSize; 00149 #endif 00150 /* SINT32 incHeap() 00151 { 00152 QUEUE* pEntry; 00153 for(int i=0;i<100;i++) 00154 { 00155 pEntry=new QUEUE; 00156 pEntry->next=m_pHeap; 00157 if(m_nExpectedElementSize>0) 00158 pEntry->pBuff=new UINT8[m_nExpectedElementSize]; 00159 else 00160 pEntry->pBuff=NULL; 00161 m_pHeap=pEntry; 00162 } 00163 return E_SUCCESS; 00164 }*/ 00165 }; 00166 #endif 00167 #endif //ONLY_LOCAL_PROXY
1.7.6.1