XRootD
XrdNetCache Class Reference

#include <XrdNetCache.hh>

+ Collaboration diagram for XrdNetCache:

Classes

union  anItem.__unnamed104__
 

Public Member Functions

 XrdNetCache (int psize=987, int csize=1597)
 
 ~XrdNetCache ()
 
void Add (XrdNetAddrInfo *hAddr, const char *hName)
 
char * Find (XrdNetAddrInfo *hAddr)
 

Static Public Member Functions

static void SetKT (int ktval)
 

Detailed Description

Definition at line 41 of file XrdNetCache.hh.


Class Documentation

◆ XrdNetCache::anItem.__unnamed104__

union XrdNetCache::anItem.__unnamed104__

Definition at line 96 of file XrdNetCache.hh.

+ Collaboration diagram for XrdNetCache::anItem.__unnamed104__:
Class Members
int aV4[4]
long long aV6[2]
char aVal[16]

Constructor & Destructor Documentation

◆ XrdNetCache()

XrdNetCache::XrdNetCache ( int  psize = 987,
int  csize = 1597 
)

Constructor. When allocateing a new hash, two adjacent Fibonocci numbers. The series is simply n[j] = n[j-1] + n[j-2].

Parameters
psizethe correct Fibonocci antecedent to csize.
csizethe initial size of the table.

Definition at line 49 of file XrdNetCache.cc.

50 {
51  prevtablesize = psize;
52  nashtablesize = csize;
53  Threshold = (csize * LoadMax) / 100;
54  nashnum = 0;
55  nashtable = (anItem **)malloc( (size_t)(csize*sizeof(anItem *)) );
56  memset((void *)nashtable, 0, (size_t)(csize*sizeof(anItem *)));
57 }

◆ ~XrdNetCache()

XrdNetCache::~XrdNetCache ( )
inline

Destructor. The XrdNetCache object is not designed to be deleted. Doing so will cause memory to be lost.

Definition at line 89 of file XrdNetCache.hh.

89 {} // Never gets deleted

Member Function Documentation

◆ Add()

void XrdNetCache::Add ( XrdNetAddrInfo hAddr,
const char *  hName 
)

Add an address-hostname association to the cache. The address must be an INET family address; otherwise it is not added.

Parameters
hAddrpoints to the address of the name.
hNamepoints to the name to be associated with the address.

Definition at line 63 of file XrdNetCache.cc.

64 {
65  anItem Item, *hip;
66  int kent;
67 
68 // Get the key and make sure this is a valid address (should be)
69 //
70  if (!GenKey(Item, hAddr)) return;
71 
72 // We may be in a race condition, check we have this item
73 //
74  myMutex.Lock();
75  if ((hip = Locate(Item)))
76  {if (hip->hName) free(hip->hName);
77  hip->hName = strdup(hName);
78  hip->expTime = time(0) + keepTime;
79  myMutex.UnLock();
80  return;
81  }
82 
83 // Check if we should expand the table
84 //
85  if (++nashnum > Threshold) Expand();
86 
87 // Allocate a new entry
88 //
89  hip = new anItem(Item, hName, keepTime);
90 
91 // Add the entry to the table
92 //
93  kent = hip->aHash % nashtablesize;
94  hip->Next = nashtable[kent];
95  nashtable[kent] = hip;
96  myMutex.UnLock();
97 }

References XrdSysMutex::Lock(), and XrdSysMutex::UnLock().

Referenced by XrdNetAddrInfo::Resolve().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Find()

char * XrdNetCache::Find ( XrdNetAddrInfo hAddr)

Locate an address-hostname association in the cache.

Parameters
hAddrpoints to the address of the name.
Returns
Success: an strdup'd string of the corresponding name. Failure: 0;

Definition at line 148 of file XrdNetCache.cc.

149 {
150  anItem Item, *nip, *pip = 0;
151  int kent;
152 
153 // Get the hash for this address
154 //
155  if (!GenKey(Item, hAddr)) return 0;
156 
157 // Compute position of the hash table entry
158 //
159  myMutex.Lock();
160  kent = Item.aHash%nashtablesize;
161 
162 // Find the entry
163 //
164  nip = nashtable[kent];
165  while(nip && *nip != Item) {pip = nip; nip = nip->Next;}
166  if (!nip) {myMutex.UnLock(); return 0;}
167 
168 // Make sure entry has not expired
169 //
170  if (nip->expTime > time(0))
171  {char *hName = strdup(nip->hName);
172  myMutex.UnLock();
173  return hName;
174  }
175 
176 // Remove the entry and return not found
177 //
178  if (pip) pip->Next = nip->Next;
179  else nashtable[kent] = nip->Next;
180  myMutex.UnLock();
181  delete nip;
182  return 0;
183 }

References XrdSysMutex::Lock(), and XrdSysMutex::UnLock().

Referenced by XrdNetAddrInfo::Format(), and XrdNetAddrInfo::Name().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetKT()

static void XrdNetCache::SetKT ( int  ktval)
inlinestatic

Set the default keep time for entries in the cache during initialization.

Parameters
ktvalthe number of seconds to keep an entry in the cache.

Definition at line 72 of file XrdNetCache.hh.

72 {keepTime = ktval;}

The documentation for this class was generated from the following files: