XRootD
Loading...
Searching...
No Matches
XrdOucReqID Class Reference

#include <XrdOucReqID.hh>

+ Collaboration diagram for XrdOucReqID:

Public Member Functions

 XrdOucReqID ()
 
 XrdOucReqID (const XrdNetSockAddr *myAddr, int myPort=-1)
 
 ~XrdOucReqID ()
 
char * ID (char *buff, int blen)
 
char * isMine (char *reqid, int &hport, char *hname, int hlen)
 
char * PFX ()
 

Static Public Member Functions

static int Index (int KeyMax, const char *KeyVal, int KeyLen=0)
 

Detailed Description

Definition at line 41 of file XrdOucReqID.hh.

Constructor & Destructor Documentation

◆ XrdOucReqID() [1/2]

XrdOucReqID::XrdOucReqID ( )

Definition at line 53 of file XrdOucReqID.cc.

54{
55 char xbuff[256];
56 int eNow = static_cast<int>(time(0)), myPid = static_cast<int>(getpid());
57
58// Now format the formatting template
59//
60 snprintf(xbuff, sizeof(xbuff)-1, "%08X:%08x.%%d", myPid, eNow);
61 reqFMT = strdup(xbuff);
62 xbuff[8] = 0;
63 reqPFX = strdup(xbuff);
64 reqPFXlen = 8;
65 reqIntern = 0;
66 reqNum = 0;
67}

◆ XrdOucReqID() [2/2]

XrdOucReqID::XrdOucReqID ( const XrdNetSockAddr * myAddr,
int myPort = -1 )

Definition at line 71 of file XrdOucReqID.cc.

72{
73 char ybuff[256], xbuff[512];
74 unsigned int pHash;
75 int n, eNow = static_cast<unsigned int>(time(0));
76
77// Encode our address as the prefix
78//
79 if ( (n = XrdNetUtils::Encode(myAddr, ybuff, sizeof(ybuff), myPort)) <= 0)
80 n = sprintf(ybuff, "%04X%08X", myPort, eNow);
81 reqPFX = strdup(ybuff);
82 reqPFXlen = n;
83 reqIntern = n+1;
84
85// Generate out hash
86//
87 pHash = XrdOucCRC::CRC32((const unsigned char *)ybuff, n);
88
89// Now format the formatting template
90//
91 snprintf(xbuff, sizeof(xbuff)-1, "%s:%08x.%08x:%%d", ybuff, pHash, eNow);
92 reqFMT = strdup(xbuff);
93 reqNum = 0;
94}
static int Encode(const XrdNetSockAddr *sadr, char *buff, int blen, int port=-1)
static uint32_t CRC32(const unsigned char *data, int count)
Definition XrdOucCRC.cc:171

References XrdOucCRC::CRC32(), and XrdNetUtils::Encode().

+ Here is the call graph for this function:

◆ ~XrdOucReqID()

XrdOucReqID::~XrdOucReqID ( )
inline

Definition at line 56 of file XrdOucReqID.hh.

56{} // Statics go away at exit

Member Function Documentation

◆ ID()

char * XrdOucReqID::ID ( char * buff,
int blen )

Definition at line 139 of file XrdOucReqID.cc.

140{
141 int myNum;
142
143// Get a new sequence number
144//
145 myMutex.Lock();
146 myNum = (reqNum += 1);
147 myMutex.UnLock();
148
149// Generate the request id and return it
150//
151 snprintf(buff, blen-1, reqFMT, myNum);
152 return buff+reqIntern;
153}

Referenced by XrdOssSys::Stage_QT().

+ Here is the caller graph for this function:

◆ Index()

int XrdOucReqID::Index ( int KeyMax,
const char * KeyVal,
int KeyLen = 0 )
static

Definition at line 159 of file XrdOucReqID.cc.

160{
161 unsigned int pHash;
162
163// Get hash value for the key and return modulo of the KeyMax value
164//
165 pHash = XrdOucCRC::CRC32((const unsigned char *)KeyVal,
166 (KeyLen ? KeyLen : strlen(KeyVal)));
167 return (int)(pHash % KeyMax);
168}

References XrdOucCRC::CRC32().

+ Here is the call graph for this function:

◆ isMine()

char * XrdOucReqID::isMine ( char * reqid,
int & hport,
char * hname,
int hlen )

Definition at line 100 of file XrdOucReqID.cc.

101{
102 XrdNetAddr theAddr;
103 XrdNetSockAddr IP;
104 const char *theHost;
105 int thePort;
106 char *cp;
107
108// Determine whether this is our host
109//
110 if (!strncmp(reqPFX,reqid,reqPFXlen) && (cp = index(reqid,':'))) return cp+1;
111
112// Not ours, try to tell the caller who it is
113//
114 hport = 0;
115 if (!hlen) return 0;
116
117// Get the IP address of his id
118//
119 thePort = XrdNetUtils::Decode(&IP, reqid, reqPFXlen);
120 if (thePort <= 0) return 0;
121
122// Convert this in the appropriate way
123//
124 if (theAddr.Set(&IP.Addr)
125 || !(theHost = theAddr.Name())
126 || strlen(theHost) >= (unsigned int)hlen) return 0;
127
128// Return the alternate host
129//
130 strcpy(hname, theHost);
131 hport = thePort;
132 return 0;
133}
struct sockaddr Addr
const char * Name(const char *eName=0, const char **eText=0)
const char * Set(const char *hSpec, int pNum=PortInSpec)
static int Decode(XrdNetSockAddr *sadr, const char *buff, int blen)

References XrdNetSockAddr::Addr, XrdNetUtils::Decode(), XrdNetAddrInfo::Name(), and XrdNetAddr::Set().

+ Here is the call graph for this function:

◆ PFX()

char * XrdOucReqID::PFX ( )
inline

Definition at line 49 of file XrdOucReqID.hh.

49{return reqPFX;}

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