Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
XrdPoll.hh
Go to the documentation of this file.
1#ifndef __XRD_POLL_H__
2#define __XRD_POLL_H__
3/******************************************************************************/
4/* */
5/* X r d P o l l . h h */
6/* */
7/* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
8/* Produced by Andrew Hanushevsky for Stanford University under contract */
9/* DE-AC02-76-SFO0515 with the Department of Energy */
10/* */
11/* This file is part of the XRootD software suite. */
12/* */
13/* XRootD is free software: you can redistribute it and/or modify it under */
14/* the terms of the GNU Lesser General Public License as published by the */
15/* Free Software Foundation, either version 3 of the License, or (at your */
16/* option) any later version. */
17/* */
18/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21/* License for more details. */
22/* */
23/* You should have received a copy of the GNU Lesser General Public License */
24/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26/* */
27/* The copyright holder's institutional names and contributor's names may not */
28/* be used to endorse or promote products derived from this software without */
29/* specific prior written permission of the institution or contributor. */
30/******************************************************************************/
31
32#include <sys/poll.h>
33#include "XrdSys/XrdSysPthread.hh"
34
35#define XRD_NUMPOLLERS 3
36
37class XrdOucTrace;
38class XrdSysError;
39class XrdLink;
40class XrdScheduler;
41class XrdSysSemaphore;
42
44{
45public:
46
47// Attach() is called when a new link needs to be assigned to a poller
48//
49static int Attach(XrdLink *lp); // Implementation supplied
50
51// Detach() is called when a link is being discarded
52//
53static void Detach(XrdLink *lp); // Implementation supplied
54
55// Disable() is called when we need to mask interrupts from a link
56//
57virtual void Disable(XrdLink *lp, const char *etxt=0) = 0;
58
59// Enable() is called when we want to receive interrupts from a link
60//
61virtual int Enable(XrdLink *lp) = 0;
62
63// Finish() is called to allow a link to gracefully terminate when scheduled
64//
65static int Finish(XrdLink *lp, const char *etxt=0); //Implementation supplied
66
67// Init() is called to set pointers to external interfaces at config time.
68//
69static void Init(XrdSysError *eP, XrdOucTrace *tP, XrdScheduler *sP)
70 {XrdLog = eP; XrdTrace = tP; XrdSched = sP;}
71
72// Poll2Text() converts bits in an revents item to text
73//
74static char *Poll2Text(short events); // Implementation supplied
75
76// Setup() is called at config time to perform poller configuration
77//
78static int Setup(int numfd); // Implementation supplied
79
80// Start() is called via a thread for each poller that was created
81//
82virtual void Start(XrdSysSemaphore *syncp, int &rc) = 0;
83
84// Stats() is called to provide statistics on polling
85//
86static int Stats(char *buff, int blen, int do_sync=0);
87
88// Identification of the thread handling this object
89//
90 int PID; // Poller ID
91 pthread_t TID; // Thread ID
92
93// The following table reference the pollers in effect
94//
96
98virtual ~XrdPoll() {}
99
100protected:
101
102static const char *TraceID; // For tracing
103static XrdOucTrace *XrdTrace;
104static XrdSysError *XrdLog;
105static XrdScheduler *XrdSched;
106
107// Gets the next request on the poll pipe. This is common to all implentations.
108//
109 int getRequest(); // Implementation supplied
110
111// Exclude() called to exclude a link from a poll set
112//
113virtual void Exclude(XrdLink *lp) = 0;
114
115// Include() called to include a link in a poll set
116//
117virtual int Include(XrdLink *lp) = 0;
118
119// newPoller() called to get a new poll object at initialization time
120// Even though static, an implementation must be supplied.
121//
122static XrdPoll *newPoller(int pollid, int numfd) /* = 0 */;
123
124// The following is common to all implementations
125//
126XrdSysMutex PollPipe;
127struct pollfd PipePoll;
128int CmdFD; // FD to send PipeData commands
129int ReqFD; // FD to recv PipeData requests
130struct PipeData {union {XrdSysSemaphore *theSem;
131 struct {int fd;
132 int ent;} Arg;
134 enum cmd {EnFD, DiFD, RmFD, Post};
136 };
140
141// The following are statistical counters each implementation must maintain
142//
143 int numEnabled; // Count of Enable() calls
144 int numEvents; // Count of poll fd's dispatched
145 int numInterrupts; // Number of interrupts (e.g., signals)
146
147private:
148
149static XrdSysMutex doingAttach;
150 int numAttached; // Number of fd's attached to poller
151};
152#endif
#define XRD_NUMPOLLERS
Definition XrdPoll.hh:35
int numAttached
Definition XrdPoll.hh:150
virtual ~XrdPoll()
Definition XrdPoll.hh:98
int numInterrupts
Definition XrdPoll.hh:145
static void Detach(XrdLink *lp)
static int Stats(char *buff, int blen, int do_sync=0)
pthread_t TID
Definition XrdPoll.hh:91
virtual int Enable(XrdLink *lp)=0
static int Finish(XrdLink *lp, const char *etxt=0)
int PID
Definition XrdPoll.hh:90
struct pollfd PipePoll
Definition XrdPoll.hh:127
static const char * TraceID
Definition XrdPoll.hh:102
virtual void Start(XrdSysSemaphore *syncp, int &rc)=0
virtual void Exclude(XrdLink *lp)=0
XrdSysMutex PollPipe
Definition XrdPoll.hh:126
static XrdSysMutex doingAttach
Definition XrdPoll.hh:149
static XrdOucTrace * XrdTrace
Definition XrdPoll.hh:103
int ReqFD
Definition XrdPoll.hh:129
int PipeBlen
Definition XrdPoll.hh:139
static int Setup(int numfd)
static char * Poll2Text(short events)
int numEvents
Definition XrdPoll.hh:144
int getRequest()
static XrdPoll * Pollers[XRD_NUMPOLLERS]
Definition XrdPoll.hh:95
PipeData ReqBuff
Definition XrdPoll.hh:137
char * PipeBuff
Definition XrdPoll.hh:138
static XrdPoll * newPoller(int pollid, int numfd)
static int Attach(XrdLink *lp)
static void Init(XrdSysError *eP, XrdOucTrace *tP, XrdScheduler *sP)
Definition XrdPoll.hh:69
virtual void Disable(XrdLink *lp, const char *etxt=0)=0
int numEnabled
Definition XrdPoll.hh:143
static XrdScheduler * XrdSched
Definition XrdPoll.hh:105
int CmdFD
Definition XrdPoll.hh:128
virtual int Include(XrdLink *lp)=0
static XrdSysError * XrdLog
Definition XrdPoll.hh:104
struct XrdPoll::PipeData::@161::@162 Arg
XrdSysSemaphore * theSem
Definition XrdPoll.hh:130
union XrdPoll::PipeData::@161 Parms