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

#include <XrdLinkCtl.hh>

+ Inheritance diagram for XrdLinkCtl:
+ Collaboration diagram for XrdLinkCtl:

Public Member Functions

 XrdLinkCtl ()
 Constructor.
 

Static Public Member Functions

static XrdLinkAlloc (XrdNetAddr &peer, int opts=0)
 
static XrdLinkfd2link (int fd)
 
static XrdLinkfd2link (int fd, unsigned int inst)
 
static XrdPollInfofd2PollInfo (int fd)
 
static XrdLinkFind (int &curr, XrdLinkMatch *who=0)
 
static int getName (int &curr, char *bname, int blen, XrdLinkMatch *who=0)
 
static void idleScan ()
 Look for idle links and close hem down.
 
static void setKWT (int wkSec, int kwSec)
 
static int Setup (int maxfds, int idlewt)
 
static void SyncAll ()
 Synchronize statustics for ll links.
 
static void Unhook (int fd)
 Unhook a link from the active table of links.
 

Static Public Attributes

static short killWait = 3
 Link destruction control constants.
 
static short waitKill = 4
 

Additional Inherited Members

- Protected Member Functions inherited from XrdLinkXeq
int RecvIOV (const struct iovec *iov, int iocnt)
 
void Reset ()
 
int sendData (const char *Buff, int Blen)
 
int SendIOV (const struct iovec *iov, int iocnt, int bytes)
 
int SFError (int rc)
 
int TLS_Error (const char *act, XrdTls::RC rc)
 
bool TLS_Write (const char *Buff, int Blen)
 
 XrdLinkXeq ()
 
 ~XrdLinkXeq ()
 
XrdNetAddrInfoAddrInfo ()
 
int Backlog ()
 
int Client (char *buff, int blen)
 
int Close (bool defer=false)
 
void DoIt ()
 
int getIOStats (long long &inbytes, long long &outbytes, int &numstall, int &numtardy)
 
XrdTlsPeerCertsgetPeerCerts ()
 
XrdProtocolgetProtocol ()
 
const char * Name () const
 
const XrdNetAddrNetAddr () const
 
int Peek (char *buff, int blen, int timeout=-1)
 
int Recv (char *buff, int blen)
 
int Recv (char *buff, int blen, int timeout)
 
int Recv (const struct iovec *iov, int iocnt, int timeout)
 
int RecvAll (char *buff, int blen, int timeout=-1)
 
bool Register (const char *hName)
 
int Send (const char *buff, int blen)
 
int Send (const sfVec *sdP, int sdn)
 
int Send (const struct iovec *iov, int iocnt, int bytes=0)
 
void setID (const char *userid, int procid)
 
void setLocation (XrdNetAddrInfo::LocInfo &loc)
 
bool setNB ()
 
void setProtName (const char *name)
 
XrdProtocolsetProtocol (XrdProtocol *pp, bool push)
 
bool setTLS (bool enable, XrdTlsContext *ctx=0)
 
void Shutdown (bool getLock)
 
void syncStats (int *ctime=0)
 
int TLS_Peek (char *Buff, int Blen, int timeout)
 
int TLS_Recv (char *Buff, int Blen)
 
int TLS_Recv (char *Buff, int Blen, int timeout, bool havelock=false)
 
int TLS_Recv (const struct iovec *iov, int iocnt, int timeout)
 
int TLS_RecvAll (char *Buff, int Blen, int timeout)
 
int TLS_Send (const char *Buff, int Blen)
 
int TLS_Send (const sfVec *sfP, int sfN)
 
int TLS_Send (const struct iovec *iov, int iocnt, int bytes)
 
const char * verTLS ()
 
- Protected Member Functions inherited from XrdJob
 XrdJob (const char *desc="")
 
virtual ~XrdJob ()
 
- Static Protected Member Functions inherited from XrdLinkXeq
static int getName (int &curr, char *bname, int blen, XrdLinkMatch *who=0)
 
static int Stats (char *buff, int blen, bool do_sync=false)
 
- Protected Attributes inherited from XrdLinkXeq
XrdNetAddr Addr
 
long long BytesIn
 
long long BytesInTot
 
long long BytesOut
 
long long BytesOutTot
 
int HNlen
 
char isIdle
 
bool KeepFD
 
char Lname [256]
 
bool LockReads
 
XrdProtocolProtoAlt
 
XrdProtocolProtocol
 
XrdSysMutex rdMutex
 
XrdSendQsendQ
 
int SfIntr
 
int stallCnt
 
int stallCntTot
 
int tardyCnt
 
int tardyCntTot
 
XrdTlsSocket tlsIO
 
char Uname [24]
 
XrdSysMutex wrMutex
 
XrdLinkInfo LinkInfo
 
XrdPollInfo PollInfo
 
- Protected Attributes inherited from XrdJob
const char * Comment
 
XrdJobNextJob
 
- Static Protected Attributes inherited from XrdLinkXeq
static long long LinkBytesIn = 0
 
static long long LinkBytesOut = 0
 
static long long LinkConTime = 0
 
static int LinkCount = 0
 
static int LinkCountMax = 0
 
static long long LinkCountTot = 0
 
static int LinkSfIntr = 0
 
static int LinkStalls = 0
 
static int LinkTimeOuts = 0
 
static XrdSysMutex statsMutex
 
static const char * TraceID = "LinkXeq"
 

Detailed Description

Definition at line 42 of file XrdLinkCtl.hh.

Constructor & Destructor Documentation

◆ XrdLinkCtl()

XrdLinkCtl::XrdLinkCtl ( )
inline

Constructor.

Definition at line 197 of file XrdLinkCtl.hh.

197{}

Referenced by Alloc(), Find(), getName(), idleScan(), and Setup().

+ Here is the caller graph for this function:

Member Function Documentation

◆ Alloc()

XrdLink * XrdLinkCtl::Alloc ( XrdNetAddr & peer,
int opts = 0 )
static

Definition at line 101 of file XrdLinkCtl.cc.

102{
103 XrdLinkCtl *lp;
104 char hName[1024], *unp, buff[32];
105 int bl, peerFD = peer.SockFD();
106
107// Make sure that the incoming file descriptor can be handled
108//
109 if (peerFD < 0 || peerFD >= maxFD)
110 {snprintf(hName, sizeof(hName), "%d", peerFD);
111 Log.Emsg("Link", "attempt to alloc out of range FD -",hName);
112 return (XrdLink *)0;
113 }
114
115// Make sure that the link slot is available
116//
117 LTMutex.Lock();
118 if (LinkBat[peerFD])
119 {LTMutex.UnLock();
120 snprintf(hName, sizeof(hName), "%d", peerFD);
121 Log.Emsg("Link", "attempt to reuse active link FD -",hName);
122 return (XrdLink *)0;
123 }
124
125// Check if we already have a link object in this slot. If not, allocate
126// a quantum of link objects and put them in the table.
127//
128 if (!(lp = LinkTab[peerFD]))
129 {unsigned int i;
130 XrdLinkCtl **blp, *nlp = 0;
131 if (LinkAlloc <= std::size_t(-1) / 2 / sizeof(XrdLinkCtl))
132 nlp = new XrdLinkCtl[LinkAlloc]();
133 if (!nlp)
134 {LTMutex.UnLock();
135 Log.Emsg("Link", ENOMEM, "create link");
136 return (XrdLink *)0;
137 }
138 blp = &LinkTab[peerFD/LinkAlloc*LinkAlloc];
139 for (i = 0; i < LinkAlloc; i++, blp++) *blp = &nlp[i];
140 lp = LinkTab[peerFD];
141 }
142 else lp->Reset();
143 LinkBat[peerFD] = XRDLINK_USED;
144 if (peerFD > LTLast) LTLast = peerFD;
145 LTMutex.UnLock();
146
147// Establish the instance number of this link. This is will prevent us from
148// sending asynchronous responses to the wrong client when the file descriptor
149// gets reused for connections to the same host.
150//
151 instMutex.Lock();
152 lp->Instance = myInstance++;
153 instMutex.UnLock();
154
155// Establish the address and connection name of this link
156//
157 peer.Format(hName, sizeof(hName), XrdNetAddr::fmtAuto,
159 lp->HostName = strdup(hName);
160 lp->HNlen = strlen(hName);
161 XrdNetTCP->Trim(hName);
162 lp->Addr = peer;
163 strlcpy(lp->Lname, hName, sizeof(lp->Lname));
164 bl = sprintf(buff, "anon.0:%d", peerFD);
165 unp = lp->Uname + sizeof(Uname) - bl - 1; // Solaris compatibility
166 memcpy(unp, buff, bl);
167 lp->ID = unp;
168 lp->PollInfo.FD = lp->LinkInfo.FD = peerFD;
169 lp->Comment = (const char *)unp;
170
171// Set options as needed
172//
173 lp->LockReads = (0 != (opts & XRDLINK_RDLOCK));
174 lp->KeepFD = (0 != (opts & XRDLINK_NOCLOSE));
175
176// Update statistics and return the link. We need to actually get the stats
177// mutex even when using atomics because we need to use compound operations.
178// The atomics will keep reporters from seeing partial results.
179//
180 statsMutex.Lock();
181 AtomicInc(LinkCountTot); // LinkCountTot++
183 statsMutex.UnLock();
184 return lp;
185}
#define XRDLINK_NOCLOSE
Definition XrdLinkCtl.hh:59
#define XRDLINK_RDLOCK
Definition XrdLinkCtl.hh:58
struct myOpts opts
#define AtomicInc(x)
size_t strlcpy(char *dst, const char *src, size_t sz)
const char * Comment
Definition XrdJob.hh:47
XrdLinkCtl()
Constructor.
char Uname[24]
static int LinkCountMax
XrdLinkInfo LinkInfo
XrdNetAddr Addr
static long long LinkCountTot
static int LinkCount
void Reset()
XrdPollInfo PollInfo
char Lname[256]
static XrdSysMutex statsMutex
static const int noPort
Do not add port number.
static const int old6Map4
Use deprecated IPV6 mapped format.
int Format(char *bAddr, int bLen, fmtUse fmtType=fmtAuto, int fmtOpts=0)
@ fmtAuto
Hostname if already resolved o/w use fmtAddr.
void Trim(char *hname)
Definition XrdNet.cc:343
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
XrdInet * XrdNetTCP
Definition XrdGlobals.cc:53
XrdSysError Log
Definition XrdConfig.cc:112

References XrdLink::XrdLink(), XrdLinkCtl(), XrdLinkXeq::Addr, AtomicInc, XrdJob::Comment, XrdLinkInfo::FD, XrdPollInfo::FD, XrdNetAddrInfo::fmtAuto, XrdNetAddrInfo::Format(), XrdLinkXeq::HNlen, XrdLink::HostName, XrdLink::ID, XrdLink::Instance, XrdLinkXeq::KeepFD, XrdLinkXeq::LinkCount, XrdLinkXeq::LinkCountMax, XrdLinkXeq::LinkCountTot, XrdLinkXeq::LinkInfo, XrdLinkXeq::Lname, XrdLinkXeq::LockReads, XrdGlobal::Log, XrdNetAddrInfo::noPort, XrdNetAddrInfo::old6Map4, opts, XrdLinkXeq::PollInfo, XrdLinkXeq::Reset(), XrdNetAddrInfo::SockFD(), XrdLinkXeq::statsMutex, strlcpy(), XrdLinkXeq::Uname, XRDLINK_NOCLOSE, XRDLINK_RDLOCK, and XrdGlobal::XrdNetTCP.

Referenced by XrdInet::Accept(), and XrdInet::Connect().

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

◆ fd2link() [1/2]

static XrdLink * XrdLinkCtl::fd2link ( int fd)
inlinestatic

Translate a file descriptor number to the corresponding link object.

Parameters
fdThe file descriptor number.
Returns
!0 Pointer to the link object. =0 The file descriptor is not associated with a link.

Definition at line 72 of file XrdLinkCtl.hh.

73 {if (fd < 0) fd = -fd;
74 return (fd <= LTLast && LinkBat[fd] ? LinkTab[fd] : 0);
75 }

References XrdLink::XrdLink().

Referenced by XrdXrootdResponse::Send(), and XrdLink::Terminate().

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

◆ fd2link() [2/2]

static XrdLink * XrdLinkCtl::fd2link ( int fd,
unsigned int inst )
inlinestatic

Translate a file descriptor number and an instance to a link object.

Parameters
fdThe file descriptor number.
instThe file descriptor number instance number.
Returns
!0 Pointer to the link object. =0 The file descriptor instance is not associated with a link.

Definition at line 87 of file XrdLinkCtl.hh.

88 {if (fd < 0) fd = -fd;
89 if (fd <= LTLast && LinkBat[fd] && LinkTab[fd]
90 && LinkTab[fd]->Instance == inst) return LinkTab[fd];
91 return (XrdLink *)0;
92 }

References XrdLink::XrdLink(), and XrdLink::Instance.

+ Here is the call graph for this function:

◆ fd2PollInfo()

static XrdPollInfo * XrdLinkCtl::fd2PollInfo ( int fd)
inlinestatic

Translate a file descriptor number to the corresponding PollInfo object.

Parameters
fdThe file descriptor number.
Returns
!0 Pointer to the PollInfo object. =0 The file descriptor is not associated with a link.

Definition at line 103 of file XrdLinkCtl.hh.

104 {if (fd < 0) fd = -fd;
105 if (fd <= LTLast && LinkBat[fd])
106 return &(LinkTab[fd]->PollInfo);
107 return 0;
108 }

◆ Find()

XrdLink * XrdLinkCtl::Find ( int & curr,
XrdLinkMatch * who = 0 )
static

Find the next link matching certain attributes.

Parameters
currIs an internal tracking value that allows repeated calls. It must be set to a value of 0 or less on the initial call and not touched therafter unless a null pointer is returned.
whoIf the object use to check if the link matches the wanted criterea (typically, client name and host name). If the ppointer is nil, the next link is always returned.
Returns
!0 Pointer to the link object that matches the criterea. The link's reference counter is increased to prevent it from being reused. A subsequent call will reduce the number. =0 No more links exist with the specified criterea.

Definition at line 196 of file XrdLinkCtl.cc.

197{
198 XrdLinkCtl *lp;
199 const int MaxSeek = 16;
200 unsigned int myINS;
201 int i, seeklim = MaxSeek;
202
203// Do initialization
204//
205 LTMutex.Lock();
206 if (curr >= 0 && LinkTab[curr]) LinkTab[curr]->setRef(-1);
207 else curr = -1;
208
209// Find next matching link. Since this may take some time, we periodically
210// release the LTMutex lock which drives up overhead but will still allow
211// other critical operations to occur.
212//
213 for (i = curr+1; i <= LTLast; i++)
214 {if ((lp = LinkTab[i]) && LinkBat[i] && lp->HostName)
215 if (!who
216 || who->Match(lp->ID,lp->Lname-lp->ID-1,lp->HostName,lp->HNlen))
217 {myINS = lp->Instance;
218 LTMutex.UnLock();
219 lp->setRef(1);
220 curr = i;
221 if (myINS == lp->Instance) return lp;
222 LTMutex.Lock();
223 }
224 if (!seeklim--) {LTMutex.UnLock(); seeklim = MaxSeek; LTMutex.Lock();}
225 }
226
227// Done scanning the table
228//
229 LTMutex.UnLock();
230 curr = -1;
231 return 0;
232}
int Match(const char *uname, int unlen, const char *hname, int hnlen)

References XrdLink::XrdLink(), XrdLinkCtl(), XrdLinkXeq::HNlen, XrdLink::HostName, XrdLink::ID, XrdLink::Instance, XrdLinkXeq::Lname, XrdLinkMatch::Match(), and XrdLink::setRef().

Referenced by XrdLink::Find().

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

◆ getName()

int XrdLinkCtl::getName ( int & curr,
char * bname,
int blen,
XrdLinkMatch * who = 0 )
static

Find the next client name matching certain attributes.

Parameters
currIs an internal tracking value that allows repeated calls. It must be set to a value of 0 or less on the initial call and not touched therafter unless zero is returned.
bnamePointer to a buffer where the name is to be returned.
blenThe length of the buffer.
whoIf the object use to check if the link matches the wanted criterea (typically, client name and host name). If the pointer is nil, a match always occurs.
Returns
!0 The length of the name placed in the buffer. =0 No more links exist with the specified criterea.

Definition at line 242 of file XrdLinkCtl.cc.

243{
244 XrdLinkCtl *lp;
245 const int MaxSeek = 16;
246 int i, ulen = 0, seeklim = MaxSeek;
247
248// Find next matching link. Since this may take some time, we periodically
249// release the LTMutex lock which drives up overhead but will still allow
250// other critical operations to occur.
251//
252 LTMutex.Lock();
253 for (i = curr+1; i <= LTLast; i++)
254 {if ((lp = LinkTab[i]) && LinkBat[i] && lp->HostName)
255 if (!who
256 || who->Match(lp->ID,lp->Lname-lp->ID-1,lp->HostName,lp->HNlen))
257 {ulen = lp->Client(nbuf, nbsz);
258 LTMutex.UnLock();
259 curr = i;
260 return ulen;
261 }
262 if (!seeklim--) {LTMutex.UnLock(); seeklim = MaxSeek; LTMutex.Lock();}
263 }
264 LTMutex.UnLock();
265
266// Done scanning the table
267//
268 curr = -1;
269 return 0;
270}
int Client(char *buff, int blen)

References XrdLinkCtl(), XrdLinkXeq::Client(), XrdLinkXeq::HNlen, XrdLink::HostName, XrdLink::ID, XrdLinkXeq::Lname, and XrdLinkMatch::Match().

Referenced by XrdLink::getName().

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

◆ idleScan()

void XrdLinkCtl::idleScan ( )
static

Look for idle links and close hem down.

Definition at line 279 of file XrdLinkCtl.cc.

280{
281 XrdLinkCtl *lp;
282 int i, ltlast, lnum = 0, tmo = 0, tmod = 0;
283
284// Get the current link high watermark
285//
286 LTMutex.Lock();
287 ltlast = LTLast;
288 LTMutex.UnLock();
289
290// Scan across all links looking for idle links. Links are never deallocated
291// so we don't need any special kind of lock for these
292//
293 for (i = 0; i <= ltlast; i++)
294 {if (LinkBat[i] != XRDLINK_USED
295 || !(lp = LinkTab[i])) continue;
296 lnum++;
297 lp->LinkInfo.opMutex.Lock();
298 if (lp->isIdle) tmo++;
299 lp->isIdle++;
300 if ((int(lp->isIdle)) < idleTicks)
301 {lp->LinkInfo.opMutex.UnLock(); continue;}
302 lp->isIdle = 0;
303 if (!(lp->PollInfo.Poller) || !(lp->PollInfo.isEnabled))
304 Log.Emsg("LinkScan","Link",lp->ID,"is disabled and idle.");
305 else if (lp->LinkInfo.InUse == 1)
306 {lp->PollInfo.Poller->Disable(lp->PollInfo, "idle timeout");
307 tmod++;
308 }
309 lp->LinkInfo.opMutex.UnLock();
310 }
311
312// Trace what we did
313//
314 TRACE(CONN, lnum <<" links; " <<tmo <<" idle; " <<tmod <<" force closed");
315}
#define TRACE(act, x)
Definition XrdTrace.hh:63
XrdSysRecMutex opMutex
XrdPoll * Poller
virtual void Disable(XrdPollInfo &pInfo, const char *etxt=0)=0

References XrdLinkCtl(), XrdPoll::Disable(), XrdLink::ID, XrdLinkInfo::InUse, XrdPollInfo::isEnabled, XrdLinkXeq::isIdle, XrdLinkXeq::LinkInfo, XrdSysMutex::Lock(), XrdGlobal::Log, XrdLinkInfo::opMutex, XrdPollInfo::Poller, XrdLinkXeq::PollInfo, TRACE, and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

◆ setKWT()

void XrdLinkCtl::setKWT ( int wkSec,
int kwSec )
static

Set kill constants.

Parameters
wkSecSeconds to wait for kill to happed,
kwSecThe minimum number of seconds to wait after killing a connection for it to end.

Definition at line 321 of file XrdLinkCtl.cc.

322{
323 if (wkSec > 0) waitKill = static_cast<short>(wkSec);
324 if (kwSec > 0) killWait = static_cast<short>(kwSec);
325}
static short waitKill
static short killWait
Link destruction control constants.

References killWait, and waitKill.

◆ Setup()

int XrdLinkCtl::Setup ( int maxfds,
int idlewt )
static

Setup link processing.

Parameters
maxfdsThe maximum number of connections to handle.
idlewtThe time interval to check for idle connections.
Returns
!0 Successful. =0 Setup failed.

Definition at line 331 of file XrdLinkCtl.cc.

332{
333 int numalloc;
334
335// Compute the number of link objects we should allocate at a time. Generally,
336// we like to allocate 8k of them at a time but always as a power of two.
337//
338 maxFD = maxfds;
339 numalloc = 8192 / sizeof(XrdLink);
340 LinkAlloc = 1;
341 while((numalloc = numalloc/2)) LinkAlloc = LinkAlloc*2;
342 TRACE(DEBUG, "Allocating " <<LinkAlloc <<" link objects at a time");
343
344// Create the link table
345//
346 if (!(LinkTab = (XrdLinkCtl **)malloc(maxfds*sizeof(XrdLinkCtl*)+LinkAlloc)))
347 {Log.Emsg("Link", ENOMEM, "create LinkTab"); return 0;}
348 memset((void *)LinkTab, 0, maxfds*sizeof(XrdLinkCtl *));
349
350// Create the slot status table
351//
352 if (!(LinkBat = (char *)malloc(maxfds*sizeof(char)+LinkAlloc)))
353 {Log.Emsg("Link", ENOMEM, "create LinkBat"); return 0;}
354 memset((void *)LinkBat, XRDLINK_FREE, maxfds*sizeof(char));
355
356// Create an idle connection scan job
357//
358 if (idlewait)
359 {if ((idleCheck = idlewait/3)) idleTicks = 3;
360 else {idleTicks = 1;
361 idleCheck = idlewait;
362 }
363 LinkScan *ls = new LinkScan;
364 Sched.Schedule((XrdJob *)ls, idleCheck+time(0));
365 }
366
367// All done
368//
369 return 1;
370}
#define DEBUG(x)
XrdJob(const char *desc="")
Definition XrdJob.hh:51
void Schedule(XrdJob *jp)
XrdScheduler Sched
Definition XrdLinkCtl.cc:54

References XrdJob::XrdJob(), XrdLink::XrdLink(), XrdLinkCtl(), DEBUG, XrdGlobal::Log, XrdGlobal::Sched, and TRACE.

+ Here is the call graph for this function:

◆ SyncAll()

void XrdLinkCtl::SyncAll ( )
static

Synchronize statustics for ll links.

Definition at line 376 of file XrdLinkCtl.cc.

377{
378 int myLTLast;
379
380// Get the current last entry
381//
382 LTMutex.Lock(); myLTLast = LTLast; LTMutex.UnLock();
383
384// Run through all the links and sync the statistics
385//
386 for (int i = 0; i <= myLTLast; i++)
387 {if (LinkBat[i] == XRDLINK_USED && LinkTab[i]) LinkTab[i]->syncStats();}
388}

Referenced by XrdLinkXeq::Stats().

+ Here is the caller graph for this function:

◆ Unhook()

void XrdLinkCtl::Unhook ( int fd)
static

Unhook a link from the active table of links.

Definition at line 394 of file XrdLinkCtl.cc.

395{
396
397// Indicate link no longer actvely neing used
398//
399 LTMutex.Lock();
400 LinkBat[fd] = XRDLINK_FREE;
401 if (fd == LTLast) while(LTLast && !(LinkBat[LTLast])) LTLast--;
402 LTMutex.UnLock();
403}

Referenced by XrdLinkXeq::Close().

+ Here is the caller graph for this function:

Member Data Documentation

◆ killWait

short XrdLinkCtl::killWait = 3
static

Link destruction control constants.

Definition at line 190 of file XrdLinkCtl.hh.

Referenced by setKWT(), and XrdLink::Terminate().

◆ waitKill

short XrdLinkCtl::waitKill = 4
static

Definition at line 191 of file XrdLinkCtl.hh.

Referenced by setKWT(), and XrdLink::Terminate().


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