Mixe for Privacy and Anonymity in the Internet
CACacheLoadBalancing.cpp
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 #include "StdAfx.h"
29 #include "CACacheLoadBalancing.hpp"
30 
31 /* Adds a new Address to the pool of Addresses.
32  * This addresses are used for Load Balancing (currently a simple Round Robin).
33  * @retval E_UNKNOWN, in case of an error
34  * @retval E_SUCCESS, if succesful
35  */
37  {
38  if(pAddr->getType()!=AF_INET)
39  return E_UNKNOWN;
40  CACHE_LB_ENTRY* pEntry=new CACHE_LB_ENTRY;
41  if(pEntry==NULL)
42  return E_UNKNOWN;
43  pEntry->pAddr=(CASocketAddrINet*)pAddr->clone();
44  m_csLock.lock();
45  if(pSelectedEntry==NULL)
46  {
47  pSelectedEntry=pEntry;
49  }
50  else
51  {
52  pEntry->next=pSelectedEntry->next;
53  pSelectedEntry->next=pEntry;
54  }
56  m_csLock.unlock();
57  return E_SUCCESS;
58  }
t_cachelb_list CACHE_LB_ENTRY
signed int SINT32
Definition: basetypedefs.h:132
CACHE_LB_ENTRY * pSelectedEntry
SINT32 add(CASocketAddr *const pAddr)
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...
virtual SINT32 getType() const =0
The type (family) of socket for which this address is useful.
virtual CASocketAddr * clone() const =0
Creates a copy of the Address.
This class represents a socket address for Internet (IP) connections.
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
#define E_UNKNOWN
Definition: errorcodes.hpp:3
CASocketAddrINet * pAddr
struct t_cachelb_list * next