xrootd
Loading...
Searching...
No Matches
XrdNetCache.hh
Go to the documentation of this file.
1#ifndef __XRDNETCACHE_HH__
2#define __XRDNETCACHE_HH__
3/******************************************************************************/
4/* */
5/* X r d N e t C a c h e . h h */
6/* */
7/* (c) 2013 by the Board of Trustees of the Leland Stanford, Jr., University */
8/* All Rights Reserved */
9/* Produced by Andrew Hanushevsky for Stanford University under contract */
10/* DE-AC02-76-SFO0515 with the Department of Energy */
11/* */
12/* This file is part of the XRootD software suite. */
13/* */
14/* XRootD is free software: you can redistribute it and/or modify it under */
15/* the terms of the GNU Lesser General Public License as published by the */
16/* Free Software Foundation, either version 3 of the License, or (at your */
17/* option) any later version. */
18/* */
19/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22/* License for more details. */
23/* */
24/* You should have received a copy of the GNU Lesser General Public License */
25/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27/* */
28/* The copyright holder's institutional names and contributor's names may not */
29/* be used to endorse or promote products derived from this software without */
30/* specific prior written permission of the institution or contributor. */
31/******************************************************************************/
32
33#include <cstring>
34#include <ctime>
35#include <sys/types.h>
36
38
39class XrdNetAddrInfo;
40
42{
43public:
44
45//------------------------------------------------------------------------------
51//------------------------------------------------------------------------------
52
53void Add(XrdNetAddrInfo *hAddr, const char *hName);
54
55//------------------------------------------------------------------------------
62//------------------------------------------------------------------------------
63
64char *Find(XrdNetAddrInfo *hAddr);
65
66//------------------------------------------------------------------------------
70//------------------------------------------------------------------------------
71static
72void SetKT(int ktval) {keepTime = ktval;}
73
74//------------------------------------------------------------------------------
80//------------------------------------------------------------------------------
81
82 XrdNetCache(int psize = 987, int csize = 1597);
83
84//------------------------------------------------------------------------------
87//------------------------------------------------------------------------------
88
89 ~XrdNetCache() {} // Never gets deleted
90
91private:
92
93static const int LoadMax = 80;
94
95struct anItem
96 {union {long long aV6[2];
97 int aV4[4];
98 char aVal[16]; // Enough for IPV4 or IPV6
99 };
101 char *hName;
102 time_t expTime; // Expiration time
103unsigned int aHash; // Hash value
104 int aLen; // Actual length 4 or 16
105
106inline int operator!=(const anItem &oth)
107 {return aLen != oth.aLen || aHash != oth.aHash
108 || memcmp(aVal, oth.aVal, aLen);
109 }
110
111 anItem() : Next(0), hName(0), aLen(0) {}
112
113 anItem(anItem &Item, const char *hn, int kt)
114 : Next(0), hName(strdup(hn)), expTime(time(0)+kt),
115 aHash(Item.aHash), aLen(Item.aLen)
116 {memcpy(aVal, Item.aVal, Item.aLen);}
117 ~anItem() {if (hName) free(hName);}
118 };
119
120void Expand();
121int GenKey(anItem &Item, XrdNetAddrInfo *hAddr);
123
124static int keepTime;
125
132};
133#endif
Definition XrdNetAddrInfo.hh:54
Definition XrdNetCache.hh:42
static int keepTime
Definition XrdNetCache.hh:124
static void SetKT(int ktval)
Definition XrdNetCache.hh:72
anItem ** nashtable
Definition XrdNetCache.hh:127
int prevtablesize
Definition XrdNetCache.hh:128
~XrdNetCache()
Definition XrdNetCache.hh:89
int GenKey(anItem &Item, XrdNetAddrInfo *hAddr)
void Expand()
int Threshold
Definition XrdNetCache.hh:131
int nashtablesize
Definition XrdNetCache.hh:129
XrdSysMutex myMutex
Definition XrdNetCache.hh:126
int nashnum
Definition XrdNetCache.hh:130
anItem * Locate(anItem &Item)
void Add(XrdNetAddrInfo *hAddr, const char *hName)
char * Find(XrdNetAddrInfo *hAddr)
static const int LoadMax
Definition XrdNetCache.hh:93
XrdNetCache(int psize=987, int csize=1597)
Definition XrdSysPthread.hh:165
Definition XrdNetCache.hh:96
unsigned int aHash
Definition XrdNetCache.hh:103
long long aV6[2]
Definition XrdNetCache.hh:96
anItem * Next
Definition XrdNetCache.hh:100
~anItem()
Definition XrdNetCache.hh:117
anItem(anItem &Item, const char *hn, int kt)
Definition XrdNetCache.hh:113
int aV4[4]
Definition XrdNetCache.hh:97
time_t expTime
Definition XrdNetCache.hh:102
int operator!=(const anItem &oth)
Definition XrdNetCache.hh:106
anItem()
Definition XrdNetCache.hh:111
char * hName
Definition XrdNetCache.hh:101
char aVal[16]
Definition XrdNetCache.hh:98
int aLen
Definition XrdNetCache.hh:104