Loading...
Searching...
No Matches
XrdNetCache.hh
Go to the documentation of this file.
#ifndef __XRDNETCACHE_HH__
#define __XRDNETCACHE_HH__
/******************************************************************************/
/* */
/* X r d N e t C a c h e . h h */
/* */
/* (c) 2013 by the Board of Trustees of the Leland Stanford, Jr., University */
/* All Rights Reserved */
/* Produced by Andrew Hanushevsky for Stanford University under contract */
/* DE-AC02-76-SFO0515 with the Department of Energy */
/* */
/* This file is part of the XRootD software suite. */
/* */
/* XRootD is free software: you can redistribute it and/or modify it under */
/* the terms of the GNU Lesser General Public License as published by the */
/* Free Software Foundation, either version 3 of the License, or (at your */
/* option) any later version. */
/* */
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
/* */
/* The copyright holder's institutional names and contributor's names may not */
/* be used to endorse or promote products derived from this software without */
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/
#include <cstring>
#include <ctime>
#include <sys/types.h>
#include "XrdSys/XrdSysPthread.hh"
class XrdNetAddrInfo;
class XrdNetCache
{
public:
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void Add(XrdNetAddrInfo *hAddr, const char *hName);
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
char *Find(XrdNetAddrInfo *hAddr);
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
static
void SetKT(int ktval) {keepTime = ktval;}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
XrdNetCache(int psize = 987, int csize = 1597);
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
~XrdNetCache() {} // Never gets deleted
private:
static const int LoadMax = 80;
struct anItem
{union {long long aV6[2];
int aV4[4];
char aVal[16]; // Enough for IPV4 or IPV6
};
anItem *Next;
char *hName;
time_t expTime; // Expiration time
unsigned int aHash; // Hash value
int aLen; // Actual length 4 or 16
inline int operator!=(const anItem &oth)
{return aLen != oth.aLen || aHash != oth.aHash
|| memcmp(aVal, oth.aVal, aLen);
}
anItem() : Next(0), hName(0), aLen(0) {}
anItem(anItem &Item, const char *hn, int kt)
: Next(0), hName(strdup(hn)), expTime(time(0)+kt),
aHash(Item.aHash), aLen(Item.aLen)
{memcpy(aVal, Item.aVal, Item.aLen);}
~anItem() {if (hName) free(hName);}
};
void Expand();
int GenKey(anItem &Item, XrdNetAddrInfo *hAddr);
anItem *Locate(anItem &Item);
static int keepTime;
XrdSysMutex myMutex;
anItem **nashtable;
int prevtablesize;
int nashtablesize;
int nashnum;
int Threshold;
};
#endif
XrdSysPthread.hh
XrdNetAddrInfo
Definition XrdNetAddrInfo.hh:54
XrdNetCache::SetKT
static void SetKT(int ktval)
Definition XrdNetCache.hh:72
XrdNetCache::anItem.__unnamed0__::aV4
int aV4[4]
XrdNetCache::anItem.__unnamed0__::aVal
char aVal[16]
XrdNetCache::~XrdNetCache
~XrdNetCache()
Definition XrdNetCache.hh:89
XrdNetCache::Add
void Add(XrdNetAddrInfo *hAddr, const char *hName)
Definition XrdNetCache.cc:63
XrdNetCache::Find
char * Find(XrdNetAddrInfo *hAddr)
Definition XrdNetCache.cc:148
XrdNetCache::anItem.__unnamed0__::aV6
long long aV6[2]
XrdNetCache::XrdNetCache
XrdNetCache(int psize=987, int csize=1597)
Definition XrdNetCache.cc:49
XrdSysMutex
Definition XrdSysPthread.hh:165