Loading...
Searching...
No Matches
XrdPoll Class Referenceabstract

`#include <XrdPoll.hh>`

Inheritance diagram for XrdPoll:
Collaboration diagram for XrdPoll:

## Classes

struct | PipeData
union | PipeData.Parms
struct | PipeData.Parms.Arg

## Public Member Functions

| XrdPoll ()
virtual | ~XrdPoll ()
virtual void | Disable (XrdPollInfo &pInfo, const char *etxt=0)=0
virtual int | Enable (XrdPollInfo &pInfo)=0
virtual void | Start (XrdSysSemaphore *syncp, int &rc)=0

## Static Public Member Functions

static int | Attach (XrdPollInfo &pInfo)
static void | Detach (XrdPollInfo &pInfo)
static int | Finish (XrdPollInfo &pInfo, const char *etxt=0)
static char * | Poll2Text (short events)
static int | Setup (int numfd)
static int | Stats (char *buff, int blen, int do_sync=0)

## Public Attributes

int | PID
pthread_t | TID

## Static Public Attributes

static XrdPoll * | Pollers [XRD_NUMPOLLERS] = {0, 0, 0}

## Protected Member Functions

virtual void | Exclude (XrdPollInfo &pInfo)=0
int | getRequest ()
virtual int | Include (XrdPollInfo &pInfo)=0

## Static Protected Member Functions

static XrdPoll * | newPoller (int pollid, int numfd)

## Protected Attributes

int | CmdFD
int | numEnabled
int | numEvents
int | numInterrupts
int | PipeBlen
char * | PipeBuff
struct pollfd | PipePoll
XrdSysMutex | PollPipe
PipeData | ReqBuff
int | ReqFD

## Static Protected Attributes

static const char * | TraceID = "Poll"

## Detailed Description

Definition at line 40 of file XrdPoll.hh.

## Class Documentation

## XrdPoll::PipeData.Parms

union XrdPoll::PipeData.Parms

Definition at line 119 of file XrdPoll.hh.

Collaboration diagram for XrdPoll::PipeData.Parms:

Class Members
struct PipeData.Parms.Arg | Arg |
XrdSysSemaphore * | theSem |

## XrdPoll::PipeData.Parms.Arg

struct XrdPoll::PipeData.Parms.Arg

Definition at line 120 of file XrdPoll.hh.

Collaboration diagram for XrdPoll::PipeData.Parms.Arg:

Class Members
int | ent |
int | fd |

## Constructor & Destructor Documentation

## XrdPoll()

XrdPoll::XrdPoll | ( |  | ) |

Definition at line 118 of file XrdPoll.cc.

{
int fildes[2];
TID=0;
numAttached=numEnabled=numEvents=numInterrupts=0;
if (XrdSysFD_Pipe(fildes) == 0)
{CmdFD = fildes[1];
ReqFD = fildes[0];
} else {
CmdFD = ReqFD = -1;
Log.Emsg("Poll", errno, "create poll pipe");
}
PipeBuff = 0;
PipeBlen = 0;
PipePoll.fd = ReqFD;
PipePoll.events = POLLIN | POLLRDNORM;
}
XrdPoll::numInterrupts
int numInterrupts
Definition XrdPoll.hh:134
XrdPoll::TID
pthread_t TID
Definition XrdPoll.hh:83
XrdPoll::PipePoll
struct pollfd PipePoll
Definition XrdPoll.hh:116
XrdPoll::ReqFD
int ReqFD
Definition XrdPoll.hh:118
XrdPoll::PipeBlen
int PipeBlen
Definition XrdPoll.hh:128
XrdPoll::numEvents
int numEvents
Definition XrdPoll.hh:133
XrdPoll::PipeBuff
char * PipeBuff
Definition XrdPoll.hh:127
XrdPoll::numEnabled
int numEnabled
Definition XrdPoll.hh:132
XrdPoll::CmdFD
int CmdFD
Definition XrdPoll.hh:117
XrdSysError::Emsg
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition XrdSysError.cc:95
XrdGlobal::Log
XrdSysError Log
Definition XrdConfig.cc:113

References CmdFD, XrdGlobal::Log, numEnabled, numEvents, numInterrupts, PipeBlen, PipeBuff, PipePoll, ReqFD, and TID.

Referenced by Attach(), Detach(), Include(), newPoller(), and Stats().

Here is the caller graph for this function:

## ~XrdPoll()

virtual XrdPoll::~XrdPoll | ( |  | ) |

inline virtual

Definition at line 90 of file XrdPoll.hh.

{}

## Member Function Documentation

## Attach()

int XrdPoll::Attach | ( | XrdPollInfo & | pInfo | ) |

static

Definition at line 144 of file XrdPoll.cc.

{
int i;
XrdPoll *pp;
// We allow only one attach at a time to simplify the processing
//
doingAttach.Lock();
// Find a poller with the smallest number of entries
//
pp = Pollers[0];
for (i = 1; i < XRD_NUMPOLLERS; i++)
if (pp->numAttached > Pollers[i]->numAttached) pp = Pollers[i];
// Include this FD into the poll set of the poller
//
if (!pp->Include(pInfo)) {doingAttach.UnLock(); return 0;}
// Complete the link setup
//
pInfo.Poller = pp;
pp->numAttached++;
doingAttach.UnLock();
TRACEI(POLL, "FD " <<pInfo.FD <<" attached to poller " <<pp->PID
<<"; num=" <<pp->numAttached);
return 1;
}
XRD_NUMPOLLERS
#define XRD_NUMPOLLERS
Definition XrdPoll.hh:35
TRACEI
#define TRACEI(act, x)
Definition XrdTrace.hh:66
XrdPollInfo::FD
int FD
Definition XrdPollInfo.hh:44
XrdPollInfo::Poller
XrdPoll * Poller
Definition XrdPollInfo.hh:43
XrdPoll::XrdPoll
XrdPoll()
Definition XrdPoll.cc:118
XrdPoll::Pollers
static XrdPoll * Pollers[XRD_NUMPOLLERS]
Definition XrdPoll.hh:79
XrdPoll::PID
int PID
Definition XrdPoll.hh:82
XrdPoll::Include
virtual int Include(XrdPollInfo &pInfo)=0

References XrdPoll(), XrdPollInfo::FD, Include(), PID, XrdPollInfo::Poller, Pollers, TRACEI, and XRD_NUMPOLLERS.

Referenced by XrdLink::Activate().

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

## Detach()

void XrdPoll::Detach | ( | XrdPollInfo & | pInfo | ) |

static

Definition at line 177 of file XrdPoll.cc.

{
XrdPoll *pp;
// If link is not attached, simply return
//
if (!(pp = pInfo.Poller)) return;
// Exclude this link from the associated poll set
//
pp->Exclude(pInfo);
// Make sure we are consistent
//
doingAttach.Lock();
if (!pp->numAttached)
{Log.Emsg("Poll","Underflow detaching", pInfo.Link.ID); abort();}
pp->numAttached--;
doingAttach.UnLock();
TRACEI(POLL, "FD " <<pInfo.FD <<" detached from poller " <<pp->PID
<<"; num=" <<pp->numAttached);
}
XrdLink::ID
char * ID
Pointer to the client's link identity.
Definition XrdLink.hh:210
XrdPollInfo::Link
XrdLink & Link
Definition XrdPollInfo.hh:41
XrdPoll::Exclude
virtual void Exclude(XrdPollInfo &pInfo)=0

References XrdPoll(), Exclude(), XrdPollInfo::FD, XrdLink::ID, XrdPollInfo::Link, XrdGlobal::Log, PID, XrdPollInfo::Poller, and TRACEI.

Referenced by XrdLinkXeq::Close().

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

## Disable()

virtual void XrdPoll::Disable | ( | XrdPollInfo & | pInfo,
|  | const char * | etxt = 0 )

pure virtual

Implemented in XrdPollE, and XrdPollPoll.

Referenced by XrdLinkCtl::idleScan().

Here is the caller graph for this function:

## Enable()

virtual int XrdPoll::Enable | ( | XrdPollInfo & | pInfo | ) |

pure virtual

Implemented in XrdPollE, and XrdPollPoll.

## Exclude()

virtual void XrdPoll::Exclude | ( | XrdPollInfo & | pInfo | ) |

protected pure virtual

Implemented in XrdPollE, and XrdPollPoll.

Referenced by Detach().

Here is the caller graph for this function:

## Finish()

int XrdPoll::Finish | ( | XrdPollInfo & | pInfo,
|  | const char * | etxt = 0 )

static

Definition at line 204 of file XrdPoll.cc.

{
static XrdPoll_End LinkEnd;
// If this link is already scheduled for termination, ignore this call.
//
if (pInfo.Link.getProtocol() == &LinkEnd)
{TRACEI(POLL, "Link " <<pInfo.FD <<" already terminating; "
<<(etxt ? etxt : "") <<" request ignored.");
return 0;
}
// Set the protocol pointer to be link termination
//
pInfo.Link.setProtocol(&LinkEnd, false, true);
if (!etxt) etxt = "reason unknown";
pInfo.Link.setEtext(etxt);
TRACEI(POLL, "Link " <<pInfo.FD <<" terminating: " <<etxt);
return 1;
}
XrdLink::setProtocol
XrdProtocol * setProtocol(XrdProtocol *pp, bool runit=false, bool push=false)
Definition XrdLink.cc:426
XrdLink::setEtext
int setEtext(const char *text)
Definition XrdLink.cc:393
XrdLink::getProtocol
XrdProtocol * getProtocol()
Obtain current protocol object pointer.
Definition XrdLink.cc:234

References XrdPollInfo::FD, XrdLink::getProtocol(), XrdPollInfo::Link, XrdLink::setEtext(), XrdLink::setProtocol(), and TRACEI.

Referenced by XrdPollE::Disable(), XrdPollPoll::Disable(), XrdPollE::Start(), and XrdPollPoll::Start().

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

## getRequest()

int XrdPoll::getRequest | ( |  | ) |

protected

Definition at line 232 of file XrdPoll.cc.

{
ssize_t rlen;
int rc;
// See if we are to resume a read or start a fresh one
//
if (!PipeBlen)
{PipeBuff = (char *)&ReqBuff; PipeBlen = sizeof(ReqBuff);}
// Wait for the next request. Some OS's (like Linux) don't support non-blocking
// pipes. So, we must front the read with a poll.
//
do {rc = poll(&PipePoll, 1, 0);}
while(rc < 0 && (errno == EAGAIN || errno == EINTR));
if (rc < 1) return 0;
// Now we can put up a read without a delay. Normally a full command will be
// present. Under some heavy conditions, this may not be the case.
//
do {rlen = read(ReqFD, PipeBuff, PipeBlen);}
while(rlen < 0 && errno == EINTR);
if (rlen <= 0)
{if (rlen) Log.Emsg("Poll", errno, "read from request pipe");
return 0;
}
// Check if all the data has arrived. If not all the data is present, defer
// this request until more data arrives.
//
if (!(PipeBlen -= rlen)) return 1;
PipeBuff += rlen;
TRACE(POLL, "Poller " <<PID <<" still needs " <<PipeBlen <<" req pipe bytes");
return 0;
}
read
#define read(a, b, c)
Definition XrdPosix.hh:82
TRACE
#define TRACE(act, x)
Definition XrdTrace.hh:63
XrdPoll::ReqBuff
PipeData ReqBuff
Definition XrdPoll.hh:126

References XrdGlobal::Log, PID, PipeBlen, PipeBuff, PipePoll, read, ReqBuff, ReqFD, and TRACE.

## Include()

virtual int XrdPoll::Include | ( | XrdPollInfo & | pInfo | ) |

protected pure virtual

Implemented in XrdPollE, and XrdPollPoll.

References XrdPoll().

Referenced by Attach().

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

## newPoller()

XrdPoll * XrdPoll::newPoller | ( | int | pollid,
|  | int | numfd )

static protected

Definition at line 45 of file XrdPollE.icc.

{
int pfd, wfd, bytes, alignment, pagsz = getpagesize();
struct epoll_event *pp;
// Open the /dev/poll driver
//
#ifndef EPOLL_CLOEXEC
if ((pfd = epoll_create(maxfd)) >= 0) fcntl(pfd, F_SETFD, FD_CLOEXEC);
else
#else
if ((pfd = epoll_create1(EPOLL_CLOEXEC)) < 0)
#endif
{Log.Emsg("Poll", errno, "create epoll device"); return 0;}
if ((wfd = eventfd(0, EFD_CLOEXEC)) < 0)
{Log.Emsg("Poll", errno,
"create an eventfd as the wait-poller descriptor");
close(pfd);
return 0;
}
// Calculate the size of the poll table and allocate it
//
bytes = maxfd * sizeof(struct epoll_event);
alignment = (bytes < pagsz ? 1024 : pagsz);
if (posix_memalign((void **)&pp, alignment, bytes))
{Log.Emsg("Poll", ENOMEM, "create poll table");
close(wfd);
close(pfd);
return 0;
}
// Create new poll object
//
memset((void *)pp, 0, bytes);
return (XrdPoll *)new XrdPollE(pp, maxfd, pfd, wfd);
}
close
#define close(a)
Definition XrdPosix.hh:48

References XrdPoll(), close, and XrdSysError::Emsg().

Referenced by Setup().

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

## Poll2Text()

char * XrdPoll::Poll2Text | ( | short | events | ) |

static

Definition at line 272 of file XrdPoll.cc.

{
if (events & POLLERR) return strdup("socket error");
if (events & POLLHUP) return strdup("hangup");
if (events & POLLNVAL) return strdup("socket closed");
{char buff[64];
sprintf(buff, "unusual event (%.4x)", events);
return strdup(buff);
}
return (char *)0;
}

Referenced by XrdLinkXeq::Peek(), XrdLinkXeq::Recv(), XrdLinkXeq::Recv(), XrdLinkXeq::RecvAll(), XrdPollPoll::Start(), and XrdLink::Wait4Data().

Here is the caller graph for this function:

## Setup()

int XrdPoll::Setup | ( | int | numfd | ) |

static

Definition at line 291 of file XrdPoll.cc.

{
pthread_t tid;
int maxfd, retc, i;
struct XrdPollArg PArg;
// Calculate the number of table entries per poller
//
maxfd = (numfd / XRD_NUMPOLLERS) + 16;
// Verify that we initialized the poller table
//
for (i = 0; i < XRD_NUMPOLLERS; i++)
{if (!(Pollers[i] = newPoller(i, maxfd))) return 0;
Pollers[i]->PID = i;
// Now start a thread to handle this poller object
//
PArg.Poller = Pollers[i];
PArg.retcode= 0;
TRACE(POLL, "Starting poller " <<i);
if ((retc = XrdSysThread::Run(&tid,XrdStartPolling,(void *)&PArg,
XRDSYSTHREAD_BIND, "Poller")))
{Log.Emsg("Poll", retc, "create poller thread"); return 0;}
Pollers[i]->TID = tid;
PArg.PollSync.Wait();
if (PArg.retcode)
{Log.Emsg("Poll", PArg.retcode, "start poller");
return 0;
}
}
// All done
//
return 1;
}
XrdStartPolling
void * XrdStartPolling(void *parg)
Definition XrdPoll.cc:107
XRDSYSTHREAD_BIND
#define XRDSYSTHREAD_BIND
Definition XrdSysPthread.hh:543
XrdPoll::newPoller
static XrdPoll * newPoller(int pollid, int numfd)
Definition XrdPollE.icc:45
XrdSysThread::Run
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)
Definition XrdSysPthread.cc:307

References XrdGlobal::Log, newPoller(), XrdPollArg::Poller, Pollers, XrdPollArg::retcode, XrdSysThread::Run(), TRACE, XRD_NUMPOLLERS, XrdStartPolling(), and XRDSYSTHREAD_BIND.

Here is the call graph for this function:

## Start()

virtual void XrdPoll::Start | ( | XrdSysSemaphore * | syncp,
|  | int & | rc )

pure virtual

Implemented in XrdPollE, and XrdPollPoll.

Referenced by XrdStartPolling().

Here is the caller graph for this function:

## Stats()

int XrdPoll::Stats | ( | char * | buff,
|  | int | blen,
|  | int | do_sync = 0 )

static

Definition at line 332 of file XrdPoll.cc.

{
static const char statfmt[] = "<stats id=\"poll\"><att>%d</att>"
"<en>%d</en><ev>%d</ev><int>%d</int></stats>";
int i, numatt = 0, numen = 0, numev = 0, numint = 0;
XrdPoll *pp;
// Return number of bytes if so wanted
//
if (!buff) return (sizeof(statfmt)+(4*16))*XRD_NUMPOLLERS;
// Get statistics. While we wish we could honor do_sync, doing so would be
// costly and hardly worth it. So, we do not include code such as:
// x = pp->y; if (do_sync) while(x != pp->y) x = pp->y; tot += x;
//
for (i = 0; i < XRD_NUMPOLLERS; i++)
{pp = Pollers[i];
numatt += pp->numAttached;
numen += pp->numEnabled;
numev += pp->numEvents;
numint += pp->numInterrupts;
}
// Format and return
//
return snprintf(buff, blen, statfmt, numatt, numen, numev, numint);
}

References XrdPoll(), numEnabled, numEvents, numInterrupts, Pollers, and XRD_NUMPOLLERS.

Here is the call graph for this function:

## Member Data Documentation

## CmdFD

int XrdPoll::CmdFD

protected

Definition at line 117 of file XrdPoll.hh.

Referenced by XrdPoll(), XrdPollPoll::Disable(), XrdPollPoll::Enable(), and XrdPollPoll::Exclude().

## numEnabled

int XrdPoll::numEnabled

protected

Definition at line 132 of file XrdPoll.hh.

Referenced by XrdPoll(), XrdPollE::Enable(), and Stats().

## numEvents

int XrdPoll::numEvents

protected

Definition at line 133 of file XrdPoll.hh.

Referenced by XrdPoll(), XrdPollE::Start(), XrdPollPoll::Start(), and Stats().

## numInterrupts

int XrdPoll::numInterrupts

protected

Definition at line 134 of file XrdPoll.hh.

Referenced by XrdPoll(), XrdPollPoll::Start(), and Stats().

## PID

int XrdPoll::PID

Definition at line 82 of file XrdPoll.hh.

Referenced by Attach(), Detach(), XrdPollE::Disable(), XrdPollPoll::Disable(), XrdPollE::Enable(), XrdPollPoll::Enable(), XrdPollPoll::Exclude(), and getRequest().

## PipeBlen

int XrdPoll::PipeBlen

protected

Definition at line 128 of file XrdPoll.hh.

Referenced by XrdPoll(), and getRequest().

## PipeBuff

char* XrdPoll::PipeBuff

protected

Definition at line 127 of file XrdPoll.hh.

Referenced by XrdPoll(), and getRequest().

## PipePoll

struct pollfd XrdPoll::PipePoll

protected

Definition at line 116 of file XrdPoll.hh.

Referenced by XrdPoll(), and getRequest().

## Pollers

XrdPoll * XrdPoll::Pollers = {0, 0, 0}

static

Definition at line 79 of file XrdPoll.hh.

Referenced by Attach(), Setup(), and Stats().

## PollPipe

XrdSysMutex XrdPoll::PollPipe

protected

Definition at line 115 of file XrdPoll.hh.

Referenced by XrdPollPoll::Disable(), XrdPollPoll::Enable(), and XrdPollPoll::Exclude().

## ReqBuff

PipeData XrdPoll::ReqBuff

protected

Definition at line 126 of file XrdPoll.hh.

Referenced by getRequest().

## ReqFD

int XrdPoll::ReqFD

protected

Definition at line 118 of file XrdPoll.hh.

Referenced by XrdPoll(), getRequest(), and XrdPollPoll::Start().

## TID

pthread_t XrdPoll::TID

Definition at line 83 of file XrdPoll.hh.

Referenced by XrdPoll().

## TraceID

const char * XrdPoll::TraceID = "Poll"

static protected

Definition at line 94 of file XrdPoll.hh.

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

- XrdPoll.hh
- XrdPoll.cc
- XrdPollE.icc
- XrdPollPoll.icc