xrootd
Main Page
Namespaces
Classes
Files
File List
File Members
src
Xrd
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-AC03-76-SFO0515 with the Department of Energy */
10
/******************************************************************************/
11
12
#include <sys/poll.h>
13
#include "
XrdSys/XrdSysPthread.hh
"
14
15
#define XRD_NUMPOLLERS 3
16
17
class
XrdOucTrace
;
18
class
XrdSysError
;
19
class
XrdLink
;
20
class
XrdScheduler
;
21
class
XrdSysSemaphore
;
22
23
class
XrdPoll
24
{
25
public
:
26
27
// Attach() is called when a new link needs to be assigned to a poller
28
//
29
static
int
Attach
(
XrdLink
*lp);
// Implementation supplied
30
31
// Detach() is called when a link is being discarded
32
//
33
static
void
Detach
(
XrdLink
*lp);
// Implementation supplied
34
35
// Disable() is called when we need to mask interrupts from a link
36
//
37
virtual
void
Disable
(
XrdLink
*lp,
const
char
*etxt=0) = 0;
38
39
// Enable() is called when we want to receive interrupts from a link
40
//
41
virtual
int
Enable
(
XrdLink
*lp) = 0;
42
43
// Finish() is called to allow a link to gracefully terminate when scheduled
44
//
45
static
int
Finish
(
XrdLink
*lp,
const
char
*etxt=0);
//Implementation supplied
46
47
// Init() is called to set pointers to external interfaces at config time.
48
//
49
static
void
Init
(
XrdSysError
*eP,
XrdOucTrace
*tP,
XrdScheduler
*sP)
50
{
XrdLog
= eP;
XrdTrace
= tP;
XrdSched
= sP;}
51
52
// Poll2Text() converts bits in an revents item to text
53
//
54
static
char
*
Poll2Text
(
short
events);
// Implementation supplied
55
56
// Setup() is called at config time to perform poller configuration
57
//
58
static
int
Setup
(
int
numfd);
// Implementation supplied
59
60
// Start() is called via a thread for each poller that was created
61
//
62
virtual
void
Start
(
XrdSysSemaphore
*syncp,
int
&rc) = 0;
63
64
// Stats() is called to provide statistics on polling
65
//
66
static
int
Stats
(
char
*buff,
int
blen,
int
do_sync=0);
67
68
// Identification of the thread handling this object
69
//
70
int
PID
;
// Poller ID
71
pthread_t
TID
;
// Thread ID
72
73
// The following table reference the pollers in effect
74
//
75
static
XrdPoll
*
Pollers
[
XRD_NUMPOLLERS
];
76
77
XrdPoll
();
78
virtual
~XrdPoll
() {}
79
80
protected
:
81
82
static
const
char
*
TraceID
;
// For tracing
83
static
XrdOucTrace
*
XrdTrace
;
84
static
XrdSysError
*
XrdLog
;
85
static
XrdScheduler
*
XrdSched
;
86
87
// Gets the next request on the poll pipe. This is common to all implentations.
88
//
89
int
getRequest
();
// Implementation supplied
90
91
// Exclude() called to exclude a link from a poll set
92
//
93
virtual
void
Exclude
(
XrdLink
*lp) = 0;
94
95
// Include() called to include a link in a poll set
96
//
97
virtual
int
Include
(
XrdLink
*lp) = 0;
98
99
// newPoller() called to get a new poll object at initialization time
100
// Even though static, an implementation must be supplied.
101
//
102
static
XrdPoll
*
newPoller
(
int
pollid,
int
numfd)
/* = 0 */
;
103
104
// The following is common to all implementations
105
//
106
XrdSysMutex
PollPipe
;
107
struct
pollfd
PipePoll
;
108
int
CmdFD
;
// FD to send PipeData commands
109
int
ReqFD
;
// FD to recv PipeData requests
110
struct
PipeData
{
union
{
XrdSysSemaphore
*
theSem
;
111
struct
{
int
fd
;
112
int
ent
;}
Arg
;
113
}
Parms
;
114
enum
cmd
{
EnFD
,
DiFD
,
RmFD
,
Post
};
115
cmd
req
;
116
};
117
PipeData
ReqBuff
;
118
char
*
PipeBuff
;
119
int
PipeBlen
;
120
121
// The following are statistical counters each implementation must maintain
122
//
123
int
numEnabled
;
// Count of Enable() calls
124
int
numEvents
;
// Count of poll fd's dispatched
125
int
numInterrupts
;
// Number of interrupts (e.g., signals)
126
127
private
:
128
129
static
XrdSysMutex
doingAttach
;
130
int
numAttached
;
// Number of fd's attached to poller
131
};
132
#endif
Generated by
1.8.1.2