Loading...
Searching...
No Matches
XrdPollPoll Class Reference

`#include <XrdPollPoll.hh>`

Inheritance diagram for XrdPollPoll:
Collaboration diagram for XrdPollPoll:

## Public Member Functions

| XrdPollPoll (struct pollfd *pp, int numfd)
| ~XrdPollPoll ()
void | Disable (XrdPollInfo &pInfo, const char *etxt=0)
int | Enable (XrdPollInfo &pInfo)
void | Start (XrdSysSemaphore *syncp, int &rc)

## Protected Member Functions

void | doDetach (int pti)
void | Exclude (XrdPollInfo &pInfo)
int | Include (XrdPollInfo &pInfo)

## Detailed Description

Definition at line 38 of file XrdPollPoll.hh.

## Constructor & Destructor Documentation

## XrdPollPoll()

XrdPollPoll::XrdPollPoll | ( | struct pollfd * | pp,
|  | int | numfd )

Definition at line 67 of file XrdPollPoll.icc.

{
// Initialize the standard stuff
//
PollTab = pp;
PollTNum= 0;
PollQ = 0;
maxent = numfd;
}

## ~XrdPollPoll()

XrdPollPoll::~XrdPollPoll | ( |  | ) |

Definition at line 82 of file XrdPollPoll.icc.

{
if (PollTab) free(PollTab);
}

## Member Function Documentation

## Disable()

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

virtual

Implements XrdPoll.

Definition at line 135 of file XrdPollPoll.icc.

{
XrdSysSemaphore mySem(0);
PipeData cmdbuff[2];
int myerrno = 0;
// Check if this link is in the pollQ. If so, remove it.
//
if (pInfo.inQ) dqLink(&pInfo);
// Simply return if the link is already disabled
//
if (!pInfo.isEnabled) return;
// Trace this event
//
TRACEI(POLL, "Poller " <<PID <<" async disabling link FD " <<pInfo.FD);
// Send a disable request to the poller thread handling this link. We need to
// wait until the operation is actually completed before returning.
//
memset(&cmdbuff, 0, sizeof(cmdbuff));
cmdbuff[0].req = PipeData::DiFD;
cmdbuff[0].Parms.Arg.fd = pInfo.FD;
cmdbuff[0].Parms.Arg.ent = pInfo.PollEnt - PollTab;
cmdbuff[1].req = PipeData::Post;
cmdbuff[1].Parms.theSem = &mySem;
PollPipe.Lock();
if (write(CmdFD, &cmdbuff, sizeof(cmdbuff)) < 0) myerrno = errno;
PollPipe.UnLock();
// Verify that all went well and if termination wanted, terminate the link
//
if (myerrno) Log.Emsg("Poll", myerrno, "disable link", pInfo.Link.ID);
else {mySem.Wait();
if (etxt && Finish(pInfo, etxt))
Sched.Schedule((XrdJob *)&pInfo.Link);
}
}
write
#define write(a, b, c)
Definition XrdPosix.hh:115
TRACEI
#define TRACEI(act, x)
Definition XrdTrace.hh:66
XrdLink::ID
char * ID
Pointer to the client's link identity.
Definition XrdLink.hh:210
XrdPollInfo::PollEnt
struct pollfd * PollEnt
Definition XrdPollInfo.hh:42
XrdPollInfo::FD
int FD
Definition XrdPollInfo.hh:44
XrdPollInfo::inQ
bool inQ
Definition XrdPollInfo.hh:45
XrdPollInfo::Link
XrdLink & Link
Definition XrdPollInfo.hh:41
XrdPollInfo::isEnabled
bool isEnabled
Definition XrdPollInfo.hh:46
XrdPoll::PID
int PID
Definition XrdPoll.hh:82
XrdPoll::PollPipe
XrdSysMutex PollPipe
Definition XrdPoll.hh:115
XrdPoll::Finish
static int Finish(XrdPollInfo &pInfo, const char *etxt=0)
Definition XrdPoll.cc:204
XrdPoll::CmdFD
int CmdFD
Definition XrdPoll.hh:117
XrdScheduler::Schedule
void Schedule(XrdJob *jp)
Definition XrdScheduler.cc:373
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
XrdGlobal::Sched
XrdScheduler Sched
Definition XrdLinkCtl.cc:54
XrdPoll::PipeData
Definition XrdPoll.hh:119

References XrdPoll::CmdFD, XrdSysError::Emsg(), XrdPollInfo::FD, XrdPoll::Finish(), XrdLink::ID, XrdPollInfo::inQ, XrdPollInfo::isEnabled, XrdPollInfo::Link, XrdPoll::PipeData::Parms, XrdPoll::PID, XrdPollInfo::PollEnt, XrdPoll::PollPipe, XrdPoll::PipeData::req, XrdScheduler::Schedule(), TRACEI, XrdSysSemaphore::Wait(), and write.

Referenced by Exclude().

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

## doDetach()

void XrdPollPoll::doDetach | ( | int | pti | ) |

protected

Definition at line 358 of file XrdPollPoll.icc.

{
int lastent;
// Get some starting values
//
if ((lastent = PollTNum-1) < 0)
{Log.Emsg("Poll","Underflow during detach"); abort();}
if (pti == lastent)
do {PollTNum--;} while(PollTNum && PollTab[PollTNum-1].fd == -1);
}

References XrdSysError::Emsg().

Here is the call graph for this function:

## Enable()

int XrdPollPoll::Enable | ( | XrdPollInfo & | pInfo | ) |

virtual

Implements XrdPoll.

Definition at line 179 of file XrdPollPoll.icc.

{
PipeData cmdbuff;
int myerrno = 0;
// Simply return if the link is already enabled
//
if (pInfo.isEnabled) return 1;
// Add this link element to the queue
//
PollMutex.Lock();
pInfo.Next = PollQ;
PollQ = &pInfo;
pInfo.inQ = true;
PollMutex.UnLock();
// Send an enable request to the poller thread handling this link
//
TRACEI(POLL, "sending poller " <<PID <<" enable for link " <<pInfo.FD);
cmdbuff.req = PipeData::EnFD;
cmdbuff.Parms.Arg.fd = pInfo.FD;
cmdbuff.Parms.Arg.ent = pInfo.PollEnt - PollTab;
PollPipe.Lock();
if (write(CmdFD, &cmdbuff, sizeof(cmdbuff)) < 0) myerrno = errno;
PollPipe.UnLock();
// Verify that all went well. Note that the link stays in the pollQ.
//
if (myerrno)
{Log.Emsg("Poll", myerrno, "enable link", pInfo.Link.ID); return 0;}
// All done
//
return 1;
}
XrdPollInfo::Next
XrdPollInfo * Next
Definition XrdPollInfo.hh:40

References XrdPoll::CmdFD, XrdSysError::Emsg(), XrdPollInfo::FD, XrdLink::ID, XrdPollInfo::inQ, XrdPollInfo::isEnabled, XrdPollInfo::Link, XrdPollInfo::Next, XrdPoll::PipeData::Parms, XrdPoll::PID, XrdPollInfo::PollEnt, XrdPoll::PollPipe, XrdPoll::PipeData::req, TRACEI, and write.

Here is the call graph for this function:

## Exclude()

void XrdPollPoll::Exclude | ( | XrdPollInfo & | pInfo | ) |

protected virtual

Implements XrdPoll.

Definition at line 220 of file XrdPollPoll.icc.

{
XrdSysSemaphore mySem(0);
PipeData cmdbuff[2];
int myerrno = 0;
// Make sure this link is not enabled
//
if (pInfo.isEnabled)
{Log.Emsg("Poll", "Detach of enabled link", pInfo.Link.ID);
Disable(pInfo);
}
else if (pInfo.inQ) dqLink(&pInfo);
// Send a deatch request to the poller thread handling this link
//
TRACEI(POLL, "sending poller " <<PID <<" detach for link " <<pInfo.FD);
cmdbuff[0].req = PipeData::RmFD;
cmdbuff[0].Parms.Arg.fd = pInfo.FD;
cmdbuff[0].Parms.Arg.ent = pInfo.PollEnt - PollTab;
cmdbuff[1].req = PipeData::Post;
cmdbuff[1].Parms.theSem = &mySem;
PollPipe.Lock();
if (write(CmdFD, &cmdbuff, sizeof(cmdbuff)) < 0) myerrno = errno;
PollPipe.UnLock();
// Verify that all went well and if termination wanted, terminate the link
//
if (myerrno) Log.Emsg("Poll", myerrno, "detach link", pInfo.Link.ID);
else mySem.Wait();
}
XrdPollPoll::Disable
void Disable(XrdPollInfo &pInfo, const char *etxt=0)
Definition XrdPollPoll.icc:135

References XrdPoll::CmdFD, Disable(), XrdSysError::Emsg(), XrdPollInfo::FD, XrdLink::ID, XrdPollInfo::inQ, XrdPollInfo::isEnabled, XrdPollInfo::Link, XrdPoll::PipeData::Parms, XrdPoll::PID, XrdPollInfo::PollEnt, XrdPoll::PollPipe, XrdPoll::PipeData::req, TRACEI, XrdSysSemaphore::Wait(), and write.

Here is the call graph for this function:

## Include()

int XrdPollPoll::Include | ( | XrdPollInfo & | pInfo | ) |

protected virtual

Implements XrdPoll.

Definition at line 91 of file XrdPollPoll.icc.

{
struct pollfd *pfd;
int ptnum;
// Lock down the poll data structure
//
PollMutex.Lock();
// Get the next entry to be used
//
ptnum = 0;
while((ptnum < PollTNum) && (PollTab[ptnum].fd != -1)) ptnum++;
// Make sure we have enough table entries to add this link
//
if (ptnum > maxent)
{Log.Emsg("Attach","Attach",pInfo.Link.ID,"failed; poll table overflow.");
PollMutex.UnLock();
return 0;
}
// Initialize the polltable entry
//
pfd = &(PollTab[ptnum]);
pfd->fd = -pInfo.FD;
pfd->events = POLLIN | POLLRDNORM;
pfd->revents = 0;
// Record relevant information in the link
//
pInfo.PollEnt = pfd;
if (ptnum == PollTNum) PollTNum++;
// All done
//
PollMutex.UnLock();
return 1;
}

References XrdSysError::Emsg(), XrdPollInfo::FD, XrdLink::ID, XrdPollInfo::Link, and XrdPollInfo::PollEnt.

Here is the call graph for this function:

## Start()

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

virtual

Implements XrdPoll.

Definition at line 256 of file XrdPollPoll.icc.

{
int numpolled, num2sched;
XrdJob *jfirst, *jlast;
XrdPollInfo *plp, *nlp, *pInfo;
XrdLink *lp;
short pollevents;
const short pollOK = POLLIN | POLLRDNORM;
// Set up he first entry in the poll table to be our communications port
//
PollTab[0].fd = ReqFD;
PollTab[0].events = pollOK;
PollTab[0].revents = 0;
PollTNum = 1;
// Signal the caller to continue
//
retcode = 0;
syncsem->Post();
// Now do the main poll loop
//
std::vector<struct pollfd> PollTabCopy;
do {// Duplicate the polling table so we don't need to hold the PollMutex
// while we are sleeping in the poll()
PollMutex.Lock();
PollTabCopy.resize(PollTNum);
memcpy(PollTabCopy.data(), PollTab, sizeof(struct pollfd) * PollTNum);
PollMutex.UnLock();
do {numpolled = poll(PollTabCopy.data(), PollTabCopy.size(), -1);}
while(numpolled < 0 && (errno == EAGAIN || errno == EINTR));
// Check if we had a polling error
//
if (numpolled < 0)
{if (errno != EINTR) Restart(errno);
else numInterrupts++;
continue;
}
numEvents += numpolled;
// Note this thread is the only one that writes directly to the poll
// table (everything else is a read). Hence, it's OK to assume that
// the table after the poll() is unchanged and we can write back the
// revents field.
PollMutex.Lock();
for (size_t idx=0; idx<PollTabCopy.size(); idx++)
PollTab[idx].revents = PollTabCopy[idx].revents;
// Check out base poll table entry, we can do this without a lock
//
if (PollTab[0].revents & pollOK)
{PollMutex.UnLock();
doRequests(numpolled);
if (--numpolled <= 0) continue;
PollMutex.Lock();
}
// Checkout which links must be dispatched (do this locked)
//
plp = 0; nlp = PollQ; jfirst = jlast = 0; num2sched = 0;
while ((pInfo = nlp) && numpolled > 0)
{if ((pollevents = pInfo->PollEnt->revents))
{pInfo->PollEnt->fd = -pInfo->PollEnt->fd;
if (plp) nlp = plp->Next = pInfo->Next;
else nlp = PollQ = pInfo->Next;
numpolled--; pInfo->inQ = false;
if (!(pollevents & pollOK))
Finish(*pInfo, Poll2Text(pollevents));
lp = &(pInfo->Link);
if (!(pInfo->isEnabled))
Log.Emsg("Poll", "Disabled event occurred for", lp->ID);
else {pInfo->isEnabled = false;
lp->NextJob = jfirst; jfirst = (XrdJob *)lp;
if (!jlast) jlast=(XrdJob *)lp;
num2sched++;
continue;
}
}
plp = pInfo; nlp = pInfo->Next;
}
if (numpolled) Recover(numpolled);
PollMutex.UnLock();
// Schedule the polled links
//
if (num2sched == 1) Sched.Schedule(jfirst);
else if (num2sched) Sched.Schedule(num2sched, jfirst, jlast);
} while(1);
}
XrdJob::NextJob
XrdJob * NextJob
Definition XrdJob.hh:46
XrdPoll::numInterrupts
int numInterrupts
Definition XrdPoll.hh:134
XrdPoll::ReqFD
int ReqFD
Definition XrdPoll.hh:118
XrdPoll::numEvents
int numEvents
Definition XrdPoll.hh:133
XrdPoll::Poll2Text
static char * Poll2Text(short events)
Definition XrdPoll.cc:272

References XrdSysError::Emsg(), XrdPoll::Finish(), XrdLink::ID, XrdPollInfo::inQ, XrdPollInfo::isEnabled, XrdPollInfo::Link, XrdPollInfo::Next, XrdJob::NextJob, XrdPoll::numEvents, XrdPoll::numInterrupts, XrdPoll::Poll2Text(), XrdPollInfo::PollEnt, XrdSysSemaphore::Post(), XrdPoll::ReqFD, and XrdScheduler::Schedule().

Here is the call graph for this function:

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

- XrdPollPoll.hh
- XrdPollPoll.icc