XRootD
XrdMpxStats.cc File Reference
#include <cstdio>
#include <unistd.h>
#include <sys/types.h>
#include <sys/uio.h>
#include "XrdApps/XrdMpxXml.hh"
#include "XrdNet/XrdNetAddr.hh"
#include "XrdNet/XrdNetOpts.hh"
#include "XrdNet/XrdNetSocket.hh"
#include "XrdSys/XrdSysError.hh"
#include "XrdSys/XrdSysLogger.hh"
#include "XrdSys/XrdSysHeaders.hh"
#include "XrdSys/XrdSysPlatform.hh"
#include "XrdSys/XrdSysPthread.hh"
+ Include dependency graph for XrdMpxStats.cc:

Go to the source code of this file.

Classes

struct  XrdMpxOut::statsBuff
 
class  XrdMpxOut
 

Namespaces

 XrdMpx
 

Functions

int main (int argc, char *argv[])
 
void * mainOutput (void *parg)
 
void Usage (int rc)
 

Variables

static const int XrdMpx::addSender = 0x0001
 
XrdSysLogger XrdMpx::Logger
 
int XrdMpx::Opts
 
XrdMpxOut XrdMpx::statsQ
 

Class Documentation

◆ XrdMpxOut::statsBuff

struct XrdMpxOut::statsBuff

Definition at line 71 of file XrdMpxStats.cc.

+ Collaboration diagram for XrdMpxOut::statsBuff:
Class Members
char Data[8190]
int Dlen
XrdNetSockAddr From
statsBuff * Next
char Pad[2]

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 209 of file XrdMpxStats.cc.

210 {
211  extern char *optarg;
212  extern int opterr, optopt;
213  sigset_t myset;
214  pthread_t tid;
216  XrdMpxOut::statsBuff *sbP = 0;
217  XrdNetSocket mySocket(&Say);
218  XrdMpxXml *xP = 0;
219  SOCKLEN_t fromLen;
220  int Port = 0, retc, udpFD;
221  char buff[64], c;
222  bool Debug;
223 
224 // Process the options
225 //
226  opterr = 0; Debug = false; Opts = 0;
227  if (argc > 1 && '-' == *argv[1])
228  while ((c = getopt(argc,argv,"df:p:s")) && ((unsigned char)c != 0xff))
229  { switch(c)
230  {
231  case 'd': Debug = true;
232  break;
233  case 'f': if (!strcmp(optarg, "cgi" )) fType = XrdMpxXml::fmtCGI;
234  else if (!strcmp(optarg, "flat")) fType = XrdMpxXml::fmtFlat;
235  else if (!strcmp(optarg, "xml" )) fType = XrdMpxXml::fmtXML;
236  else {Say.Emsg(":", "Invalid format - ", optarg); Usage(1);}
237  break;
238  case 'h': Usage(0);
239  break;
240  case 'p': if (!(Port = atoi(optarg)))
241  {Say.Emsg(":", "Invalid port number - ", optarg); Usage(1);}
242  break;
243  case 's': Opts |= addSender;
244  break;
245  default: sprintf(buff,"'%c'", optopt);
246  if (c == ':') Say.Emsg(":", buff, "value not specified.");
247  else Say.Emsg(0, buff, "option is invalid");
248  Usage(1);
249  break;
250  }
251  }
252 
253 // Make sure port has been specified
254 //
255  if (!Port) {Say.Emsg(":", "Port has not been specified."); Usage(1);}
256 
257 // Turn off sigpipe and host a variety of others before we start any threads
258 //
259  signal(SIGPIPE, SIG_IGN); // Solaris optimization
260  sigemptyset(&myset);
261  sigaddset(&myset, SIGPIPE);
262  sigaddset(&myset, SIGCHLD);
263  pthread_sigmask(SIG_BLOCK, &myset, NULL);
264 
265 // Set the default stack size here
266 //
267  if (sizeof(long) > 4) XrdSysThread::setStackSize((size_t)1048576);
268  else XrdSysThread::setStackSize((size_t)786432);
269 
270 // Create a UDP socket and bind it to a port
271 //
272  if (mySocket.Open(0, Port, XRDNET_SERVER|XRDNET_UDPSOCKET, 0) < 0)
273  {Say.Emsg(":", -mySocket.LastError(), "create udp socket"); exit(4);}
274  udpFD = mySocket.Detach();
275 
276 // Establish format
277 //
278  if (fType != XrdMpxXml::fmtXML) xP = new XrdMpxXml(fType, Debug);
279 
280 // Now run a thread to output whatever we get
281 //
282  if ((retc = XrdSysThread::Run(&tid, mainOutput, (void *)xP,
283  XRDSYSTHREAD_BIND, "Output")))
284  {Say.Emsg(":", retc, "create output thread"); exit(4);}
285 
286 // Now simply wait for the messages
287 //
288  fromLen = sizeof(sbP->From);
289  while(1)
290  {sbP = statsQ.getBuff();
291  retc = recvfrom(udpFD, sbP->Data, sizeof(sbP->Data), 0,
292  &sbP->From.Addr, &fromLen);
293  if (retc < 0) {Say.Emsg(":", retc, "recv udp message"); exit(8);}
294  sbP->Dlen = retc;
295  statsQ.Add(sbP);
296  }
297 
298 // Should never get here
299 //
300  return 0;
301 }
int optopt
void * mainOutput(void *parg)
Definition: XrdMpxStats.cc:189
void Usage(int rc)
Definition: XrdMpxStats.cc:199
#define XRDNET_SERVER
Definition: XrdNetOpts.hh:99
#define XRDNET_UDPSOCKET
Definition: XrdNetOpts.hh:79
struct sockaddr Addr
#define SOCKLEN_t
#define XRDSYSTHREAD_BIND
XrdNetSockAddr From
Definition: XrdMpxStats.cc:73
void Add(statsBuff *sbP)
Definition: XrdMpxStats.cc:101
statsBuff * getBuff()
Definition: XrdMpxStats.cc:117
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)
static void setStackSize(size_t stsz, bool force=false)
XrdSysError Say
XrdMpxOut statsQ
Definition: XrdMpxStats.cc:182
static const int addSender
Definition: XrdMpxStats.cc:56
int Opts
Definition: XrdMpxStats.cc:58

References XrdMpxOut::Add(), XrdNetSockAddr::Addr, XrdMpx::addSender, XrdMpxOut::statsBuff::Data, Macaroons::Debug, XrdNetSocket::Detach(), XrdMpxOut::statsBuff::Dlen, XrdSysError::Emsg(), XrdMpxXml::fmtCGI, XrdMpxXml::fmtFlat, XrdMpxXml::fmtXML, XrdMpxOut::statsBuff::From, XrdMpxOut::getBuff(), XrdNetSocket::LastError(), mainOutput(), XrdNetSocket::Open(), optopt, XrdMpx::Opts, XrdSysThread::Run(), XrdCms::Say, XrdSysThread::setStackSize(), SOCKLEN_t, XrdMpx::statsQ, Usage(), XRDNET_SERVER, XRDNET_UDPSOCKET, and XRDSYSTHREAD_BIND.

+ Here is the call graph for this function:

◆ mainOutput()

void* mainOutput ( void *  parg)

Definition at line 189 of file XrdMpxStats.cc.

190 {
191  XrdMpxXml *xP = static_cast<XrdMpxXml *>(parg);
192  return statsQ.Run(xP);
193 }
void * Run(XrdMpxXml *xP)
Definition: XrdMpxStats.cc:134

References XrdMpxOut::Run(), and XrdMpx::statsQ.

Referenced by main().

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

◆ Usage()

void Usage ( int  rc)

Definition at line 199 of file XrdMpxStats.cc.

200 {
201  std::cerr <<"\nUsage: mpxstats [-f {cgi|flat|xml}] -p <port> [-s]" <<std::endl;
202  exit(rc);
203 }

Referenced by main().

+ Here is the caller graph for this function: