xrootd
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 XrdPollInfo;
38 class XrdSysSemaphore;
39 
40 class XrdPoll
41 {
42 public:
43 
44 // Attach() is called when a new link needs to be assigned to a poller
45 //
46 static int Attach(XrdPollInfo &pInfo);
47 
48 // Detach() is called when a link is being discarded
49 //
50 static void Detach(XrdPollInfo &pInfo);
51 
52 // Disable() is called when we need to mask interrupts from a link
53 //
54 virtual void Disable(XrdPollInfo &pInfo, const char *etxt=0) = 0;
55 
56 // Enable() is called when we want to receive interrupts from a link
57 //
58 virtual int Enable(XrdPollInfo &pInfo) = 0;
59 
60 // Finish() is called to allow a link to gracefully terminate when scheduled
61 //
62 static int Finish(XrdPollInfo &pInfo, const char *etxt=0); //Implementation supplied
63 
64 // Poll2Text() converts bits in an revents item to text
65 //
66 static char *Poll2Text(short events); // Implementation supplied
67 
68 // Setup() is called at config time to perform poller configuration
69 //
70 static int Setup(int numfd); // Implementation supplied
71 
72 // Start() is called via a thread for each poller that was created
73 //
74 virtual void Start(XrdSysSemaphore *syncp, int &rc) = 0;
75 
76 // Stats() is called to provide statistics on polling
77 //
78 static int Stats(char *buff, int blen, int do_sync=0);
79 
80 // Identification of the thread handling this object
81 //
82  int PID; // Poller ID
83  pthread_t TID; // Thread ID
84 
85 // The following table reference the pollers in effect
86 //
88 
89  XrdPoll();
90 virtual ~XrdPoll() {}
91 
92 protected:
93 
94 static const char *TraceID; // For tracing
95 
96 // Gets the next request on the poll pipe. This is common to all implentations.
97 //
98  int getRequest(); // Implementation supplied
99 
100 // Exclude() called to exclude a link from a poll set
101 //
102 virtual void Exclude(XrdPollInfo &pInfo) = 0;
103 
104 // Include() called to include a link in a poll set
105 //
106 virtual int Include(XrdPollInfo &pInfo) = 0;
107 
108 // newPoller() called to get a new poll object at initialization time
109 // Even though static, an implementation must be supplied.
110 //
111 static XrdPoll *newPoller(int pollid, int numfd) /* = 0 */;
112 
113 // The following is common to all implementations
114 //
116 struct pollfd PipePoll;
117 int CmdFD; // FD to send PipeData commands
118 int ReqFD; // FD to recv PipeData requests
120  struct {int fd;
121  int ent;} Arg;
122  } Parms;
123  enum cmd {EnFD, DiFD, RmFD, Post};
125  };
127 char *PipeBuff;
129 
130 // The following are statistical counters each implementation must maintain
131 //
132  int numEnabled; // Count of Enable() calls
133  int numEvents; // Count of poll fd's dispatched
134  int numInterrupts; // Number of interrupts (e.g., signals)
135 
136 private:
137 
139  int numAttached; // Number of fd's attached to poller
140 };
141 #endif
static int Attach(XrdPollInfo &pInfo)
int getRequest()
virtual void Exclude(XrdPollInfo &pInfo)=0
virtual int Enable(XrdPollInfo &pInfo)=0
XrdSysMutex PollPipe
Definition: XrdPoll.hh:115
int numEnabled
Definition: XrdPoll.hh:132
virtual void Start(XrdSysSemaphore *syncp, int &rc)=0
static const char * TraceID
Definition: XrdPoll.hh:94
struct XrdPoll::PipeData::@14::@15 Arg
XrdSysSemaphore * theSem
Definition: XrdPoll.hh:119
static int Setup(int numfd)
virtual ~XrdPoll()
Definition: XrdPoll.hh:90
int fd
Definition: XrdPoll.hh:120
int ReqFD
Definition: XrdPoll.hh:118
union XrdPoll::PipeData::@14 Parms
Definition: XrdPoll.hh:119
Definition: XrdPollInfo.hh:36
Definition: XrdPoll.hh:123
static char * Poll2Text(short events)
Definition: XrdPoll.hh:123
Definition: XrdSysPthread.hh:165
Definition: XrdPoll.hh:40
Definition: XrdPoll.hh:123
virtual void Disable(XrdPollInfo &pInfo, const char *etxt=0)=0
Definition: XrdSysPthread.hh:405
int numInterrupts
Definition: XrdPoll.hh:134
pthread_t TID
Definition: XrdPoll.hh:83
static int Finish(XrdPollInfo &pInfo, const char *etxt=0)
cmd req
Definition: XrdPoll.hh:124
Definition: XrdPoll.hh:123
int ent
Definition: XrdPoll.hh:121
char * PipeBuff
Definition: XrdPoll.hh:127
int numAttached
Definition: XrdPoll.hh:139
static void Detach(XrdPollInfo &pInfo)
struct pollfd PipePoll
Definition: XrdPoll.hh:116
static XrdSysMutex doingAttach
Definition: XrdPoll.hh:138
static int Stats(char *buff, int blen, int do_sync=0)
static XrdPoll * Pollers[XRD_NUMPOLLERS]
Definition: XrdPoll.hh:87
PipeData ReqBuff
Definition: XrdPoll.hh:126
cmd
Definition: XrdPoll.hh:123
#define XRD_NUMPOLLERS
Definition: XrdPoll.hh:35
int CmdFD
Definition: XrdPoll.hh:117
static XrdPoll * newPoller(int pollid, int numfd)
int PipeBlen
Definition: XrdPoll.hh:128
virtual int Include(XrdPollInfo &pInfo)=0
int numEvents
Definition: XrdPoll.hh:133
int PID
Definition: XrdPoll.hh:82