XRootD
XrdXrootdGSReal Class Reference

#include <XrdXrootdGSReal.hh>

+ Inheritance diagram for XrdXrootdGSReal:
+ Collaboration diagram for XrdXrootdGSReal:

Classes

struct  GSParms
 

Public Member Functions

 XrdXrootdGSReal (const GSParms &gsParms, bool &aOK)
 
 ~XrdXrootdGSReal ()
 Destructor. Normally, this object is never deleted. More...
 
void DoIt ()
 
void Flush ()
 
uint32_t GetDictID (const char *text, bool isPath=false)
 
bool HasHdr ()
 
void Ident ()
 
bool Insert (const char *data, int dlen)
 
bool Insert (int dlen)
 
char * Reserve (int dlen)
 
int SetAutoFlush (int afsec)
 
int Space ()
 
- Public Member Functions inherited from XrdJob
 XrdJob (const char *desc="")
 
virtual ~XrdJob ()
 
- Public Member Functions inherited from XrdXrootdGStream
 XrdXrootdGStream (XrdXrootdGSReal &gsRef)
 
void Flush ()
 
uint32_t GetDictID (const char *text, bool isPath=false)
 
bool HasHdr ()
 
bool Insert (const char *data, int dlen)
 
bool Insert (int dlen)
 
char * Reserve (int dlen)
 
int SetAutoFlush (int afsec)
 
int Space ()
 
- Public Member Functions inherited from XrdXrootdMonitor::Hello
 Hello (const char *dest, char mode)
 
virtual ~Hello ()
 

Static Public Attributes

static const int fmtBin = 1
 Do not include info. More...
 
static const int fmtCgi = 2
 Format as binary info. More...
 
static const int fmtJson = 3
 Format as CGI info. More...
 
static const int fmtNone = 0
 
static const int hdrFull = 5
 Include site, host, port, inst, pgm. More...
 
static const int hdrHost = 3
 Include site, host. More...
 
static const int hdrInst = 4
 Include site, host, port, inst. More...
 
static const int hdrNone = 0
 Format as JSON info. More...
 
static const int hdrNorm = 1
 Include standard header. More...
 
static const int hdrSite = 2
 Include site. More...
 
static const int optNoID = 0x01
 Don't send ident records. More...
 
- Static Public Attributes inherited from XrdXrootdGStream
static const int MaxDataLen = 65280
 The larest amount of data that can be inserted in a single call to GStream. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from XrdXrootdMonitor::Hello
static bool Hail ()
 
- Public Attributes inherited from XrdJob
const char * Comment
 
XrdJobNextJob
 
- Protected Member Functions inherited from XrdXrootdGStream
 ~XrdXrootdGStream ()
 Destructor. This stream should never be directly deleted. More...
 

Detailed Description

Definition at line 48 of file XrdXrootdGSReal.hh.


Class Documentation

◆ XrdXrootdGSReal::GSParms

struct XrdXrootdGSReal::GSParms

Definition at line 95 of file XrdXrootdGSReal.hh.

+ Collaboration diagram for XrdXrootdGSReal::GSParms:
Class Members
const char * dest Destination for records.
int flsT Flush time (default from monitor)
char Fmt How to handle the records.
char Hdr Hdr type.
int maxL Maximum packet length (default 32K)
int Mode the monitor type for send routing.
char Opt Options.
const char * pin the plugin name.
kXR_char Type the specific G-Stream identifier

Constructor & Destructor Documentation

◆ XrdXrootdGSReal()

XrdXrootdGSReal::XrdXrootdGSReal ( const GSParms gsParms,
bool &  aOK 
)

Definition at line 64 of file XrdXrootdGSReal.cc.

66  : XrdJob("GStream"), XrdXrootdGStream(*this),
67  Hello(gsParms.Opt & XrdXrootdGSReal::optNoID
68  || gsParms.Hdr == XrdXrootdGSReal::hdrNone
69  ? 0 : gsParms.dest, gsParms.Fmt),
70  pSeq(0), pSeqID(0), pSeqDID(0), binHdr(0),
71  isCGI(false)
72 {
73  static const int minSZ = 1024;
74  static const int dflSZ = 1024*32;
75  static const int maxSZ = 1024*64;
76  int flsT, maxL, hdrLen;
77 
78 // Do common initialization
79 //
80  memset(&hInfo, 0, sizeof(hInfo));
81  aOK = true;
82 
83 // Compute the correct size of the UDP buffer
84 //
85  if (gsParms.maxL <= 0) maxL = dflSZ;
86  else if (gsParms.maxL < minSZ) maxL = minSZ;
87  else if (gsParms.maxL > maxSZ) maxL = maxSZ;
88  else maxL = gsParms.maxL;
89  maxL &= ~7; // Doubleword lengths
90 
91 // Allocate the UDP buffer. Try to keep the data within a single page.
92 //
93  int align;
94  if (maxL >= getpagesize()) align = getpagesize();
95  else if (maxL >= 2048) align = 2048;
96  else if (maxL >= 1024) align = 1024;
97  else align = sizeof(void*);
98 
99  if (posix_memalign((void **)&udpBuffer, align, maxL)) {aOK = false; return;}
100 
101 // Setup the header as needed
102 //
103  if (gsParms.Hdr == hdrNone)
104  {hdrLen = 0;
105  binHdr = 0;
106  dictHdr = idntHdr0 = idntHdr1 = 0;
107  } else {
108  switch(gsParms.Fmt)
109  {case fmtBin: hdrLen = hdrBIN(gsParms);
110  break;
111  case fmtCgi: hdrLen = hdrCGI(gsParms, udpBuffer, maxL);
112  break;
113  case fmtJson: hdrLen = hdrJSN(gsParms, udpBuffer, maxL);
114  break;
115  default: hdrLen = 0;
116  }
117  if (gsParms.Opt & optNoID)
118  {if (idntHdr0) {free(idntHdr0); idntHdr0 = 0;}
119  if (idntHdr1) {free(idntHdr1); idntHdr1 = 0;}
120  }
121  }
122 
123 // Setup buffer pointers
124 //
125  udpBFirst = udpBNext = udpBuffer + hdrLen;
126  udpBEnd = udpBuffer + maxL - 1;
127 
128  tBeg = tEnd = afTime = 0;
129 
130 // Initialize remaining variables
131 //
132  monType = gsParms.Mode;
133  rsvbytes = 0;
134 
135 // If we have a specific end-point, then create a network relay to it
136 //
137  if (gsParms.dest) udpDest = new XrdNetMsg(eDest, gsParms.dest, &aOK);
138  else udpDest = 0;
139 
140 // Setup autoflush (a negative value uses the default)
141 //
142  if (gsParms.flsT < 0) flsT = XrdXrootdMonitor::Flushing();
143  else flsT = gsParms.flsT;
144  afRunning = false;
145  SetAutoFlush(flsT);
146 
147 // Construct our user name as in <gNamePI>.0:0@<myhost>
148 //
149  char idBuff[1024];
150  snprintf(idBuff, sizeof(idBuff), "%s.0:0@%s", gsParms.pin, monHost);
151 
152 // Register ourselves
153 //
154  gMon.Register(idBuff, monHost, "xroot");
155 }
XrdJob(const char *desc="")
Definition: XrdJob.hh:51
static const int hdrNone
Format as JSON info.
int SetAutoFlush(int afsec)
static const int fmtBin
Do not include info.
static const int fmtJson
Format as CGI info.
static const int optNoID
Don't send ident records.
static const int fmtCgi
Format as binary info.
XrdXrootdGStream(XrdXrootdGSReal &gsRef)
Hello(const char *dest, char mode)
void Register(const char *Uname, const char *Hname, const char *Pname, unsigned int xSID=0)
static int Flushing()
XrdSysError * eDest

References XrdXrootdGSReal::GSParms::dest, XrdXrootdMonInfo::eDest, XrdXrootdGSReal::GSParms::flsT, XrdXrootdMonitor::Flushing(), XrdXrootdGSReal::GSParms::Fmt, fmtBin, fmtCgi, fmtJson, XrdXrootdGSReal::GSParms::Hdr, hdrNone, XrdXrootdGSReal::GSParms::maxL, XrdXrootdGSReal::GSParms::Mode, XrdXrootdMonInfo::monHost, XrdXrootdGSReal::GSParms::Opt, optNoID, XrdXrootdGSReal::GSParms::pin, XrdXrootdMonitor::User::Register(), and SetAutoFlush().

+ Here is the call graph for this function:

◆ ~XrdXrootdGSReal()

XrdXrootdGSReal::~XrdXrootdGSReal ( )
inline

Destructor. Normally, this object is never deleted.

Definition at line 112 of file XrdXrootdGSReal.hh.

112 {}

Member Function Documentation

◆ DoIt()

void XrdXrootdGSReal::DoIt ( )
virtual

Implements XrdJob.

Definition at line 173 of file XrdXrootdGSReal.cc.

174 {
175  XrdSysMutexHelper gHelp(gMutex);
176 
177 // Check if we need to do anything here
178 //
179  afRunning = false;
180  if (afTime)
181  {if (tBeg && time(0)-tBeg >= afTime) Expel(0);
182  AutoFlush();
183  }
184 }

◆ Flush()

void XrdXrootdGSReal::Flush ( )

Definition at line 241 of file XrdXrootdGSReal.cc.

242 {
243  XrdSysMutexHelper gHelp(gMutex);
244  Expel(0);
245 }

Referenced by XrdXrootdGStream::Flush().

+ Here is the caller graph for this function:

◆ GetDictID()

uint32_t XrdXrootdGSReal::GetDictID ( const char *  text,
bool  isPath = false 
)

Definition at line 251 of file XrdXrootdGSReal.cc.

252 {
253 // If this is binary encoded, the record the mapping and return it
254 //
255  if (binHdr) return (isPath ? gMon.MapPath(text) : gMon.MapInfo(text));
256 
257 // If there are no headers then we can't produce this record
258 //
259  uint32_t psq, did = XrdXrootdMonitor::GetDictID(true);
260  if (!dictHdr) return htonl(did);
261 
262 // We need to do some additional work to generate non-binary headers here
263 //
264  struct iovec iov[3];
265  char dit = (isPath ? XROOTD_MON_MAPPATH : XROOTD_MON_MAPINFO);
266  char buff[1024];
267 
268 // Generate a new packet sequence number
269 //
270  gMutex.Lock();
271  if (pSeqDID >= 999) pSeqDID = 0;
272  else pSeqDID++;
273  psq = pSeqDID;
274  gMutex.UnLock();
275 
276 // Generate the packet
277 //
278  iov[0].iov_base = buff;
279  iov[0].iov_len = snprintf(buff, sizeof(buff), dictHdr, dit, psq, did);
280  iov[1].iov_base = (void *)text;
281  iov[1].iov_len = strlen(text);
282  iov[2].iov_base = (void *)"\"}";
283  iov[2].iov_len = 3;
284 
285 // Now send it off
286 //
287  udpDest->Send(iov, (*dictHdr == '{' ? 3 : 2));
288  return htonl(did);
289 }
const kXR_char XROOTD_MON_MAPINFO
const kXR_char XROOTD_MON_MAPPATH
int Send(const char *buff, int blen=0, const char *dest=0, int tmo=-1)
Definition: XrdNetMsg.cc:70
kXR_unt32 MapInfo(const char *Info)
kXR_unt32 MapPath(const char *Path)
static kXR_unt32 GetDictID(bool hbo=false)

References XrdXrootdMonitor::GetDictID(), XrdSysMutex::Lock(), XrdXrootdMonitor::User::MapInfo(), XrdXrootdMonitor::User::MapPath(), XrdNetMsg::Send(), XrdSysMutex::UnLock(), XROOTD_MON_MAPINFO, and XROOTD_MON_MAPPATH.

Referenced by XrdXrootdGStream::GetDictID().

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

◆ HasHdr()

bool XrdXrootdGSReal::HasHdr ( )

Definition at line 295 of file XrdXrootdGSReal.cc.

296 {
297  return binHdr != 0 || dictHdr != 0;
298 }

Referenced by XrdXrootdGStream::HasHdr().

+ Here is the caller graph for this function:

◆ Ident()

void XrdXrootdGSReal::Ident ( )
virtual

Reimplemented from XrdXrootdMonitor::Hello.

Definition at line 455 of file XrdXrootdGSReal.cc.

456 {
457  struct iovec iov[2];
458  char buff[40];
459  uint32_t psq;
460 
461 // If identification suppressed, then just return
462 //
463  if (!idntHdr0 || !udpDest) return;
464 
465 // Generate a new packet sequence number
466 //
467  gMutex.Lock();
468  if (pSeqID >= 999) pSeqID = 0;
469  else pSeqID++;
470  psq = pSeqID;
471  gMutex.UnLock();
472 
473 // Create header and iovec to send the header
474 //
475  iov[0].iov_base = buff;
476  iov[0].iov_len = snprintf(buff, sizeof(buff), idntHdr0, psq);
477  iov[1].iov_base = idntHdr1;
478  iov[1].iov_len = idntHsz1;
479  udpDest->Send(iov, 2);
480 }

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

+ Here is the call graph for this function:

◆ Insert() [1/2]

bool XrdXrootdGSReal::Insert ( const char *  data,
int  dlen 
)

Definition at line 486 of file XrdXrootdGSReal.cc.

487 {
488 
489 // Validate the length and message
490 //
491  if (dlen < 8 || dlen > XrdXrootdGStream::MaxDataLen
492  || !data || data[dlen-1]) return false;
493 
494 // Reserve the storage and copy the message. It always will end with a newline
495 //
496  gMutex.Lock();
497  Expel(dlen);
498  memcpy(udpBNext, data, dlen-1);
499  udpBNext[dlen-1] = '\n';
500 
501 // Timestamp the record and aAdjust buffer pointers
502 //
503  tEnd = time(0);
504  if (udpBNext == udpBFirst) tBeg = tEnd;
505  udpBNext += dlen;
506 
507 // All done
508 //
509  gMutex.UnLock();
510  return true;
511 }
static const int MaxDataLen
The larest amount of data that can be inserted in a single call to GStream.

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

Referenced by XrdXrootdGStream::Insert().

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

◆ Insert() [2/2]

bool XrdXrootdGSReal::Insert ( int  dlen)

Definition at line 515 of file XrdXrootdGSReal.cc.

516 {
517  XrdSysMutexHelper gHelp(gMutex);
518 
519 // Make sure space is reserved
520 //
521  if (!rsvbytes) return false;
522 
523 // We are now sure that the recursive lock is held twice by this thread. So,
524 // make it a unitary lock so it gets fully unlocked upon rturn.
525 //
526  gMutex.UnLock();
527 
528 // Check for cancellation
529 //
530  if (!dlen)
531  {rsvbytes = 0;
532  return true;
533  }
534 
535 // Length, it must >= 8 and <= reserved amount and the data must end with a 0.
536 //
537  if (dlen > rsvbytes || dlen < 8 || *(udpBNext+dlen-1))
538  {rsvbytes = 0;
539  return false;
540  }
541 
542 // Adjust the buffer space and time stamp the record
543 //
544  tEnd = time(0);
545  if (udpBNext == udpBFirst) tBeg = tEnd;
546  udpBNext += dlen;
547  *(udpBNext-1) = '\n';
548  rsvbytes = 0;
549 
550 // All done
551 
552  return true;
553 }

References XrdSysMutex::UnLock().

+ Here is the call graph for this function:

◆ Reserve()

char * XrdXrootdGSReal::Reserve ( int  dlen)

Definition at line 559 of file XrdXrootdGSReal.cc.

560 {
561 // Validate the length
562 //
563  if (dlen < 8 || dlen > XrdXrootdGStream::MaxDataLen) return 0;
564 
565 // Make sure there is no reserve outstanding
566 //
567  gMutex.Lock();
568  if (rsvbytes)
569  {gMutex.UnLock();
570  return 0;
571  }
572 
573 // Return the allocated the space but keep the lock until Insert() is called.
574 //
575  rsvbytes = dlen;
576  Expel(dlen);
577  return udpBNext;
578 }

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

Referenced by XrdXrootdGStream::Reserve().

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

◆ SetAutoFlush()

int XrdXrootdGSReal::SetAutoFlush ( int  afsec)

Definition at line 584 of file XrdXrootdGSReal.cc.

585 {
586  XrdSysMutexHelper gHelp(gMutex);
587 
588 // Save the current settting and establish the new one and relaunch
589 //
590  int afNow = afTime;
591  afTime = (afsec > 0 ? afsec : 0);
592  AutoFlush();
593 
594 // All done
595 //
596  return afNow;
597 }

Referenced by XrdXrootdGSReal(), and XrdXrootdGStream::SetAutoFlush().

+ Here is the caller graph for this function:

◆ Space()

int XrdXrootdGSReal::Space ( )

Definition at line 603 of file XrdXrootdGSReal.cc.

604 {
605  XrdSysMutexHelper gHelp(gMutex);
606 
607 // Return amount of space left
608 //
609  return udpBEnd - udpBNext;
610 }

Referenced by XrdXrootdGStream::Space().

+ Here is the caller graph for this function:

Member Data Documentation

◆ fmtBin

const int XrdXrootdGSReal::fmtBin = 1
static

Do not include info.

Definition at line 82 of file XrdXrootdGSReal.hh.

Referenced by XrdXrootdGSReal().

◆ fmtCgi

const int XrdXrootdGSReal::fmtCgi = 2
static

Format as binary info.

Definition at line 83 of file XrdXrootdGSReal.hh.

Referenced by XrdXrootdGSReal().

◆ fmtJson

const int XrdXrootdGSReal::fmtJson = 3
static

Format as CGI info.

Definition at line 84 of file XrdXrootdGSReal.hh.

Referenced by XrdXrootdGSReal().

◆ fmtNone

const int XrdXrootdGSReal::fmtNone = 0
static

Constructor

Parameters
gsParmsthe stream parameters as defined by GSParms.
aOKreference to a boolean which will contain true on success or will be set to false, otherwise.

Definition at line 81 of file XrdXrootdGSReal.hh.

◆ hdrFull

const int XrdXrootdGSReal::hdrFull = 5
static

Include site, host, port, inst, pgm.

Definition at line 91 of file XrdXrootdGSReal.hh.

◆ hdrHost

const int XrdXrootdGSReal::hdrHost = 3
static

Include site, host.

Definition at line 89 of file XrdXrootdGSReal.hh.

◆ hdrInst

const int XrdXrootdGSReal::hdrInst = 4
static

Include site, host, port, inst.

Definition at line 90 of file XrdXrootdGSReal.hh.

◆ hdrNone

const int XrdXrootdGSReal::hdrNone = 0
static

Format as JSON info.

Do not include header

Definition at line 86 of file XrdXrootdGSReal.hh.

Referenced by XrdXrootdGSReal().

◆ hdrNorm

const int XrdXrootdGSReal::hdrNorm = 1
static

Include standard header.

Definition at line 87 of file XrdXrootdGSReal.hh.

◆ hdrSite

const int XrdXrootdGSReal::hdrSite = 2
static

Include site.

Definition at line 88 of file XrdXrootdGSReal.hh.

◆ optNoID

const int XrdXrootdGSReal::optNoID = 0x01
static

Don't send ident records.

Definition at line 93 of file XrdXrootdGSReal.hh.

Referenced by XrdXrootdGSReal().


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