XRootD
Loading...
Searching...
No Matches
XrdSys::IOEvents::PollPort Class Reference
+ Inheritance diagram for XrdSys::IOEvents::PollPort:
+ Collaboration diagram for XrdSys::IOEvents::PollPort:

Public Member Functions

 PollPort (port_event_t *ptab, int numfd, int pfd, int pFD[2])
 
 ~PollPort ()
 
- Public Member Functions inherited from XrdSys::IOEvents::Poller
 Poller (int cFD, int rFD)
 
virtual ~Poller ()
 Destructor. Stop() is effecively called when this object is deleted.
 
void Stop ()
 

Static Public Member Functions

static int AllocMem (void **memP, int slots)
 
- Static Public Member Functions inherited from XrdSys::IOEvents::Poller
static PollerCreate (int &eNum, const char **eTxt=0, int crOpts=0)
 

Static Public Attributes

static const int pollER = POLLERR| POLLHUP
 
static const int pollOK = POLLIN | POLLRDNORM | POLLPRI | POLLOUT
 
static const int pollRD = POLLIN | POLLRDNORM | POLLPRI
 
static const int pollWR = POLLOUT
 

Protected Member Functions

void Begin (XrdSysSemaphore *syncp, int &rc, const char **eMsg)
 
timespec_t * BegTO (timespec_t &theTO)
 
void Exclude (Channel *cP, bool &isLocked, bool dover=1)
 
bool Include (Channel *cP, int &eNum, const char **eTxt, bool &isLocked)
 
bool Modify (Channel *cP, int &eNum, const char **eTxt, bool &isLocked)
 
void Shutdown ()
 
- Protected Member Functions inherited from XrdSys::IOEvents::Poller
void CbkTMO ()
 
bool CbkXeq (Channel *cP, int events, int eNum, const char *eTxt)
 
 CPP_ATOMIC_TYPE (bool) wakePend
 
int GetFault (Channel *cP)
 
int GetPollEnt (Channel *cP)
 
int GetRequest ()
 
bool Init (Channel *cP, int &eNum, const char **eTxt, bool &isLockd)
 
void LockChannel (Channel *cP)
 
int Poll2Enum (short events)
 
int SendCmd (PipeData &cmd)
 
void SetPollEnt (Channel *cP, int ptEnt)
 
bool TmoAdd (Channel *cP, int tmoSet)
 
void TmoDel (Channel *cP)
 
int TmoGet ()
 
void UnLockChannel (Channel *cP)
 

Additional Inherited Members

- Public Types inherited from XrdSys::IOEvents::Poller
enum  CreateOpts { optTOM }
 
- Protected Attributes inherited from XrdSys::IOEvents::Poller
ChannelattBase
 
bool chDead
 
int cmdFD
 
int pipeBlen
 
char * pipeBuff
 
struct pollfd pipePoll
 
pthread_t pollTid
 
PipeData reqBuff
 
int reqFD
 
ChanneltmoBase
 
unsigned char tmoMask
 
- Static Protected Attributes inherited from XrdSys::IOEvents::Poller
static time_t maxTime = (sizeof(time_t) == 8 ? 0x7fffffffffffffffLL : 0x7fffffff)
 
static pid_t parentPID = getpid()
 

Detailed Description

Definition at line 47 of file XrdSysIOEventsPollPort.icc.

Constructor & Destructor Documentation

◆ PollPort()

XrdSys::IOEvents::PollPort::PollPort ( port_event_t * ptab,
int numfd,
int pfd,
int pFD[2] )
inline

Definition at line 53 of file XrdSysIOEventsPollPort.icc.

54 : Poller(pFD[0], pFD[1]), pollTab(ptab),
55 pollDfd(pfd), pollMax(numfd)
56 {}

References XrdSys::IOEvents::Poller::Poller().

+ Here is the call graph for this function:

◆ ~PollPort()

XrdSys::IOEvents::PollPort::~PollPort ( )
inline

Definition at line 57 of file XrdSysIOEventsPollPort.icc.

References XrdSys::IOEvents::Poller::Stop().

+ Here is the call graph for this function:

Member Function Documentation

◆ AllocMem()

int XrdSys::IOEvents::PollPort::AllocMem ( void ** memP,
int slots )
static

Definition at line 155 of file XrdSysIOEventsPollPort.icc.

156{
157 int bytes, alignment, pagsz = getpagesize();
158
159// Calculate the size of the poll table and allocate it
160//
161 bytes = slots * sizeof(port_event_t);
162 alignment = (bytes < pagsz ? 1024 : pagsz);
163 if (posix_memalign(memP, alignment, bytes)) return ENOMEM;
164 memset(*memP, 0, bytes);
165 return 0;
166}

◆ Begin()

void XrdSys::IOEvents::PollPort::Begin ( XrdSysSemaphore * syncp,
int & rc,
const char ** eTxt )
protectedvirtual

Start the polling event loop. An implementation must be supplied. Begin() is called via the internal BootStrap class from a new thread.

Implements XrdSys::IOEvents::Poller.

Definition at line 172 of file XrdSysIOEventsPollPort.icc.

175{
176 unsigned int numpolled;
177 int rc;
178 timespec_t toVal;
179 Channel *cP;
180
181// Indicate to the starting thread that all went well
182//
183 retcode = 0;
184 *eTxt = 0;
185 syncsem->Post();
186
187// Now start dispatching channels that are ready. We use the wakePend flag to
188// keep the chatter down when we actually wakeup. There is also a "feature" of
189// poll_getn() that can return an errno of zero upon a timeout, sigh.
190//
191 do {numpolled = 1; errno = 0;
192 do {rc = port_getn(pollDfd, pollTab, pollMax, &numpolled, BegTO(toVal));}
193 while (rc < 0 && errno == EINTR);
194 wakePend = true; numPoll = numpolled;
195 if (rc)
196 {if (errno == ETIME || !errno) CbkTMO();
197 else {int rc = errno;
198 //--------------------------------------------------------------
199 // If we are in a child process and the poll file descriptor
200 // has been closed, there is an immense chance the fork will be
201 // followed by an exec, in which case we don't want to abort
202 //--------------------------------------------------------------
203 if( rc == EBADF && parentPID != getpid() ) return;
204 std::cerr <<"PollP: " <<XrdSysE2T(rc) <<" polling for events" <<std::endl;
205 abort();
206 }
207 }
208 for (int i = 0; i < (int)numpolled; i++)
209 if (pollTab[i].portev_source == PORT_SOURCE_FD)
210 {if ((cP = (Channel *)pollTab[i].portev_user))
211 {cbCurr = i; Dispatch(cP, pollTab[i].portev_events);}
212 else if (!Process(i)) return;
213 }
214 } while(1);
215}
const char * XrdSysE2T(int errcode)
Definition XrdSysE2T.cc:104
timespec_t * BegTO(timespec_t &theTO)

References BegTO(), XrdSys::IOEvents::Poller::CbkTMO(), XrdSys::IOEvents::Poller::Channel, ETIME, XrdSys::IOEvents::Poller::parentPID, XrdSysSemaphore::Post(), and XrdSysE2T().

+ Here is the call graph for this function:

◆ BegTO()

timespec_t * XrdSys::IOEvents::PollPort::BegTO ( timespec_t & theTO)
inlineprotected

Definition at line 68 of file XrdSysIOEventsPollPort.icc.

69 {int toval = TmoGet();
70 if (toval < 0) return 0;
71 theTO.tv_sec = toval/1000;
72 theTO.tv_nsec= 0;
73 return &theTO;
74 }

References XrdSys::IOEvents::Poller::TmoGet().

Referenced by Begin().

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

◆ Exclude()

void XrdSys::IOEvents::PollPort::Exclude ( Channel * cP,
bool & isLocked,
bool dover = 1 )
protectedvirtual

Remove a channel to the poll set. An implementation must be supplied. The channel is locked when this method is called but must be unlocked by the method if a command is sent to the poller thread and isLocked set to false.

Implements XrdSys::IOEvents::Poller.

Definition at line 257 of file XrdSysIOEventsPollPort.icc.

259{
260
261// Remove this channel from the poll set. We ignore errors as the descriptor
262// may have been closed prior to this call (though this shouldn't happen).
263//
264 port_dissociate(pollDfd, PORT_SOURCE_FD, cP->GetFD());
265
266// If we need to verify this action, sync with the poller thread (note that the
267// poller thread will not ask for this action unless it wants to deadlock). We
268// may actually deadlock anyway if the channel lock is held. We are allowed to
269// release it if the caller locked it. This will prevent a deadlock.
270//
271 if (dover)
272 {PipeData cmdbuff;
273 if (isLocked)
274 {isLocked = false;
275 UnLockChannel(cP);
276 }
277 cmdbuff.req = PipeData::RmFD;
278 cmdbuff.fd = cP->GetFD();
279 SendCmd(cmdbuff);
280 } else {
281 if (cbNow && cbNow != cP)
282 for (int i = cbCurr+1; i < numPoll; i++)
283 {if (cP == (Channel *)pollTab[i].portev_user)
284 pollTab[i].portev_user = &deadChP;
285 }
286 }
287}
int SendCmd(PipeData &cmd)
void UnLockChannel(Channel *cP)

References XrdSys::IOEvents::Poller::Channel, XrdSys::IOEvents::Poller::PipeData::fd, XrdSys::IOEvents::Channel::GetFD(), XrdSys::IOEvents::Poller::PipeData::req, XrdSys::IOEvents::Poller::SendCmd(), and XrdSys::IOEvents::Poller::UnLockChannel().

+ Here is the call graph for this function:

◆ Include()

bool XrdSys::IOEvents::PollPort::Include ( Channel * cP,
int & eNum,
const char ** eTxt,
bool & isLocked )
protectedvirtual

Add a channel to the poll set. An implementation must be supplied. The channel is locked when this method is called but must be unlocked by the method if a command is sent to the poller thread and isLocked set to false.

Implements XrdSys::IOEvents::Poller.

Definition at line 293 of file XrdSysIOEventsPollPort.icc.

297{
298 int pEvents = 0, events = cP->GetEvents();
299
300// Establish new event mask
301//
302 if (events & Channel:: readEvents) pEvents = pollRD;
303 if (events & Channel::writeEvents) pEvents |= pollWR;
304
305// Add this fd to the poll set
306//
307 if (port_associate(pollDfd, PORT_SOURCE_FD, cP->GetFD(), pEvents, cP))
308 {eNum = errno;
309 if (eTxt) *eTxt = "adding channel";
310 return false;
311 }
312
313// All went well.
314//
315 return true;
316}
@ writeEvents
Write and Write Timeouts.
@ readEvents
Read and Read Timeouts.

References XrdSys::IOEvents::Channel::GetEvents(), XrdSys::IOEvents::Channel::GetFD(), pollRD, pollWR, XrdSys::IOEvents::Channel::readEvents, and XrdSys::IOEvents::Channel::writeEvents.

+ Here is the call graph for this function:

◆ Modify()

bool XrdSys::IOEvents::PollPort::Modify ( Channel * cP,
int & eNum,
const char ** eTxt,
bool & isLocked )
protectedvirtual

Modify the event status of a channel. An implementation must be supplied. The channel is locked when this method is called but must be unlocked by the method if a command is sent to the poller thread and isLocked set to false.

Implements XrdSys::IOEvents::Poller.

Definition at line 322 of file XrdSysIOEventsPollPort.icc.

326{
327 int pEvents = 0, events = cP->GetEvents();
328
329// Establish new event mask
330//
331 if (events & Channel:: readEvents) pEvents = pollRD;
332 if (events & Channel::writeEvents) pEvents |= pollWR;
333
334// Associate the fd to the poll set
335//
336 if (port_associate(pollDfd, PORT_SOURCE_FD, cP->GetFD(), pEvents, cP))
337 {eNum = errno;
338 if (eTxt) *eTxt = "modifying poll events";
339 return false;
340 }
341
342// All done
343//
344 return true;
345}

References XrdSys::IOEvents::Channel::GetEvents(), XrdSys::IOEvents::Channel::GetFD(), pollRD, pollWR, XrdSys::IOEvents::Channel::readEvents, and XrdSys::IOEvents::Channel::writeEvents.

+ Here is the call graph for this function:

◆ Shutdown()

void XrdSys::IOEvents::PollPort::Shutdown ( )
protectedvirtual

Shutdown the poller. An implementation must be supplied. The shutdown method must release any allocated storage and close private file descriptors. The polling thread will have already been terminated and x-thread pipe closed. Warning: the derived destructor must call Stop() and do nothing else!

Implements XrdSys::IOEvents::Poller.

Definition at line 379 of file XrdSysIOEventsPollPort.icc.

380{
381 static XrdSysMutex shutMutex;
382
383// To avoid race conditions, we serialize this code
384//
385 shutMutex.Lock();
386
387// Release the poll table
388//
389 if (pollTab) {free(pollTab); pollTab = 0;}
390
391// Close the epoll file descriptor
392//
393 if (pollDfd >= 0) {close(pollDfd); pollDfd = -1;}
394
395// All done
396//
397 shutMutex.UnLock();
398}
#define close(a)
Definition XrdPosix.hh:43

References close, XrdSysMutex::Lock(), and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

Member Data Documentation

◆ pollER

const int XrdSys::IOEvents::PollPort::pollER = POLLERR| POLLHUP
static

Definition at line 59 of file XrdSysIOEventsPollPort.icc.

◆ pollOK

const int XrdSys::IOEvents::PollPort::pollOK = POLLIN | POLLRDNORM | POLLPRI | POLLOUT
static

Definition at line 60 of file XrdSysIOEventsPollPort.icc.

◆ pollRD

const int XrdSys::IOEvents::PollPort::pollRD = POLLIN | POLLRDNORM | POLLPRI
static

Definition at line 61 of file XrdSysIOEventsPollPort.icc.

Referenced by Include(), and Modify().

◆ pollWR

const int XrdSys::IOEvents::PollPort::pollWR = POLLOUT
static

Definition at line 62 of file XrdSysIOEventsPollPort.icc.

Referenced by Include(), and Modify().


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