Logo ROOT   6.07/09
Reference Guide
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 
37 class XrdOucTrace;
38 class XrdSysError;
39 class XrdLink;
40 class XrdScheduler;
41 class XrdSysSemaphore;
42 
43 class XrdPoll
44 {
45 public:
46 
47 // Attach() is called when a new link needs to be assigned to a poller
48 //
49 static int Attach(XrdLink *lp); // Implementation supplied
50 
51 // Detach() is called when a link is being discarded
52 //
53 static void Detach(XrdLink *lp); // Implementation supplied
54 
55 // Disable() is called when we need to mask interrupts from a link
56 //
57 virtual void Disable(XrdLink *lp, const char *etxt=0) = 0;
58 
59 // Enable() is called when we want to receive interrupts from a link
60 //
61 virtual int Enable(XrdLink *lp) = 0;
62 
63 // Finish() is called to allow a link to gracefully terminate when scheduled
64 //
65 static 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 //
69 static 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 //
74 static char *Poll2Text(short events); // Implementation supplied
75 
76 // Setup() is called at config time to perform poller configuration
77 //
78 static int Setup(int numfd); // Implementation supplied
79 
80 // Start() is called via a thread for each poller that was created
81 //
82 virtual void Start(XrdSysSemaphore *syncp, int &rc) = 0;
83 
84 // Stats() is called to provide statistics on polling
85 //
86 static 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 
97  XrdPoll();
98 virtual ~XrdPoll() {}
99 
100 protected:
101 
102 static const char *TraceID; // For tracing
103 static XrdOucTrace *XrdTrace;
105 static 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 //
113 virtual void Exclude(XrdLink *lp) = 0;
114 
115 // Include() called to include a link in a poll set
116 //
117 virtual 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 //
122 static XrdPoll *newPoller(int pollid, int numfd) /* = 0 */;
123 
124 // The following is common to all implementations
125 //
127 struct pollfd PipePoll;
128 int CmdFD; // FD to send PipeData commands
129 int ReqFD; // FD to recv PipeData requests
130 struct PipeData {union {XrdSysSemaphore *theSem;
131  struct {int fd;
132  int ent;} Arg;
133  } Parms;
134  enum cmd {EnFD, DiFD, RmFD, Post};
136  };
138 char *PipeBuff;
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 
147 private:
148 
150  int numAttached; // Number of fd's attached to poller
151 };
152 #endif
static XrdScheduler * XrdSched
Definition: XrdPoll.hh:105
int getRequest()
XrdSysMutex PollPipe
Definition: XrdPoll.hh:126
int numEnabled
Definition: XrdPoll.hh:143
virtual void Start(XrdSysSemaphore *syncp, int &rc)=0
static const char * TraceID
Definition: XrdPoll.hh:102
struct XrdPoll::PipeData::@175::@176 Arg
virtual void Exclude(XrdLink *lp)=0
static XrdOucTrace * XrdTrace
Definition: XrdPoll.hh:103
XrdSysSemaphore * theSem
Definition: XrdPoll.hh:130
static void Init(XrdSysError *eP, XrdOucTrace *tP, XrdScheduler *sP)
Definition: XrdPoll.hh:69
static int Setup(int numfd)
virtual ~XrdPoll()
Definition: XrdPoll.hh:98
int ReqFD
Definition: XrdPoll.hh:129
virtual int Include(XrdLink *lp)=0
union XrdPoll::PipeData::@175 Parms
static char * Poll2Text(short events)
static int Attach(XrdLink *lp)
static XrdSysError * XrdLog
Definition: XrdPoll.hh:104
#define XrdSysMutex
Definition: XrdSysToOuc.h:16
int numInterrupts
Definition: XrdPoll.hh:145
#define XrdSysError
Definition: XpdSysError.h:8
pthread_t TID
Definition: XrdPoll.hh:91
static void Detach(XrdLink *lp)
char * PipeBuff
Definition: XrdPoll.hh:138
virtual int Enable(XrdLink *lp)=0
int numAttached
Definition: XrdPoll.hh:150
struct pollfd PipePoll
Definition: XrdPoll.hh:127
static XrdSysMutex doingAttach
Definition: XrdPoll.hh:149
static int Stats(char *buff, int blen, int do_sync=0)
static XrdPoll * Pollers[XRD_NUMPOLLERS]
Definition: XrdPoll.hh:95
PipeData ReqBuff
Definition: XrdPoll.hh:137
#define XRD_NUMPOLLERS
Definition: XrdPoll.hh:35
int CmdFD
Definition: XrdPoll.hh:128
static XrdPoll * newPoller(int pollid, int numfd)
static int Finish(XrdLink *lp, const char *etxt=0)
int PipeBlen
Definition: XrdPoll.hh:139
virtual void Disable(XrdLink *lp, const char *etxt=0)=0
int numEvents
Definition: XrdPoll.hh:144
int PID
Definition: XrdPoll.hh:90