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), WaitFdSem2(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:48

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:113
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 our 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 so we
202 // must make sure that the there are no more events.
203 // This is a separate issue from ensuring that if this Link is Scheduled it
204 // has completed processing. In the usual flow this is ensured by calling
205 // Close -> Detach -> Exclude from within the Link's schedule task.
206 //
207  Wait4Poller();
208 }
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 246 of file XrdPollE.icc.

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

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 295 of file XrdPollE.icc.

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

392 {
393  if (events & EPOLLERR) return "socket error";
394 
395  if (events & (EPOLLHUP | EPOLLRDHUP)) return "hangup";
396 
397  sprintf(buff, "unusual event (%.4x)", events);
398  return buff;
399 }
#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: