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 Poller * | Create (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
Channel * | attBase
bool | chDead
int | cmdFD
int | pipeBlen
char * | pipeBuff
struct pollfd | pipePoll
pthread_t | pollTid
PipeData | reqBuff
int | reqFD
Channel * | tmoBase
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.

: Poller(pFD[0], pFD[1]), pollTab(ptab),
pollDfd(pfd), pollMax(numfd)
{}
XrdSys::IOEvents::Poller::Poller
Poller(int cFD, int rFD)
Definition XrdSysIOEvents.cc:571

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.

{Stop();}
XrdSys::IOEvents::Poller::Stop
void Stop()
Definition XrdSysIOEvents.cc:1030

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.

{
int bytes, alignment, pagsz = getpagesize();
// Calculate the size of the poll table and allocate it
//
bytes = slots * sizeof(port_event_t);
alignment = (bytes < pagsz ? 1024 : pagsz);
if (posix_memalign(memP, alignment, bytes)) return ENOMEM;
memset(*memP, 0, bytes);
return 0;
}

## Begin()

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

protected virtual

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.

{
unsigned int numpolled;
int rc;
timespec_t toVal;
Channel *cP;
// Indicate to the starting thread that all went well
//
retcode = 0;
*eTxt = 0;
syncsem->Post();
// Now start dispatching channels that are ready. We use the wakePend flag to
// keep the chatter down when we actually wakeup. There is also a "feature" of
// poll_getn() that can return an errno of zero upon a timeout, sigh.
//
do {numpolled = 1; errno = 0;
do {rc = port_getn(pollDfd, pollTab, pollMax, &numpolled, BegTO(toVal));}
while (rc < 0 && errno == EINTR);
wakePend = true; numPoll = numpolled;
if (rc)
{if (errno == ETIME || !errno) CbkTMO();
else {int rc = errno;
//--------------------------------------------------------------
// If we are in a child process and the poll file descriptor
// has been closed, there is an immense chance the fork will be
// followed by an exec, in which case we don't want to abort
//--------------------------------------------------------------
if( rc == EBADF && parentPID != getpid() ) return;
std::cerr <<"PollP: " <<XrdSysE2T(rc) <<" polling for events" <<std::endl;
abort();
}
}
for (int i = 0; i < (int)numpolled; i++)
if (pollTab[i].portev_source == PORT_SOURCE_FD)
{if ((cP = (Channel *)pollTab[i].portev_user))
{cbCurr = i; Dispatch(cP, pollTab[i].portev_events);}
else if (!Process(i)) return;
}
} while(1);
}
ETIME
#define ETIME
Definition XrdLink.cc:74
XrdSysE2T
const char * XrdSysE2T(int errcode)
Definition XrdSysE2T.cc:104
XrdSys::IOEvents::PollPort::BegTO
timespec_t * BegTO(timespec_t &theTO)
Definition XrdSysIOEventsPollPort.icc:68
XrdSys::IOEvents::Poller::CbkTMO
void CbkTMO()
Definition XrdSysIOEvents.cc:614
XrdSys::IOEvents::Poller::Channel
friend class Channel
Definition XrdSysIOEvents.hh:374
XrdSys::IOEvents::Poller::parentPID
static pid_t parentPID
Definition XrdSysIOEvents.hh:515

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 | ) |

inline protected

Definition at line 68 of file XrdSysIOEventsPollPort.icc.

{int toval = TmoGet();
if (toval < 0) return 0;
theTO.tv_sec = toval/1000;
theTO.tv_nsec= 0;
return &theTO;
}
XrdSys::IOEvents::Poller::TmoGet
int TmoGet()
Definition XrdSysIOEvents.cc:1180

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 )

protected virtual

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.

{
// Remove this channel from the poll set. We ignore errors as the descriptor
// may have been closed prior to this call (though this shouldn't happen).
//
port_dissociate(pollDfd, PORT_SOURCE_FD, cP->GetFD());
// If we need to verify this action, sync with the poller thread (note that the
// poller thread will not ask for this action unless it wants to deadlock). We
// may actually deadlock anyway if the channel lock is held. We are allowed to
// release it if the caller locked it. This will prevent a deadlock.
//
if (dover)
{PipeData cmdbuff;
if (isLocked)
{isLocked = false;
UnLockChannel(cP);
}
cmdbuff.req = PipeData::RmFD;
cmdbuff.fd = cP->GetFD();
SendCmd(cmdbuff);
} else {
if (cbNow && cbNow != cP)
for (int i = cbCurr+1; i < numPoll; i++)
{if (cP == (Channel *)pollTab[i].portev_user)
pollTab[i].portev_user = &deadChP;
}
}
}
XrdSys::IOEvents::Poller::SendCmd
int SendCmd(PipeData &cmd)
Definition XrdSysIOEvents.cc:993
XrdSys::IOEvents::Poller::UnLockChannel
void UnLockChannel(Channel *cP)
Definition XrdSysIOEvents.hh:448
XrdSys::IOEvents::Poller::PipeData
Definition XrdSysIOEvents.hh:496
XrdSys::IOEvents::Poller::PipeData::req
char req
Definition XrdSysIOEvents.hh:496

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 )

protected virtual

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.

{
int pEvents = 0, events = cP->GetEvents();
// Establish new event mask
//
if (events & Channel:: readEvents) pEvents = pollRD;
if (events & Channel::writeEvents) pEvents |= pollWR;
// Add this fd to the poll set
//
if (port_associate(pollDfd, PORT_SOURCE_FD, cP->GetFD(), pEvents, cP))
{eNum = errno;
if (eTxt) *eTxt = "adding channel";
return false;
}
// All went well.
//
return true;
}
XrdSys::IOEvents::Channel::writeEvents
@ writeEvents
Write and Write Timeouts.
Definition XrdSysIOEvents.hh:193
XrdSys::IOEvents::Channel::readEvents
@ readEvents
Read and Read Timeouts.
Definition XrdSysIOEvents.hh:192
XrdSys::IOEvents::PollPort::pollRD
static const int pollRD
Definition XrdSysIOEventsPollPort.icc:61
XrdSys::IOEvents::PollPort::pollWR
static const int pollWR
Definition XrdSysIOEventsPollPort.icc:62

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 )

protected virtual

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.

{
int pEvents = 0, events = cP->GetEvents();
// Establish new event mask
//
if (events & Channel:: readEvents) pEvents = pollRD;
if (events & Channel::writeEvents) pEvents |= pollWR;
// Associate the fd to the poll set
//
if (port_associate(pollDfd, PORT_SOURCE_FD, cP->GetFD(), pEvents, cP))
{eNum = errno;
if (eTxt) *eTxt = "modifying poll events";
return false;
}
// All done
//
return true;
}

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 | ( |  | ) |

protected virtual

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.

{
static XrdSysMutex shutMutex;
// To avoid race conditions, we serialize this code
//
shutMutex.Lock();
// Release the poll table
//
if (pollTab) {free(pollTab); pollTab = 0;}
// Close the epoll file descriptor
//
if (pollDfd >= 0) {close(pollDfd); pollDfd = -1;}
// All done
//
shutMutex.UnLock();
}
close
#define close(a)
Definition XrdPosix.hh:48
XrdSysMutex::Lock
void Lock()
Definition XrdSysPthread.hh:222
XrdSysMutex::UnLock
void UnLock()
Definition XrdSysPthread.hh:224

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:

- XrdSysIOEventsPollPort.icc