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{}

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 = new XrdLinkCtl[LinkAlloc]();
131 if (!nlp)
132 {LTMutex.UnLock();
133 Log.Emsg("Link", ENOMEM, "create link");
134 return (XrdLink *)0;
135 }
136 blp = &LinkTab[peerFD/LinkAlloc*LinkAlloc];
137 for (i = 0; i < LinkAlloc; i++, blp++) *blp = &nlp[i];
138 lp = LinkTab[peerFD];
139 }
140 else lp->Reset();
141 LinkBat[peerFD] = XRDLINK_USED;
142 if (peerFD > LTLast) LTLast = peerFD;
143 LTMutex.UnLock();
144
145// Establish the instance number of this link. This is will prevent us from
146// sending asynchronous responses to the wrong client when the file descriptor
147// gets reused for connections to the same host.
148//
149 instMutex.Lock();
150 lp->Instance = myInstance++;
151 instMutex.UnLock();
152
153// Establish the address and connection name of this link
154//
155 peer.Format(hName, sizeof(hName), XrdNetAddr::fmtAuto,
157 lp->HostName = strdup(hName);
158 lp->HNlen = strlen(hName);
159 XrdNetTCP->Trim(hName);
160 lp->Addr = peer;
161 strlcpy(lp->Lname, hName, sizeof(lp->Lname));
162 bl = sprintf(buff, "anon.0:%d", peerFD);
163 unp = lp->Uname + sizeof(Uname) - bl - 1; // Solaris compatibility
164 memcpy(unp, buff, bl);
165 lp->ID = unp;
166 lp->PollInfo.FD = lp->LinkInfo.FD = peerFD;
167 lp->Comment = (const char *)unp;
168
169// Set options as needed
170//
171 lp->LockReads = (0 != (opts & XRDLINK_RDLOCK));
172 lp->KeepFD = (0 != (opts & XRDLINK_NOCLOSE));
173
174// Update statistics and return the link. We need to actually get the stats
175// mutex even when using atomics because we need to use compound operations.
176// The atomics will keep reporters from seeing partial results.
177//
179 AtomicInc(LinkCountTot); // LinkCountTot++
182 return lp;
183}
#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
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 XrdLinkXeq::Addr, AtomicInc, XrdJob::Comment, XrdSysError::Emsg(), 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, XrdSysMutex::Lock(), XrdLinkXeq::LockReads, XrdGlobal::Log, XrdNetAddrInfo::noPort, XrdNetAddrInfo::old6Map4, opts, XrdLinkXeq::PollInfo, XrdLinkXeq::Reset(), XrdNetAddrInfo::SockFD(), XrdLinkXeq::statsMutex, strlcpy(), XrdNet::Trim(), XrdLinkXeq::Uname, XrdSysMutex::UnLock(), 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 }

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

+ 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::Instance.

◆ 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 }

References XrdLinkXeq::PollInfo.

◆ 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 194 of file XrdLinkCtl.cc.

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

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

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 240 of file XrdLinkCtl.cc.

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

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

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 277 of file XrdLinkCtl.cc.

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

References XrdPoll::Disable(), XrdSysError::Emsg(), 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 319 of file XrdLinkCtl.cc.

320{
321 if (wkSec > 0) waitKill = static_cast<short>(wkSec);
322 if (kwSec > 0) killWait = static_cast<short>(kwSec);
323}
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 329 of file XrdLinkCtl.cc.

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

References XrdLink::XrdLink(), DEBUG, XrdSysError::Emsg(), XrdGlobal::Log, XrdGlobal::Sched, XrdScheduler::Schedule(), and TRACE.

+ Here is the call graph for this function:

◆ SyncAll()

void XrdLinkCtl::SyncAll ( )
static

Synchronize statustics for ll links.

Definition at line 374 of file XrdLinkCtl.cc.

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

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

Referenced by XrdLinkXeq::Stats().

+ Here is the call graph for this function:
+ 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 392 of file XrdLinkCtl.cc.

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

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

Referenced by XrdLinkXeq::Close().

+ Here is the call graph for this function:
+ 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: