Mixe for Privacy and Anonymity in the Internet
CACacheLoadBalancing.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2000, The JAP-Team
3 All rights reserved.
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6 
7  - Redistributions of source code must retain the above copyright notice,
8  this list of conditions and the following disclaimer.
9 
10  - Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation and/or
12  other materials provided with the distribution.
13 
14  - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors
15  may be used to endorse or promote products derived from this software without specific
16  prior written permission.
17 
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
20 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
27 */
28 #ifndef _CA_CACHE_LOAD_BALANCING
29 #define _CA_CACHE_LOAD_BALANCING
30 #include "CASocketAddrINet.hpp"
31 #include "CAMutex.hpp"
32 
34  {
37  };
38 
40 
46  {
47  public:
49  {
51  pSelectedEntry=NULL;
52  }
54 
57  {
58  m_csLock.lock();
59  CACHE_LB_ENTRY* pEntry;
61  while(pSelectedEntry!=NULL)
62  {
63  if(pSelectedEntry->next==pFirst)
64  pEntry=NULL;
65  else
66  pEntry=pSelectedEntry->next;
67  delete pSelectedEntry->pAddr;
68  pSelectedEntry->pAddr = NULL;
69  delete pSelectedEntry;
70  pSelectedEntry = NULL;
71  pSelectedEntry=pEntry;
72  }
74  m_csLock.unlock();
75  return E_SUCCESS;
76  }
77 
78  SINT32 add(CASocketAddr* const pAddr);
79 
85  {
86  m_csLock.lock();
87  if(pSelectedEntry==NULL)
88  {
89  m_csLock.unlock();
90  return NULL;
91  }
93  m_csLock.unlock();
94  return pSelectedEntry->pAddr;
95  }
96 
97  /* Gets the number of Addresses added.
98  * @return number of added Addresses
99  */
101  {
102  return m_ElementCount;
103  }
104 
105  private:
109  };
110 #endif
t_cachelb_list CACHE_LB_ENTRY
signed int SINT32
Definition: basetypedefs.h:132
unsigned int UINT32
Definition: basetypedefs.h:131
This class stores Addresses off different Cache-Proxies.
CACHE_LB_ENTRY * pSelectedEntry
SINT32 add(CASocketAddr *const pAddr)
CASocketAddrINet * get()
Gets the 'next' Address according to the Load-Balancing algorithm.
SINT32 clean()
Deletes all information.
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41
This is an abstract class for representing a socket address used in CASocket, CADatagramSocket and CA...
This class represents a socket address for Internet (IP) connections.
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
CASocketAddrINet * pAddr
struct t_cachelb_list * next