XRootD
XrdPollE Class Reference

#include <XrdPollE.hh>

+ Inheritance diagram for XrdPollE:
+ Collaboration diagram for XrdPollE:

Public Member Functions

 XrdPollE (struct epoll_event *ptab, int numfd, int pfd, int wfd)
 
 ~XrdPollE ()
 
void Disable (XrdPollInfo &pInfo, const char *etxt=0)
 
int Enable (XrdPollInfo &pInfo)
 
void Start (XrdSysSemaphore *syncp, int &rc)
 
- Public Member Functions inherited from XrdPoll
 XrdPoll ()
 
virtual ~XrdPoll ()
 

Protected Member Functions

void Exclude (XrdPollInfo &pInfo)
 
int Include (XrdPollInfo &pInfo)
 
const char * x2Text (unsigned int evf, char *buff)
 
- Protected Member Functions inherited from XrdPoll
int getRequest ()
 

Additional Inherited Members

- Static Public Member Functions inherited from XrdPoll
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 inherited from XrdPoll
int PID
 
pthread_t TID
 
- Static Public Attributes inherited from XrdPoll
static XrdPollPollers [XRD_NUMPOLLERS] = {0, 0, 0}
 
- Static Protected Member Functions inherited from XrdPoll
static XrdPollnewPoller (int pollid, int numfd)
 
- Protected Attributes inherited from XrdPoll
int CmdFD
 
int numEnabled
 
int numEvents
 
int numInterrupts
 
int PipeBlen
 
char * PipeBuff
 
struct pollfd PipePoll
 
XrdSysMutex PollPipe
 
PipeData ReqBuff
 
int ReqFD
 
- Static Protected Attributes inherited from XrdPoll
static const char * TraceID = "Poll"
 

Detailed Description

Definition at line 40 of file XrdPollE.hh.

Constructor & Destructor Documentation

◆ XrdPollE()

XrdPollE::XrdPollE ( struct epoll_event *  ptab,
int  numfd,
int  pfd,
int  wfd 
)
inline

Definition at line 50 of file XrdPollE.hh.

51  : WaitFdSem(0)
52  {PollTab = ptab; PollMax = numfd; PollDfd = pfd;
53  WaitFd = wfd;
54  }

◆ ~XrdPollE()

XrdPollE::~XrdPollE ( )

Definition at line 88 of file XrdPollE.icc.

89 {
90  if (PollTab) free(PollTab);
91  if (WaitFd >= 0) close(WaitFd);
92  if (PollDfd >= 0) close(PollDfd);
93 }
#define close(a)
Definition: XrdPosix.hh:43

References close.

Member Function Documentation

◆ Disable()

void XrdPollE::Disable ( XrdPollInfo pInfo,
const char *  etxt = 0 
)
virtual

Implements XrdPoll.

Definition at line 119 of file XrdPollE.icc.

120 {
121 
122 // Simply return if the link is already disabled
123 //
124  if (!pInfo.isEnabled) return;
125 
126 // If Linux 2.6.9 we use EPOLLONESHOT to automatically disable a polled fd.
127 // So, the Disable() method need not do anything. Prior kernels did not have
128 // this mechanism so we need to do this manually.
129 //
130 #ifndef EPOLLONESHOT
131  struct epoll_event myEvents = {0, (void *)&pInfo};
132 
133 // Disable this fd. Unlike solaris, epoll_ctl() does not block when the pollfd
134 // is being waited upon by another thread.
135 //
136  if (epoll_ctl(PollDfd, EPOLL_CTL_MOD, pInfo.FD, &myEvents))
137  {Log.Emsg("Poll", errno, "disable link", lp->ID); return;}
138 #endif
139 
140 // Trace this event
141 //
142  pInfo.isEnabled = false;
143  TRACEI(POLL, "Poller " <<PID <<" async disabling link " <<pInfo.FD);
144 
145 // Check if this link needs to be rescheduled. If so, the caller better have
146 // the link opMutex lock held for this to work!
147 //
148  if (etxt && Finish(pInfo, etxt)) Sched.Schedule((XrdJob *)&pInfo.Link);
149 }
#define TRACEI(act, x)
Definition: XrdTrace.hh:66
Definition: XrdJob.hh:43
XrdLink & Link
Definition: XrdPollInfo.hh:41
bool isEnabled
Definition: XrdPollInfo.hh:46
int PID
Definition: XrdPoll.hh:82
static int Finish(XrdPollInfo &pInfo, const char *etxt=0)
Definition: XrdPoll.cc:204
void Schedule(XrdJob *jp)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95
XrdSysError Log
Definition: XrdConfig.cc:112
XrdScheduler Sched
Definition: XrdLinkCtl.cc:54

References XrdSysError::Emsg(), XrdPollInfo::FD, XrdPoll::Finish(), XrdPollInfo::isEnabled, XrdPollInfo::Link, XrdGlobal::Log, XrdPoll::PID, XrdGlobal::Sched, XrdScheduler::Schedule(), and TRACEI.

Referenced by Exclude().

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

◆ Enable()

int XrdPollE::Enable ( XrdPollInfo pInfo)
virtual

Implements XrdPoll.

Definition at line 155 of file XrdPollE.icc.

156 {
157  struct epoll_event myEvents = {ePollEvents, {(void *)&pInfo}};
158 
159 // Simply return if the link is already enabled
160 //
161  if (pInfo.isEnabled) return 1;
162 
163 // Enable this fd. Unlike solaris, epoll_ctl() does not block when the pollfd
164 // is being waited upon by another thread.
165 //
166  pInfo.isEnabled = true;
167  if (epoll_ctl(PollDfd, EPOLL_CTL_MOD, pInfo.FD, &myEvents))
168  {Log.Emsg("Poll", errno, "enable link", pInfo.Link.ID);
169  pInfo.isEnabled = false;
170  return 0;
171  }
172 
173 // Do final processing
174 //
175  TRACE(POLL, "Poller " <<PID <<" enabled " <<pInfo.Link.ID);
176  numEnabled++;
177  return 1;
178 }
#define TRACE(act, x)
Definition: XrdTrace.hh:63
int numEnabled
Definition: XrdPoll.hh:132

References XrdSysError::Emsg(), XrdPollInfo::FD, XrdLink::ID, XrdPollInfo::isEnabled, XrdPollInfo::Link, XrdGlobal::Log, XrdPoll::numEnabled, XrdPoll::PID, and TRACE.

+ Here is the call graph for this function:

◆ Exclude()

void XrdPollE::Exclude ( XrdPollInfo pInfo)
protectedvirtual

Implements XrdPoll.

Definition at line 184 of file XrdPollE.icc.

185 {
186 
187 // Make sure this link is not enabled
188 //
189  if (pInfo.isEnabled)
190  {Log.Emsg("Poll", "Detach of enabled link", pInfo.Link.ID);
191  Disable(pInfo);
192  }
193 
194 // Forcibly remove the link from the poll set
195 //
196  remFD(pInfo, 0);
197 
198 // Wait to make sure the poll thread has completed handling the last set of
199 // events which may have included this Link. The handing includes examining the
200 // Link's PollInfo before deciding if to schedule the Link. After we return,
201 // the PollInfo may be reset and the Link could be subsequently reused.
202 //
203  Wait4Poller();
204 }
void Disable(XrdPollInfo &pInfo, const char *etxt=0)
Definition: XrdPollE.icc:119

References Disable(), XrdSysError::Emsg(), XrdLink::ID, XrdPollInfo::isEnabled, XrdPollInfo::Link, and XrdGlobal::Log.

+ Here is the call graph for this function:

◆ Include()

int XrdPollE::Include ( XrdPollInfo pInfo)
protectedvirtual

Implements XrdPoll.

Definition at line 241 of file XrdPollE.icc.

242 {
243  struct epoll_event myEvent = {0, {(void *)&pInfo}};
244  int rc;
245 
246 // Add this fd to the poll set
247 //
248  if ((rc = epoll_ctl(PollDfd, EPOLL_CTL_ADD, pInfo.FD, &myEvent)) < 0)
249  Log.Emsg("Poll", errno, "include link", pInfo.Link.ID);
250 
251 // All done
252 //
253  return rc == 0;
254 }

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

+ Here is the call graph for this function:

◆ Start()

void XrdPollE::Start ( XrdSysSemaphore syncp,
int &  rc 
)
virtual

Implements XrdPoll.

Definition at line 290 of file XrdPollE.icc.

291 {
292  char eBuff[64];
293  int rc, i, numpolled, num2sched;
294  unsigned int waitFdEvents;
295  bool haveWaiters;
296  XrdJob *jfirst, *jlast;
297  const short pollOK = EPOLLIN | EPOLLPRI;
298  XrdLink *lp;
299  XrdPollInfo *pInfo;
300 
301  if ((rc = AddWaitFd()))
302  {retcode = rc;
303  syncsem->Post();
304  return;
305  }
306 
307 // Indicate to the starting thread that all went well
308 //
309  retcode = 0;
310  syncsem->Post();
311 
312 // Now start dispatching links that are ready
313 //
314  do {do {numpolled = epoll_wait(PollDfd, PollTab, PollMax, -1);}
315  while (numpolled < 0 && errno == EINTR);
316  if (numpolled == 0) continue;
317  if (numpolled < 0)
318  {Log.Emsg("Poll", errno, "poll for events");
319  abort();
320  }
321  numEvents += numpolled;
322 
323  // Checkout which links must be dispatched (no need to lock)
324  //
325  jfirst = jlast = 0; num2sched = 0;
326  haveWaiters = false; waitFdEvents = 0;
327  for (i = 0; i < numpolled; i++)
328  {if (PollTab[i].data.ptr == &WaitFd)
329  {haveWaiters = true; waitFdEvents = PollTab[i].events;}
330  else if ((pInfo = (XrdPollInfo *)PollTab[i].data.ptr))
331  {if (!(pInfo->isEnabled) && pInfo->FD >= 0)
332  remFD(*pInfo, PollTab[i].events);
333  else {pInfo->isEnabled = 0;
334  if (!(PollTab[i].events & pollOK)
335  || (PollTab[i].events & POLLRDHUP))
336  Finish(*pInfo, x2Text(PollTab[i].events, eBuff));
337  lp = &(pInfo->Link);
338  lp->NextJob = jfirst; jfirst = (XrdJob *)lp;
339  if (!jlast) jlast=(XrdJob *)lp;
340  num2sched++;
341 #ifndef EPOLLONESHOT
342  PollTab[i].events = 0;
343  if (epoll_ctl(PollDfd,EPOLL_CTL_MOD,pInfo.FD,&PollTab[i]))
344  Log.Emsg("Poll",errno,"disable link",pInfo.Link.ID);
345 #endif
346  }
347  } else Log.Emsg("Poll", "null link event!!!!");
348  }
349 
350  // Schedule the polled links
351  //
352  if (num2sched == 1) Sched.Schedule(jfirst);
353  else if (num2sched) Sched.Schedule(num2sched, jfirst, jlast);
354 
355  if (haveWaiters) HandleWaitFd(waitFdEvents);
356  } while(1);
357 }
XrdJob * NextJob
Definition: XrdJob.hh:46
const char * x2Text(unsigned int evf, char *buff)
Definition: XrdPollE.icc:380
int numEvents
Definition: XrdPoll.hh:133

References XrdSysError::Emsg(), XrdPollInfo::FD, XrdPoll::Finish(), XrdLink::ID, XrdPollInfo::isEnabled, XrdPollInfo::Link, XrdGlobal::Log, XrdJob::NextJob, XrdPoll::numEvents, XrdSysSemaphore::Post(), XrdGlobal::Sched, XrdScheduler::Schedule(), and x2Text().

+ Here is the call graph for this function:

◆ x2Text()

const char * XrdPollE::x2Text ( unsigned int  evf,
char *  buff 
)
protected

Definition at line 380 of file XrdPollE.icc.

381 {
382  if (events & EPOLLERR) return "socket error";
383 
384  if (events & (EPOLLHUP | EPOLLRDHUP)) return "hangup";
385 
386  sprintf(buff, "unusual event (%.4x)", events);
387  return buff;
388 }
#define EPOLLRDHUP
Definition: XrdPollE.hh:37

References EPOLLRDHUP.

Referenced by Start().

+ Here is the caller graph for this function:

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