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

#include <XrdLink.hh>

Inheritance diagram for XrdLink:
Collaboration diagram for XrdLink:

Public Types

typedef XrdOucSFVec sfVec

Public Member Functions

 XrdLink (XrdLinkXeq &lxq)
bool Activate ()
XrdNetAddrInfoAddrInfo ()
void armBridge ()
 Mark this link as an in-memory communications bridge (internal use only).
int Backlog ()
int Client (char *buff, int blen)
int Close (bool defer=false)
void Enable ()
 Enable the link to field interrupts.
int FDnum ()
int getIOStats (long long &inbytes, long long &outbytes, int &numstall, int &numtardy)
XrdTlsPeerCertsgetPeerCerts ()
XrdProtocolgetProtocol ()
 Obtain current protocol object pointer.
bool hasBridge () const
bool hasTLS () const
void Hold (bool lk)
const char * Host () const
unsigned int Inst () const
bool isFlawed () const
bool isInstance (unsigned int inst) const
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 Serialize ()
 Wait for all outstanding requests to be completed on the link.
int setEtext (const char *text)
void setID (const char *userid, int procid)
void setLocation (XrdNetAddrInfo::LocInfo &loc)
bool setNB ()
void setProtName (const char *name)
XrdProtocolsetProtocol (XrdProtocol *pp, bool runit=false, bool push=false)
void setRef (int cnt)
bool setTLS (bool enable, XrdTlsContext *ctx=0)
 Enable or disable TLS on the link.
void Shutdown (bool getLock)
void syncStats (int *ctime=0)
int Terminate (const char *owner, int fdnum, unsigned int inst)
time_t timeCon () const
 Return the time the link was made active (i.e. time of connection).
int UseCnt () const
 Return link's reference count.
const char * verTLS ()
Public Member Functions inherited from XrdJob
 XrdJob (const char *desc="")
virtual ~XrdJob ()

Static Public Member Functions

static XrdLinkFind (int &curr, XrdLinkMatch *who=0)
static int getName (int &curr, char *bname, int blen, XrdLinkMatch *who=0)
static int Stats (char *buff, int blen, bool do_sync=0)

Public Attributes

char * ID
 Pointer to the client's link identity.
Public Attributes inherited from XrdJob
const char * Comment
XrdJobNextJob

Static Public Attributes

static bool sfOK = false

Protected Member Functions

 ~XrdLink ()
void DoIt ()
void ResetLink ()
int Wait4Data (int timeout)

Protected Attributes

char * HostName
unsigned int Instance
bool isBridged
bool isTLS
XrdLinkXeqlinkXQ
void * rsvd1 [3]
char rsvd2 [2]

Detailed Description

Definition at line 51 of file XrdLink.hh.

Member Typedef Documentation

◆ sfVec

Definition at line 390 of file XrdLink.hh.

Constructor & Destructor Documentation

◆ XrdLink()

XrdLink::XrdLink ( XrdLinkXeq & lxq)

Constructor

Parameters
lxqReference to the implementation.

Definition at line 111 of file XrdLink.cc.

111 : XrdJob("connection"), linkXQ(lxq),
112 HostName(0)
113{
114 memset(rsvd1, 0, sizeof(rsvd1));
115 memset(rsvd2, 0, sizeof(rsvd2));
116 ResetLink();
117}
XrdJob(const char *desc="")
Definition XrdJob.hh:51

References XrdJob::XrdJob(), HostName, linkXQ, ResetLink(), rsvd1, and rsvd2.

Referenced by XrdLinkXeq::XrdLinkXeq(), XrdLinkCtl::Alloc(), XrdLinkCtl::fd2link(), XrdLinkCtl::fd2link(), Find(), XrdLinkCtl::Find(), and Terminate().

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

◆ ~XrdLink()

XrdLink::~XrdLink ( )
inlineprotected

Definition at line 583 of file XrdLink.hh.

583{} // Is never deleted!

Member Function Documentation

◆ Activate()

bool XrdLink::Activate ( )

Activate a link by attaching it to a poller object.

Returns
True if activation succeeded and false otherwise.

Definition at line 131 of file XrdLink.cc.

132{
133
134// Attach this link to a poller
135//
136 return XrdPoll::Attach(linkXQ.PollInfo);
137}
static int Attach(XrdPollInfo &pInfo)
Definition XrdPoll.cc:144

References XrdPoll::Attach(), and linkXQ.

Referenced by XrdProtLoad::Process(), and XrdPoll__Attach().

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

◆ AddrInfo()

XrdNetAddrInfo * XrdLink::AddrInfo ( )

Obtain the address information for this link.

Returns
Pointer to the XrdAddrInfo object. The pointer is valid while the end-point is connected.

Definition at line 143 of file XrdLink.cc.

143{return linkXQ.AddrInfo();}

References linkXQ.

Referenced by XrdCmsLogin::Admit(), XrdCmsSecurity::Authenticate(), XrdCmsSecurity::Identify(), XrdHttpProtocol::Match(), and XrdXrootdProtocol::Match().

Here is the caller graph for this function:

◆ armBridge()

void XrdLink::armBridge ( )

Mark this link as an in-memory communications bridge (internal use only).

Definition at line 149 of file XrdLink.cc.

149{isBridged = 1;}

References isBridged.

◆ Backlog()

int XrdLink::Backlog ( )

Obtain the number of queued async requests.

Returns
The number of async requests queued.

Definition at line 155 of file XrdLink.cc.

155{return linkXQ.Backlog();}

References linkXQ.

◆ Client()

int XrdLink::Client ( char * buff,
int blen )

Get a copy of the client's name as known by the link.

Parameters
buffPointer to buffer to hold the name.
blenLength of the buffer.
Returns
!0 The length of the name in gthe buffer. =0 The name could not be returned.

Definition at line 161 of file XrdLink.cc.

161{return linkXQ.Client(nbuf, nbsz);}

References linkXQ.

◆ Close()

int XrdLink::Close ( bool defer = false)

Close the link.

Parameters
deferIf true, the link is made unaccessible but the link object not the file descriptor is released.
Returns
!0 An error occurred, the return value is the errno. =0 Action successfully completed.

Definition at line 167 of file XrdLink.cc.

167{return linkXQ.Close(defer);}

References linkXQ.

Referenced by XrdCmsSupervisor::Start().

Here is the caller graph for this function:

◆ DoIt()

void XrdLink::DoIt ( )
protectedvirtual

Implements XrdJob.

Reimplemented in XrdLinkXeq.

Definition at line 173 of file XrdLink.cc.

173{} // This is overridden by the implementation

Referenced by setProtocol().

Here is the caller graph for this function:

◆ Enable()

void XrdLink::Enable ( )

Enable the link to field interrupts.

Definition at line 179 of file XrdLink.cc.

180{
181 if (linkXQ.PollInfo.Poller) linkXQ.PollInfo.Poller->Enable(linkXQ.PollInfo);
182}

References linkXQ.

◆ FDnum()

int XrdLink::FDnum ( )

Get the associated file descriptor.

Returns
The file descriptor number.

Definition at line 188 of file XrdLink.cc.

189{
190 return linkXQ.PollInfo.FD;
191}

References linkXQ.

◆ Find()

XrdLink * XrdLink::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 pointer 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 197 of file XrdLink.cc.

198 {return XrdLinkCtl::Find(curr, who);}
static XrdLink * Find(int &curr, XrdLinkMatch *who=0)

References XrdLink(), and XrdLinkCtl::Find().

Here is the call graph for this function:

◆ getIOStats()

int XrdLink::getIOStats ( long long & inbytes,
long long & outbytes,
int & numstall,
int & numtardy )

Get I/O statistics.

Parameters
inbytesThe number of bytes read.
outbytesThe number of bytes written.
numstallThe number of times the link was rescheduled due to unavailability.
numtardyThe number of times the link was delayed due to unavailability.
Returns
The link's reference count. The parameters will hold the indicated statistic.

Definition at line 204 of file XrdLink.cc.

206 {return linkXQ.getIOStats(inbytes, outbytes,
207 numstall, numtardy);
208 }

References linkXQ.

◆ getName()

int XrdLink::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 218 of file XrdLink.cc.

219 {return XrdLinkCtl::getName(curr, nbuf, nbsz, who);}
static int getName(int &curr, char *bname, int blen, XrdLinkMatch *who=0)

References XrdLinkCtl::getName().

Here is the call graph for this function:

◆ getPeerCerts()

XrdTlsPeerCerts * XrdLink::getPeerCerts ( )

Get the x509 certificate information for this TLS enabled link.

Returns
A pointer to the XrdTlsCerts object holding verified certificates if such certificates exist. Otherwise a nil pointer is returned.
Note
Used by various protocols, so XrdTlsPeerCerts is a private header.

Definition at line 225 of file XrdLink.cc.

226{
227 return linkXQ.getPeerCerts();
228}

References linkXQ.

◆ getProtocol()

XrdProtocol * XrdLink::getProtocol ( )

Obtain current protocol object pointer.

Definition at line 234 of file XrdLink.cc.

234{return linkXQ.getProtocol();}

References linkXQ.

Referenced by XrdPoll::Finish().

Here is the caller graph for this function:

◆ hasBridge()

bool XrdLink::hasBridge ( ) const
inline

Determine if this link is a bridge.

Returns
true this link is a bridge.
false this link is a plain old link.

Definition at line 554 of file XrdLink.hh.

554{return isBridged;}

References isBridged.

◆ hasTLS()

bool XrdLink::hasTLS ( ) const
inline

Determine if this link is using TLS.

Returns
true this link is using TLS.
false this link not using TLS.

Definition at line 563 of file XrdLink.hh.

563{return isTLS;}

References isTLS.

◆ Hold()

void XrdLink::Hold ( bool lk)

Lock or unlock the mutex used for control operations.

Parameters
lkWhen true, a lock is obtained. Otherwise it is released. The caller is responsible for consistency.

Definition at line 240 of file XrdLink.cc.

241{
242 (lk ? linkXQ.LinkInfo.opMutex.Lock() : linkXQ.LinkInfo.opMutex.UnLock());
243}

References linkXQ.

Referenced by Terminate().

Here is the caller graph for this function:

◆ Host()

const char * XrdLink::Host ( ) const
inline

Get the fully qualified name of the endpoint.

Returns
Pointer to fully qualified host name. The contents are valid while the endpoint is connected.

Definition at line 204 of file XrdLink.hh.

204{return (const char *)HostName;}

References HostName.

Referenced by XrdCmsLogin::Admit(), XrdCmsSecurity::Authenticate(), XrdCmsSecurity::Identify(), XrdXrootdProtocol::Match(), XrdCmsNode::setName(), Terminate(), and XrdCmsManager::Verify().

Here is the caller graph for this function:

◆ Inst()

unsigned int XrdLink::Inst ( ) const
inline

Obtain the link's instance number.

Returns
The link's instance number.

Definition at line 218 of file XrdLink.hh.

218{return Instance;}

References Instance.

◆ isFlawed()

bool XrdLink::isFlawed ( ) const

Indicate whether or not the link has an outstanding error.

Returns
True the link has an outstanding error. the link has no outstanding error.

Definition at line 249 of file XrdLink.cc.

249{return linkXQ.LinkInfo.Etext != 0;}

References linkXQ.

Referenced by XrdProtLoad::Process().

Here is the caller graph for this function:

◆ isInstance()

bool XrdLink::isInstance ( unsigned int inst) const

Indicate whether or not this link is of a particular instance. only be used for display and not for security purposes.

Parameters
instthe expected instance number.
Returns
true the link matches the instance number. false the link differs the instance number.

Definition at line 255 of file XrdLink.cc.

256 {return Instance == inst && linkXQ.PollInfo.FD >= 0;}

References Instance, and linkXQ.

◆ Name()

const char * XrdLink::Name ( ) const

Obtain the domain trimmed name of the end-point. The returned value should only be used for display and not for security purposes.

Returns
Pointer to the name that remains valid during the link's lifetime.

Definition at line 262 of file XrdLink.cc.

262{return linkXQ.Name();}

References linkXQ.

Referenced by XrdCmsManager::Add(), and XrdCmsJob::Alloc().

Here is the caller graph for this function:

◆ NetAddr()

const XrdNetAddr * XrdLink::NetAddr ( ) const

Obtain the network address object for this link. The returned value is valid as long as the end-point is connected. Otherwise, it may change.

Returns
Pointer to the object and remains valid during the link's lifetime.

Definition at line 268 of file XrdLink.cc.

268{return linkXQ.NetAddr();}

References linkXQ.

Referenced by XrdCmsNode::isNode(), XrdHttpProtocol::Match(), and XrdCmsNode::setName().

Here is the caller graph for this function:

◆ Peek()

int XrdLink::Peek ( char * buff,
int blen,
int timeout = -1 )

Issue a socket peek() and return result (do not use for TLS connections).

Parameters
buffpointer to buffer to hold data.
blenlength of buffer.
timeoutmilliseconds to wait for data. A negative value waits forever.
Returns
>=0 buffer holds data equal to the returned value. < 0 an error or timeout occurred.

Definition at line 274 of file XrdLink.cc.

275{
276 if (isTLS) return linkXQ.TLS_Peek(Buff, Blen, timeout);
277 else return linkXQ.Peek (Buff, Blen, timeout);
278}

References isTLS, and linkXQ.

Referenced by XrdCmsProtocol::Match(), XrdHttpProtocol::Match(), and XrdXrootdProtocol::Match().

Here is the caller graph for this function:

◆ Recv() [1/3]

int XrdLink::Recv ( char * buff,
int blen )

Read data from a link. Note that this call blocks until some data is available. Use Recv() with a timeout to avoid blocking.

Parameters
buffpointer to buffer to hold data.
blenlength of buffer (implies the maximum bytes wanted).
Returns
>=0 buffer holds data equal to the returned value. < 0 an error occurred.

Definition at line 284 of file XrdLink.cc.

285{
286 if (isTLS) return linkXQ.TLS_Recv(Buff, Blen);
287 else return linkXQ.Recv (Buff, Blen);
288}

References isTLS, and linkXQ.

Referenced by XrdCmsTalk::Attend(), BIO_XrdLink_read(), and XrdXrootdProtocol::Match().

Here is the caller graph for this function:

◆ Recv() [2/3]

int XrdLink::Recv ( char * buff,
int blen,
int timeout )

Read data from a link. Note that this call either reads all the data wanted or no data if the passed timeout occurs before any data is present.

Parameters
buffpointer to buffer to hold data.
blenlength of buffer (implies the actual bytes wanted).
timeoutmilliseconds to wait for data. A negative value waits forever.
Returns
>=0 buffer holds data equal to the returned value. < 0 an error occurred. Note that a special error -ENOMSG is returned if poll() indicated data was present but no bytes were actually read.

Definition at line 292 of file XrdLink.cc.

293{
294 if (isTLS) return linkXQ.TLS_Recv(Buff, Blen, timeout);
295 else return linkXQ.Recv (Buff, Blen, timeout);
296}

References isTLS, and linkXQ.

◆ Recv() [3/3]

int XrdLink::Recv ( const struct iovec * iov,
int iocnt,
int timeout )

Read data on a link. Note that this call either reads all the data wanted or no data if the passed timeout occurs before any data is present.

Parameters
iovpointer to the message vector.
iocntnumber of iov elements in the vector.
timeoutmilliseconds to wait for data. A negative value waits forever.
Returns
>=0 number of bytes read. < 0 an error occurred or when -ETIMEDOUT is returned, no data arrived within the timeout period. -ENOMSG is returned when poll indicated data was present but 0 bytes were read.

Definition at line 300 of file XrdLink.cc.

301{
302// Execute the send
303//
304 if (isTLS) return linkXQ.TLS_Recv(iov, iocnt, timeout);
305 else return linkXQ.Recv (iov, iocnt, timeout);
306}

References isTLS, and linkXQ.

◆ RecvAll()

int XrdLink::RecvAll ( char * buff,
int blen,
int timeout = -1 )

Read data from a link. Note that this call reads as much data as it can or until the passed timeout has occurred.

Parameters
buffpointer to buffer to hold data.
blenlength of buffer (implies the maximum bytes wanted).
timeoutmilliseconds to wait for data. A negative value waits forever.
Returns
>=0 buffer holds data equal to the returned value. < 0 an error occurred or when -ETIMEDOUT is returned, no data arrived within the timeout period. -ENOMSG is returned when poll indicated data was present but 0 bytes were read.

Definition at line 312 of file XrdLink.cc.

313{
314 if (isTLS) return linkXQ.TLS_RecvAll(Buff, Blen, timeout);
315 else return linkXQ.RecvAll (Buff, Blen, timeout);
316}

References isTLS, and linkXQ.

Referenced by XrdCmsLogin::Login().

Here is the caller graph for this function:

◆ Register()

bool XrdLink::Register ( const char * hName)

Register a host name with this IP address. This is not MT-safe!

Parameters
hNamepointer to a true host name which should be fully qualified. One of the IP addresses registered to this name must match the IP address associated with this object.
Returns
True: Specified name is now associated with this link. False: Nothing changed, registration could not be verified.

Definition at line 322 of file XrdLink.cc.

323{
324 return linkXQ.Register(hName);
325}

References linkXQ.

◆ ResetLink()

void XrdLink::ResetLink ( )
protected

Definition at line 119 of file XrdLink.cc.

120{
121 if (HostName) {free(HostName); HostName = 0;}
122 Instance = 0;
123 isBridged= false;
124 isTLS = false;
125}

References HostName, Instance, isBridged, and isTLS.

Referenced by XrdLink(), and XrdLinkXeq::Reset().

Here is the caller graph for this function:

◆ Send() [1/3]

int XrdLink::Send ( const char * buff,
int blen )

Send data on a link. This calls may block unless the socket was marked nonblocking. If a block would occur, the data is copied for later sending.

Parameters
buffpointer to buffer to send.
blenlength of buffer.
Returns
>=0 number of bytes sent. < 0 an error or occurred.

Definition at line 331 of file XrdLink.cc.

332{
333 if (isTLS) return linkXQ.TLS_Send(Buff, Blen);
334 else return linkXQ.Send (Buff, Blen);
335}

References isTLS, and linkXQ.

Referenced by BIO_XrdLink_write(), XrdCmsTalk::Complain(), XrdXrootdProtocol::Match(), XrdCmsNode::Report_Usage(), XrdCmsTalk::Request(), XrdCmsTalk::Respond(), and XrdCmsState::sendState().

Here is the caller graph for this function:

◆ Send() [2/3]

int XrdLink::Send ( const sfVec * sdP,
int sdn )

Definition at line 353 of file XrdLink.cc.

354{
355// Make sure we have valid vector count
356//
357 if (sfN < 1 || sfN > XrdOucSFVec::sfMax)
358 {Log.Emsg("Link", E2BIG, "send file to", ID);
359 return -1;
360 }
361
362// Do the send
363//
364 if (isTLS) return linkXQ.TLS_Send(sfP, sfN);
365 else return linkXQ.Send (sfP, sfN);
366}
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
XrdSysError Log
Definition XrdConfig.cc:112

References ID, isTLS, linkXQ, XrdGlobal::Log, and XrdOucSFVec::sfMax.

◆ Send() [3/3]

int XrdLink::Send ( const struct iovec * iov,
int iocnt,
int bytes = 0 )

Send data on a link. This calls may block unless the socket was marked nonblocking. If a block would occur, the data is copied for later sending.

Parameters
iovpointer to the message vector.
iocntnumber of iov elements in the vector.
bytesthe sum of the sizes in the vector.
Returns
>=0 number of bytes sent. < 0 an error occurred.

Definition at line 339 of file XrdLink.cc.

340{
341// Allways make sure we have a total byte count
342//
343 if (!bytes) for (int i = 0; i < iocnt; i++) bytes += iov[i].iov_len;
344
345// Execute the send
346//
347 if (isTLS) return linkXQ.TLS_Send(iov, iocnt, bytes);
348 else return linkXQ.Send (iov, iocnt, bytes);
349}

References isTLS, and linkXQ.

◆ Serialize()

void XrdLink::Serialize ( )

Wait for all outstanding requests to be completed on the link.

Definition at line 372 of file XrdLink.cc.

373{
374
375// This is meant to make sure that no protocol objects are refering to this
376// link so that we can safely run in pseudo single thread mode for critical
377// functions.
378//
379 linkXQ.LinkInfo.opMutex.Lock();
380 if (linkXQ.LinkInfo.InUse <= 1) linkXQ.LinkInfo.opMutex.UnLock();
381 else {linkXQ.LinkInfo.doPost++;
382 linkXQ.LinkInfo.opMutex.UnLock();
383 TRACEI(DEBUG, "Waiting for link serialization; use="
384 <<linkXQ.LinkInfo.InUse);
385 linkXQ.LinkInfo.IOSemaphore.Wait();
386 }
387}
#define DEBUG(x)
#define TRACEI(act, x)
Definition XrdTrace.hh:66

References DEBUG, linkXQ, and TRACEI.

Referenced by XrdLinkXeq::Close(), and XrdCmsProtocol::Process().

Here is the caller graph for this function:

◆ setEtext()

int XrdLink::setEtext ( const char * text)

Set an error indication on he link.

Parameters
texta message describing the error.
Returns
=0 message set, the link is considered in error. -1 the message pointer was nil.

Definition at line 393 of file XrdLink.cc.

394{
395 linkXQ.LinkInfo.opMutex.Lock();
396 if (linkXQ.LinkInfo.Etext) free(linkXQ.LinkInfo.Etext);
397 linkXQ.LinkInfo.Etext = (text ? strdup(text) : 0);
398 linkXQ.LinkInfo.opMutex.UnLock();
399 return -1;
400}

References linkXQ.

Referenced by XrdPoll::Finish(), XrdCmsProtocol::Match(), XrdHttpProtocol::Match(), XrdXrootdProtocol::Match(), XrdCmsProtocol::Process(), and XrdProtLoad::Process().

Here is the caller graph for this function:

◆ setID()

void XrdLink::setID ( const char * userid,
int procid )

Set the client's link identity.

Parameters
useridpointer to the client's username.
procidthe client's process id (i.e. pid).

Definition at line 406 of file XrdLink.cc.

407 {linkXQ.setID(userid, procid);}

References linkXQ.

Referenced by XrdCmsManager::Add(), and XrdCmsSecurity::Authenticate().

Here is the caller graph for this function:

◆ setLocation()

void XrdLink::setLocation ( XrdNetAddrInfo::LocInfo & loc)

Set the client's location.

Parameters
locreference to the location information.

Definition at line 419 of file XrdLink.cc.

420 {linkXQ.setLocation(loc);}

References linkXQ.

◆ setNB()

bool XrdLink::setNB ( )

Set the link to be non-blocking.

Returns
true mode has been set.
false mode is not supported for this operating system.

Definition at line 413 of file XrdLink.cc.

413{return linkXQ.setNB();}

References linkXQ.

◆ setProtName()

void XrdLink::setProtName ( const char * name)

Set the link's protocol name.

Parameters
namename of he protocol being used. The storage must be valid for the duration of the program.

Definition at line 443 of file XrdLink.cc.

444{
445
446// Ask the mplementation to set the name.
447//
448 linkXQ.setProtName(name);
449}

References linkXQ.

Referenced by mainAdmin(), and XrdProtLoad::Process().

Here is the caller graph for this function:

◆ setProtocol()

XrdProtocol * XrdLink::setProtocol ( XrdProtocol * pp,
bool runit = false,
bool push = false )

Set the link's protocol.

Parameters
pppointer to the protocol object.
runitif true, starts running the protocol.
pushif true, pushes current protocol to be the alternate one.
Returns
pointer to the previous protocol (may be nil).

Definition at line 426 of file XrdLink.cc.

427{
428
429// Ask the mplementation to set or push the protocol
430//
431 XrdProtocol *op = linkXQ.setProtocol(pp, push);
432
433// Run the protocol if so requested
434//
435 if (runit) DoIt();
436 return op;
437}

References DoIt(), and linkXQ.

Referenced by XrdMain::DoIt(), XrdPoll::Finish(), mainAdmin(), XrdProtLoad::Process(), and XrdCmsSupervisor::Start().

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

◆ setRef()

void XrdLink::setRef ( int cnt)

Set the link's parallel usage count.

Parameters
cntshould be 1 to increased the count and -1 to decrease it.

Definition at line 455 of file XrdLink.cc.

456{
457 linkXQ.LinkInfo.opMutex.Lock();
458 TRACEI(DEBUG,"Setting FD "<<linkXQ.LinkInfo.FD <<" ref to "
459 <<linkXQ.LinkInfo.InUse <<'+'
460 <<use <<" post=" <<linkXQ.LinkInfo.doPost);
461 linkXQ.LinkInfo.InUse += use;
462
463 if (!linkXQ.LinkInfo.InUse)
464 {linkXQ.LinkInfo.InUse = 1; linkXQ.LinkInfo.opMutex.UnLock();
465 Log.Emsg("Link", "Zero use count for", ID);
466 }
467 else if (linkXQ.LinkInfo.InUse == 1 && linkXQ.LinkInfo.doPost)
468 {while(linkXQ.LinkInfo.doPost)
469 {linkXQ.LinkInfo.IOSemaphore.Post();
470 TRACEI(CONN, "setRef posted link");
471 linkXQ.LinkInfo.doPost--;
472 }
473 linkXQ.LinkInfo.opMutex.UnLock();
474 }
475 else if (linkXQ.LinkInfo.InUse < 0)
476 {linkXQ.LinkInfo.InUse = 1;
477 linkXQ.LinkInfo.opMutex.UnLock();
478 Log.Emsg("Link", "Negative use count for", ID);
479 }
480 else linkXQ.LinkInfo.opMutex.UnLock();
481}

References DEBUG, ID, linkXQ, XrdGlobal::Log, and TRACEI.

Referenced by XrdCmsJob::Alloc(), and XrdLinkCtl::Find().

Here is the caller graph for this function:

◆ setTLS()

bool XrdLink::setTLS ( bool enable,
XrdTlsContext * ctx = 0 )

Enable or disable TLS on the link.

Parameters
enableif true, TLS is enabled if not already enabled. Otherwise, TLS is disabled and the TLS logical connection torn down. statistics may be contradictory as they are collected async.
ctxThe context to use when enabling TLS. When nil, the default context is used.
Returns
True if successful, false otherwise.

Definition at line 487 of file XrdLink.cc.

488{
489// If we are already in a compatible mode, we are done
490//
491 if (isTLS == enable) return true;
492
493 return linkXQ.setTLS(enable, ctx);
494}

References isTLS, and linkXQ.

Referenced by XrdProtLoad::Process().

Here is the caller graph for this function:

◆ Shutdown()

void XrdLink::Shutdown ( bool getLock)

Shutdown the link but otherwise keep it intact.

Parameters
getLockif true, the operation is performed under a lock.

Definition at line 500 of file XrdLink.cc.

500{linkXQ.Shutdown(getLock);}

References linkXQ.

◆ Stats()

int XrdLink::Stats ( char * buff,
int blen,
bool do_sync = 0 )
static

Obtain link statistics.

Parameters
buffpointer to the buffer for the xml statistics.
blenlength of the buffer.
do_syncif true, the statistics self-consistent. Otherwise, the statistics may be contradictory as they are collected async.
Returns
number of bytes placed in the buffer excluding the null byte.

Definition at line 506 of file XrdLink.cc.

507 {return XrdLinkXeq::Stats(buff, blen, do_sync);}
static int Stats(char *buff, int blen, bool do_sync=false)

References XrdLinkXeq::Stats().

Here is the call graph for this function:

◆ syncStats()

void XrdLink::syncStats ( int * ctime = 0)

Add all local statistics to the global counters.

Parameters
ctimeif not nil, return the total connect time in seconds.

Definition at line 513 of file XrdLink.cc.

513{linkXQ.syncStats(ctime);}

References linkXQ.

◆ Terminate()

int XrdLink::Terminate ( const char * owner,
int fdnum,
unsigned int inst )

Terminate a connection.

Parameters
ownerpointer to the link ID representing a client who made the connection to be terminated. If nil then this is a request for the link to terminate another link, if possible.
fdnumthe file descriptor number of the link to be terminated.
instthe link's instance number.
Returns
>0 caller should wait this number of seconds and try again.
=0 link terminated.
<0 link could not be terminated: -EACCES the links was not created by the passed owner. -EPIPE link already being terminated. -ESRCH fdnum does not refer to a link. -ETIME unsuccessful, too many tries.

Definition at line 519 of file XrdLink.cc.

520{
521
522// Find the correspodning link and check for self-termination. Otherwise, if
523// the target link is owned by the owner then ask the link to terminate itself.
524//
525 if (!owner)
526 {XrdLink *lp;
527 char *cp;
528 if (!(lp = XrdLinkCtl::fd2link(fdnum, inst))) return -ESRCH;
529 if (lp == this) return 0;
530 lp->Hold(true);
531 if (!(cp = index(ID, ':')) || strncmp(lp->ID, ID, cp-ID)
532 || strcmp(HostName, lp->Host()))
533 {lp->Hold(false);
534 return -EACCES;
535 }
536 int rc = lp->Terminate(ID, fdnum, inst);
537 lp->Hold(false);
538 return rc;
539 }
540
541// At this pint, we are excuting in the context of the target link.
542// If this link is now dead, simply ignore the request. Typically, this
543// indicates a race condition that the server won.
544//
545 if ( linkXQ.PollInfo.FD != fdnum || Instance != inst
546 || !linkXQ.PollInfo.Poller || !linkXQ.getProtocol()) return -EPIPE;
547
548// Check if we have too many tries here
549//
550 int wTime, killTries;
551 killTries = linkXQ.LinkInfo.KillCnt & KillMsk;
552 if (killTries > KillMax) return -ETIME;
553
554// Wait time increases as we have more unsuccessful kills. Update numbers.
555//
556 wTime = killTries++;
557 linkXQ.LinkInfo.KillCnt = killTries | KillXwt;
558
559// Make sure we can disable this link. If not, then force the caller to wait
560// a tad more than the read timeout interval.
561//
562 if (!linkXQ.PollInfo.isEnabled || linkXQ.LinkInfo.InUse > 1
563 || linkXQ.LinkInfo.KillcvP)
564 {wTime = wTime*2+XrdLinkCtl::waitKill;
565 return (wTime > 60 ? 60: wTime);
566 }
567
568// Set the pointer to our condvar. We are holding the opMutex to prevent a race.
569//
570 XrdSysCondVar killDone(0);
571 linkXQ.LinkInfo.KillcvP = &killDone;
572 killDone.Lock();
573
574// We can now disable the link and schedule a close
575//
576 char buff[1024];
577 snprintf(buff, sizeof(buff), "ended by %s", owner);
578 buff[sizeof(buff)-1] = '\0';
579 linkXQ.PollInfo.Poller->Disable(linkXQ.PollInfo, buff);
580 linkXQ.LinkInfo.opMutex.UnLock();
581
582// Now wait for the link to shutdown. This avoids lock problems.
583//
584 if (killDone.Wait(int(XrdLinkCtl::killWait))) wTime += XrdLinkCtl::killWait;
585 else wTime = -EPIPE;
586 killDone.UnLock();
587
588// Reobtain the opmutex so that we can zero out the pointer the condvar pntr
589// This is really stupid code but because we don't have a way of associating
590// an arbitrary mutex with a condvar. But since this code is rarely executed
591// the ugliness is sort of tolerable.
592//
593 linkXQ.LinkInfo.opMutex.Lock();
594 linkXQ.LinkInfo.KillcvP = 0;
595 linkXQ.LinkInfo.opMutex.UnLock();
596
597// Do some tracing
598//
599 TRACEI(DEBUG,"Terminate " << (wTime <= 0 ? "complete ":"timeout ") <<wTime);
600 return wTime;
601}
static short waitKill
static XrdLink * fd2link(int fd)
Definition XrdLinkCtl.hh:72
static short killWait
Link destruction control constants.

References XrdLink(), DEBUG, ETIME, XrdLinkCtl::fd2link(), Hold(), Host(), HostName, ID, Instance, XrdLinkCtl::killWait, linkXQ, XrdSysCondVar::Lock(), Terminate(), TRACEI, XrdSysCondVar::UnLock(), XrdSysCondVar::Wait(), and XrdLinkCtl::waitKill.

Referenced by Terminate().

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

◆ timeCon()

time_t XrdLink::timeCon ( ) const

Return the time the link was made active (i.e. time of connection).

Definition at line 607 of file XrdLink.cc.

607{return linkXQ.LinkInfo.conTime;}

References linkXQ.

◆ UseCnt()

int XrdLink::UseCnt ( ) const

Return link's reference count.

Definition at line 613 of file XrdLink.cc.

613{return linkXQ.LinkInfo.InUse;}

References linkXQ.

◆ verTLS()

const char * XrdLink::verTLS ( )

Return TLS protocol version being used.

Returns
The TLS protocol version number. If the link is not using TLS, a null string is returned;

Definition at line 619 of file XrdLink.cc.

620{
621 return (isTLS ? linkXQ.verTLS() : "");
622}

References isTLS, and linkXQ.

◆ Wait4Data()

int XrdLink::Wait4Data ( int timeout)
protected

Definition at line 628 of file XrdLink.cc.

629{
630 struct pollfd polltab = {linkXQ.PollInfo.FD, POLLIN|POLLRDNORM, 0};
631 int retc;
632
633// Issue poll and do preliminary check
634//
635 do {retc = poll(&polltab, 1, timeout);} while(retc < 0 && errno == EINTR);
636 if (retc != 1)
637 {if (retc == 0) return 0;
638 Log.Emsg("Link", -errno, "poll", ID);
639 return -1;
640 }
641
642// Verify it is safe to read now
643//
644 if (!(polltab.revents & (POLLIN|POLLRDNORM)))
645 {Log.Emsg("Link", XrdPoll::Poll2Text(polltab.revents), "polling", ID);
646 return -1;
647 }
648 return 1;
649}
static char * Poll2Text(short events)
Definition XrdPoll.cc:272

References ID, linkXQ, XrdGlobal::Log, and XrdPoll::Poll2Text().

Referenced by XrdLinkXeq::TLS_Peek(), XrdLinkXeq::TLS_Recv(), and XrdLinkXeq::TLS_RecvAll().

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

Member Data Documentation

◆ HostName

char* XrdLink::HostName
protected

◆ ID

◆ Instance

unsigned int XrdLink::Instance
protected

◆ isBridged

bool XrdLink::isBridged
protected

Definition at line 593 of file XrdLink.hh.

Referenced by armBridge(), hasBridge(), and ResetLink().

◆ isTLS

◆ linkXQ

◆ rsvd1

void* XrdLink::rsvd1[3]
protected

Definition at line 589 of file XrdLink.hh.

Referenced by XrdLink().

◆ rsvd2

char XrdLink::rsvd2[2]
protected

Definition at line 595 of file XrdLink.hh.

Referenced by XrdLink().

◆ sfOK

bool XrdLink::sfOK = false
static

Send data on a link using sendfile(). This call always blocks until all data is sent. It should only be called if sfOK is true (see below).

Parameters
sdPpointer to the sendfile vector.
sdnnumber of elements in the vector.
Returns
>=0 number of bytes sent. < 0 an error occurred.

Definition at line 388 of file XrdLink.hh.

Referenced by XrdXrootdProtocol::Configure(), and XrdLinkXeq::Send().


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