XRootD
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 <poll.h>
34
35#define XRD_NUMPOLLERS 3
36
37class XrdPollInfo;
38class XrdSysSemaphore;
39
41{
42public:
43
44// Attach() is called when a new link needs to be assigned to a poller
45//
46static int Attach(XrdPollInfo &pInfo);
47
48// Detach() is called when a link is being discarded
49//
50static void Detach(XrdPollInfo &pInfo);
51
52// Disable() is called when we need to mask interrupts from a link
53//
54virtual void Disable(XrdPollInfo &pInfo, const char *etxt=0) = 0;
55
56// Enable() is called when we want to receive interrupts from a link
57//
58virtual int Enable(XrdPollInfo &pInfo) = 0;
59
60// Finish() is called to allow a link to gracefully terminate when scheduled
61//
62static int Finish(XrdPollInfo &pInfo, const char *etxt=0); //Implementation supplied
63
64// Poll2Text() converts bits in an revents item to text
65//
66static char *Poll2Text(short events); // Implementation supplied
67
68// Setup() is called at config time to perform poller configuration
69//
70static int Setup(int numfd); // Implementation supplied
71
72// Start() is called via a thread for each poller that was created
73//
74virtual void Start(XrdSysSemaphore *syncp, int &rc) = 0;
75
76// Stats() is called to provide statistics on polling
77//
78static int Stats(char *buff, int blen, int do_sync=0);
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();
90virtual ~XrdPoll() {}
91
92protected:
93
94static 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//
102virtual void Exclude(XrdPollInfo &pInfo) = 0;
103
104// Include() called to include a link in a poll set
105//
106virtual 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//
111static XrdPoll *newPoller(int pollid, int numfd) /* = 0 */;
112
113// The following is common to all implementations
114//
116struct pollfd PipePoll;
117int CmdFD; // FD to send PipeData commands
118int ReqFD; // FD to recv PipeData requests
119struct PipeData {union {XrdSysSemaphore *theSem;
120 struct {int fd;
121 int ent;} Arg;
123 enum cmd {EnFD, DiFD, RmFD, Post};
125 };
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
136private:
137
138static XrdSysMutex doingAttach;
139 int numAttached; // Number of fd's attached to poller
140};
141#endif
#define XRD_NUMPOLLERS
Definition XrdPoll.hh:35
virtual ~XrdPoll()
Definition XrdPoll.hh:90
static const char * TraceID
Definition XrdPoll.hh:94
int numInterrupts
Definition XrdPoll.hh:134
virtual int Enable(XrdPollInfo &pInfo)=0
XrdPoll()
Definition XrdPoll.cc:118
static XrdPoll * Pollers[XRD_NUMPOLLERS]
Definition XrdPoll.hh:79
pthread_t TID
Definition XrdPoll.hh:83
int PID
Definition XrdPoll.hh:82
struct pollfd PipePoll
Definition XrdPoll.hh:116
virtual int Include(XrdPollInfo &pInfo)=0
virtual void Start(XrdSysSemaphore *syncp, int &rc)=0
XrdSysMutex PollPipe
Definition XrdPoll.hh:115
virtual void Exclude(XrdPollInfo &pInfo)=0
int ReqFD
Definition XrdPoll.hh:118
int PipeBlen
Definition XrdPoll.hh:128
int numEvents
Definition XrdPoll.hh:133
int getRequest()
Definition XrdPoll.cc:232
PipeData ReqBuff
Definition XrdPoll.hh:126
char * PipeBuff
Definition XrdPoll.hh:127
static char * Poll2Text(short events)
Definition XrdPoll.cc:272
static XrdPoll * newPoller(int pollid, int numfd)
Definition XrdPollE.icc:45
static int Finish(XrdPollInfo &pInfo, const char *etxt=0)
Definition XrdPoll.cc:204
static void Detach(XrdPollInfo &pInfo)
Definition XrdPoll.cc:177
int numEnabled
Definition XrdPoll.hh:132
int CmdFD
Definition XrdPoll.hh:117
static int Setup(int numfd)
Definition XrdPoll.cc:291
virtual void Disable(XrdPollInfo &pInfo, const char *etxt=0)=0
static int Stats(char *buff, int blen, int do_sync=0)
Definition XrdPoll.cc:332
static int Attach(XrdPollInfo &pInfo)
Definition XrdPoll.cc:144
union XrdPoll::PipeData::@6 Parms