XRootD
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 65 of file XrdPollPoll.icc.

66 {
67 
68 // Initialize the standard stuff
69 //
70  PollTab = pp;
71  PollTNum= 0;
72  PollQ = 0;
73  maxent = numfd;
74 }

◆ ~XrdPollPoll()

XrdPollPoll::~XrdPollPoll ( )

Definition at line 80 of file XrdPollPoll.icc.

81 {
82  if (PollTab) free(PollTab);
83 }

Member Function Documentation

◆ Disable()

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

Implements XrdPoll.

Definition at line 133 of file XrdPollPoll.icc.

134 {
135  XrdSysSemaphore mySem(0);
136  PipeData cmdbuff[2];
137  int myerrno = 0;
138 
139 // Check if this link is in the pollQ. If so, remove it.
140 //
141  if (pInfo.inQ) dqLink(&pInfo);
142 
143 // Simply return if the link is already disabled
144 //
145  if (!pInfo.isEnabled) return;
146 
147 // Trace this event
148 //
149  TRACEI(POLL, "Poller " <<PID <<" async disabling link FD " <<pInfo.FD);
150 
151 // Send a disable request to the poller thread handling this link. We need to
152 // wait until the operation is actually completed before returning.
153 //
154  memset(&cmdbuff, 0, sizeof(cmdbuff));
155  cmdbuff[0].req = PipeData::DiFD;
156  cmdbuff[0].Parms.Arg.fd = pInfo.FD;
157  cmdbuff[0].Parms.Arg.ent = pInfo.PollEnt - PollTab;
158  cmdbuff[1].req = PipeData::Post;
159  cmdbuff[1].Parms.theSem = &mySem;
160  PollPipe.Lock();
161  if (write(CmdFD, &cmdbuff, sizeof(cmdbuff)) < 0) myerrno = errno;
162  PollPipe.UnLock();
163 
164 // Verify that all went well and if termination wanted, terminate the link
165 //
166  if (myerrno) Log.Emsg("Poll", myerrno, "disable link", pInfo.Link.ID);
167  else {mySem.Wait();
168  if (etxt && Finish(pInfo, etxt))
169  Sched.Schedule((XrdJob *)&pInfo.Link);
170  }
171 }
ssize_t write(int fildes, const void *buf, size_t nbyte)
#define TRACEI(act, x)
Definition: XrdTrace.hh:66
Definition: XrdJob.hh:43
struct pollfd * PollEnt
Definition: XrdPollInfo.hh:42
XrdLink & Link
Definition: XrdPollInfo.hh:41
bool isEnabled
Definition: XrdPollInfo.hh:46
int PID
Definition: XrdPoll.hh:82
XrdSysMutex PollPipe
Definition: XrdPoll.hh:115
static int Finish(XrdPollInfo &pInfo, const char *etxt=0)
Definition: XrdPoll.cc:204
int CmdFD
Definition: XrdPoll.hh:117
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 XrdPoll::CmdFD, XrdPoll::PipeData::DiFD, XrdSysError::Emsg(), XrdPollInfo::FD, XrdPoll::Finish(), XrdLink::ID, XrdPollInfo::inQ, XrdPollInfo::isEnabled, XrdPollInfo::Link, XrdSysMutex::Lock(), XrdGlobal::Log, XrdPoll::PipeData::Parms, XrdPoll::PID, XrdPollInfo::PollEnt, XrdPoll::PollPipe, XrdPoll::PipeData::Post, XrdPoll::PipeData::req, XrdGlobal::Sched, XrdScheduler::Schedule(), TRACEI, XrdSysMutex::UnLock(), 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 337 of file XrdPollPoll.icc.

338 {
339  int lastent;
340 
341 // Get some starting values
342 //
343  PollMutex.Lock();
344  if ((lastent = PollTNum-1) < 0)
345  {Log.Emsg("Poll","Underflow during detach"); abort();}
346 
347  if (pti == lastent)
348  do {PollTNum--;} while(PollTNum && PollTab[PollTNum-1].fd == -1);
349  PollMutex.UnLock();
350 }

References XrdSysError::Emsg(), XrdSysMutex::Lock(), XrdGlobal::Log, and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

◆ Enable()

int XrdPollPoll::Enable ( XrdPollInfo pInfo)
virtual

Implements XrdPoll.

Definition at line 177 of file XrdPollPoll.icc.

178 {
179  PipeData cmdbuff;
180  int myerrno = 0;
181 
182 // Simply return if the link is already enabled
183 //
184  if (pInfo.isEnabled) return 1;
185 
186 // Add this link element to the queue
187 //
188  PollMutex.Lock();
189  pInfo.Next = PollQ;
190  PollQ = &pInfo;
191  pInfo.inQ = true;
192  PollMutex.UnLock();
193 
194 // Send an enable request to the poller thread handling this link
195 //
196  TRACEI(POLL, "sending poller " <<PID <<" enable for link " <<pInfo.FD);
197  cmdbuff.req = PipeData::EnFD;
198  cmdbuff.Parms.Arg.fd = pInfo.FD;
199  cmdbuff.Parms.Arg.ent = pInfo.PollEnt - PollTab;
200  PollPipe.Lock();
201  if (write(CmdFD, &cmdbuff, sizeof(cmdbuff)) < 0) myerrno = errno;
202  PollPipe.UnLock();
203 
204 // Verify that all went well. Note that the link stays in the pollQ.
205 //
206  if (myerrno)
207  {Log.Emsg("Poll", myerrno, "enable link", pInfo.Link.ID); return 0;}
208 
209 // All done
210 //
211  return 1;
212 }
XrdPollInfo * Next
Definition: XrdPollInfo.hh:40

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

+ Here is the call graph for this function:

◆ Exclude()

void XrdPollPoll::Exclude ( XrdPollInfo pInfo)
protectedvirtual

Implements XrdPoll.

Definition at line 218 of file XrdPollPoll.icc.

219 {
220  XrdSysSemaphore mySem(0);
221  PipeData cmdbuff[2];
222  int myerrno = 0;
223 
224 // Make sure this link is not enabled
225 //
226  if (pInfo.isEnabled)
227  {Log.Emsg("Poll", "Detach of enabled link", pInfo.Link.ID);
228  Disable(pInfo);
229  }
230  else if (pInfo.inQ) dqLink(&pInfo);
231 
232 // Send a deatch request to the poller thread handling this link
233 //
234  TRACEI(POLL, "sending poller " <<PID <<" detach for link " <<pInfo.FD);
235  cmdbuff[0].req = PipeData::RmFD;
236  cmdbuff[0].Parms.Arg.fd = pInfo.FD;
237  cmdbuff[0].Parms.Arg.ent = pInfo.PollEnt - PollTab;
238  cmdbuff[1].req = PipeData::Post;
239  cmdbuff[1].Parms.theSem = &mySem;
240  PollPipe.Lock();
241  if (write(CmdFD, &cmdbuff, sizeof(cmdbuff)) < 0) myerrno = errno;
242  PollPipe.UnLock();
243 
244 // Verify that all went well and if termination wanted, terminate the link
245 //
246  if (myerrno) Log.Emsg("Poll", myerrno, "detach link", pInfo.Link.ID);
247  else mySem.Wait();
248 }
void Disable(XrdPollInfo &pInfo, const char *etxt=0)

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

+ Here is the call graph for this function:

◆ Include()

int XrdPollPoll::Include ( XrdPollInfo pInfo)
protectedvirtual

Implements XrdPoll.

Definition at line 89 of file XrdPollPoll.icc.

90 {
91  struct pollfd *pfd;
92  int ptnum;
93 
94 // Lock down the poll data structure
95 //
96  PollMutex.Lock();
97 
98 // Get the next entry to be used
99 //
100  ptnum = 0;
101  while((ptnum < PollTNum) && (PollTab[ptnum].fd != -1)) ptnum++;
102 
103 // Make sure we have enough table entries to add this link
104 //
105  if (ptnum > maxent)
106  {Log.Emsg("Attach","Attach",pInfo.Link.ID,"failed; poll table overflow.");
107  PollMutex.UnLock();
108  return 0;
109  }
110 
111 // Initialize the polltable entry
112 //
113  pfd = &(PollTab[ptnum]);
114  pfd->fd = -pInfo.FD;
115  pfd->events = POLLIN | POLLRDNORM;
116  pfd->revents = 0;
117 
118 // Record relevant information in the link
119 //
120  pInfo.PollEnt = pfd;
121  if (ptnum == PollTNum) PollTNum++;
122 
123 // All done
124 //
125  PollMutex.UnLock();
126  return 1;
127 }

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

+ Here is the call graph for this function:

◆ Start()

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

Implements XrdPoll.

Definition at line 254 of file XrdPollPoll.icc.

255 {
256  int numpolled, num2sched;
257  XrdJob *jfirst, *jlast;
258  XrdPollInfo *plp, *nlp, *pInfo;
259  XrdLink *lp;
260  short pollevents;
261  const short pollOK = POLLIN | POLLRDNORM;
262 
263 // Set up he first entry in the poll table to be our communications port
264 //
265  PollTab[0].fd = ReqFD;
266  PollTab[0].events = pollOK;
267  PollTab[0].revents = 0;
268  PollTNum = 1;
269 
270 // Signal the caller to continue
271 //
272  retcode = 0;
273  syncsem->Post();
274 
275 // Now do the main poll loop
276 //
277  do {do {numpolled = poll(PollTab, PollTNum, -1);}
278  while(numpolled < 0 && (errno == EAGAIN || errno == EINTR));
279 
280  // Check if we had a polling error
281  //
282  if (numpolled < 0)
283  {if (errno != EINTR) Restart(errno);
284  else numInterrupts++;
285  continue;
286  }
287  numEvents += numpolled;
288 
289  // Check out base poll table entry, we can do this without a lock
290  //
291  if (PollTab[0].revents & pollOK)
292  {doRequests(numpolled);
293  if (--numpolled <= 0) continue;
294  }
295 
296  // Checkout which links must be dispatched (do this locked)
297  //
298  PollMutex.Lock();
299  plp = 0; nlp = PollQ; jfirst = jlast = 0; num2sched = 0;
300  while ((pInfo = nlp) && numpolled > 0)
301  {if ((pollevents = pInfo->PollEnt->revents))
302  {pInfo->PollEnt->fd = -pInfo->PollEnt->fd;
303  if (plp) nlp = plp->Next = pInfo->Next;
304  else nlp = PollQ = pInfo->Next;
305  numpolled--; pInfo->inQ = false;
306  if (!(pollevents & pollOK))
307  Finish(*pInfo, Poll2Text(pollevents));
308  lp = &(pInfo->Link);
309  if (!(pInfo->isEnabled))
310  Log.Emsg("Poll", "Disabled event occurred for", lp->ID);
311  else {pInfo->isEnabled = false;
312  lp->NextJob = jfirst; jfirst = (XrdJob *)lp;
313  if (!jlast) jlast=(XrdJob *)lp;
314  num2sched++;
315  continue;
316  }
317  }
318  plp = pInfo; nlp = pInfo->Next;
319  }
320  if (numpolled) Recover(numpolled);
321  PollMutex.UnLock();
322 
323  // Schedule the polled links
324  //
325  if (num2sched == 1) Sched.Schedule(jfirst);
326  else if (num2sched) Sched.Schedule(num2sched, jfirst, jlast);
327  } while(1);
328 }
XrdJob * NextJob
Definition: XrdJob.hh:46
int numInterrupts
Definition: XrdPoll.hh:134
int ReqFD
Definition: XrdPoll.hh:118
int numEvents
Definition: XrdPoll.hh:133
static char * Poll2Text(short events)
Definition: XrdPoll.cc:272

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

+ Here is the call graph for this function:

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