xrootd
Main Page
Namespaces
Classes
Files
File List
File Members
src
XrdSys
XrdSysIOEvents.hh
Go to the documentation of this file.
1
#ifndef __XRDSYSIOEVENTS_HH__
2
#define __XRDSYSIOEVENTS_HH__
3
/******************************************************************************/
4
/* */
5
/* X r d S y s I O E v e n t s . h h */
6
/* */
7
/* (c) 2012 by the Board of Trustees of the Leland Stanford, Jr., University */
8
/* All Rights Reserved */
9
/* Produced by Andrew Hanushevsky for Stanford University under contract */
10
/* DE-AC02-76-SFO0515 with the Department of Energy */
11
/* */
12
/* This file is part of the XRootD software suite. */
13
/* */
14
/* XRootD is free software: you can redistribute it and/or modify it under */
15
/* the terms of the GNU Lesser General Public License as published by the */
16
/* Free Software Foundation, either version 3 of the License, or (at your */
17
/* option) any later version. */
18
/* */
19
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22
/* License for more details. */
23
/* */
24
/* You should have received a copy of the GNU Lesser General Public License */
25
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27
/* */
28
/* The copyright holder's institutional names and contributor's names may not */
29
/* be used to endorse or promote products derived from this software without */
30
/* specific prior written permission of the institution or contributor. */
31
/******************************************************************************/
32
33
#include <poll.h>
34
#include <time.h>
35
#include <sys/types.h>
36
37
#include "
XrdSys/XrdSysPthread.hh
"
38
39
//-----------------------------------------------------------------------------
53
//-----------------------------------------------------------------------------
54
55
namespace
XrdSys
56
{
57
namespace
IOEvents
58
{
59
60
/******************************************************************************/
61
/* C l a s s C a l l B a c k */
62
/******************************************************************************/
63
64
//-----------------------------------------------------------------------------
74
//-----------------------------------------------------------------------------
75
76
class
Channel
;
77
class
CallBack
78
{
79
public
:
80
81
//-----------------------------------------------------------------------------
83
//-----------------------------------------------------------------------------
84
85
enum
EventType
86
{
87
ReadyToRead
= 0x01,
88
ReadTimeOut
= 0x02,
89
ReadyToWrite
= 0x04,
90
WriteTimeOut
= 0x08
91
};
92
93
//-----------------------------------------------------------------------------
110
//-----------------------------------------------------------------------------
111
112
virtual
bool
Event
(
Channel
*chP,
void
*cbArg,
int
evFlags) = 0;
113
114
//-----------------------------------------------------------------------------
125
//-----------------------------------------------------------------------------
126
127
virtual
void
Fatal
(
Channel
*chP,
void
*cbArg,
int
eNum,
const
char
*eTxt)
128
{
129
(void)chP; (void)cbArg; (void)eNum; (void)eTxt;
130
};
131
132
//-----------------------------------------------------------------------------
140
//-----------------------------------------------------------------------------
141
142
virtual
void
Stop
(
Channel
*chP,
void
*cbArg)
143
{
144
(void)chP; (void)cbArg;
145
}
146
147
//-----------------------------------------------------------------------------
149
//-----------------------------------------------------------------------------
150
151
CallBack
() {}
152
153
//-----------------------------------------------------------------------------
155
//-----------------------------------------------------------------------------
156
157
virtual
~CallBack
() {}
158
};
159
160
/******************************************************************************/
161
/* C l a s s C h a n n e l */
162
/******************************************************************************/
163
164
//-----------------------------------------------------------------------------
168
//-----------------------------------------------------------------------------
169
170
class
ChannelWait;
171
class
Poller;
172
class
Channel
173
{
174
friend
class
Poller
;
175
public
:
176
177
//-----------------------------------------------------------------------------
179
//-----------------------------------------------------------------------------
180
181
enum
EventCode
{
readEvents
= 0x01,
182
writeEvents
= 0x04,
183
rwEvents
= 0x05,
184
errorEvents
= 0x10,
185
stopEvent
= 0x20,
186
allEvents
= 0x35
187
};
188
189
//-----------------------------------------------------------------------------
199
//-----------------------------------------------------------------------------
200
201
bool
Disable
(
int
events,
const
char
**eText=0);
202
203
//-----------------------------------------------------------------------------
235
//-----------------------------------------------------------------------------
236
237
bool
Enable
(
int
events,
int
timeout=0,
const
char
**eText=0);
238
239
//-----------------------------------------------------------------------------
244
//-----------------------------------------------------------------------------
245
246
void
GetCallBack
(
CallBack
**cbP,
void
**cbArg);
247
248
//-----------------------------------------------------------------------------
254
//-----------------------------------------------------------------------------
255
256
int
GetEvents
() {
return
(
chPoller
? static_cast<int>(
chEvents
) : -1);}
257
258
//-----------------------------------------------------------------------------
263
//-----------------------------------------------------------------------------
264
265
int
GetFD
() {
return
chFD
;}
266
267
//-----------------------------------------------------------------------------
274
//-----------------------------------------------------------------------------
275
276
void
SetCallBack
(
CallBack
*cbP,
void
*cbArg=0);
277
278
//-----------------------------------------------------------------------------
287
//-----------------------------------------------------------------------------
288
289
void
SetFD
(
int
fd);
290
291
//-----------------------------------------------------------------------------
306
//-----------------------------------------------------------------------------
307
308
Channel
(
Poller
*pollP,
int
fd,
CallBack
*cbP=0,
void
*cbArg=0);
309
310
//-----------------------------------------------------------------------------
314
//-----------------------------------------------------------------------------
315
316
~Channel
();
317
318
private
:
319
320
struct
dlQ
{
Channel
*
next
;
Channel
*
prev
;};
321
322
XrdSysRecMutex
chMutex
;
323
324
dlQ
attList
;
// List of attached channels
325
dlQ
tmoList
;
// List of channels in the timeout queue
326
327
Poller
*
chPoller
;
// The effective poller
328
Poller
*
chPollXQ
;
// The real poller
329
CallBack
*
chCB
;
// CallBack function
330
void
*
chCBA
;
// CallBack argument
331
int
chFD
;
// Associated file descriptor
332
int
pollEnt
;
// Used only for poll() type pollers
333
int
chRTO
;
// Read timeout value (0 means none)
334
int
chWTO
;
// Write timeout value (0 means none)
335
time_t
rdDL
;
// Read deadline
336
time_t
wrDL
;
// Write deadline
337
time_t
deadLine
;
// The deadline in effect (read or write)
338
char
dlType
;
// The deadline type in deadLine as CallBack type
339
char
chEvents
;
// Enabled events as Channel type
340
char
chStat
;
// Channel status below (!0 -> in callback mode)
341
enum
Status
{
isClear
= 0,
isCBMode
,
isDead
};
342
char
inTOQ
;
// True if the channel is in the timeout queue
343
char
inPSet
;
// FD is in the actual poll set
344
char
reMod
;
// Modify issued while defered, re-issue needed
345
short
chFault
;
// Defered error, 0 if all is well
346
347
void
Reset
(
Poller
*thePoller,
int
fd,
int
eNum=0);
348
};
349
350
/******************************************************************************/
351
/* C l a s s P o l l e r */
352
/******************************************************************************/
353
354
//-----------------------------------------------------------------------------
360
//-----------------------------------------------------------------------------
361
362
class
Poller
363
{
364
friend
class
BootStrap
;
365
friend
class
Channel
;
366
public
:
367
368
//-----------------------------------------------------------------------------
382
//-----------------------------------------------------------------------------
383
384
static
Poller
*
Create
(
int
&eNum,
const
char
**eTxt=0);
385
386
//-----------------------------------------------------------------------------
397
//-----------------------------------------------------------------------------
398
399
void
Stop
();
400
401
//-----------------------------------------------------------------------------
406
//-----------------------------------------------------------------------------
407
408
Poller
(
int
cFD,
int
rFD);
409
410
//-----------------------------------------------------------------------------
412
//-----------------------------------------------------------------------------
413
414
virtual
~Poller
() {}
415
416
protected
:
417
struct
PipeData;
418
419
void
CbkTMO
();
420
bool
CbkXeq
(
Channel
*cP,
int
events,
int
eNum,
const
char
*eTxt);
421
inline
int
GetFault
(
Channel
*cP) {
return
cP->
chFault
;}
422
inline
int
GetPollEnt
(
Channel
*cP) {
return
cP->
pollEnt
;}
423
int
GetRequest
();
424
bool
Init
(
Channel
*cP,
int
&eNum,
const
char
**eTxt,
bool
&isLockd);
425
inline
void
LockChannel
(
Channel
*cP) {cP->
chMutex
.
Lock
();}
426
int
Poll2Enum
(
short
events);
427
int
SendCmd
(PipeData &cmd);
428
void
SetPollEnt
(
Channel
*cP,
int
ptEnt);
429
bool
TmoAdd
(
Channel
*cP);
430
void
TmoDel
(
Channel
*cP);
431
int
TmoGet
();
432
inline
void
UnLockChannel
(
Channel
*cP) {cP->
chMutex
.
UnLock
();}
433
437
virtual
void
Begin
(
XrdSysSemaphore
*syncp,
int
&rc,
const
char
**eTxt) = 0;
438
443
virtual
void
Exclude
(
Channel
*cP,
bool
&isLocked,
bool
dover=1) = 0;
444
449
virtual
bool
Include
(
Channel
*cP,
450
int
&eNum,
451
const
char
**eTxt,
452
bool
&isLocked) = 0;
453
458
virtual
bool
Modify
(
Channel
*cP,
459
int
&eNum,
460
const
char
**eTxt,
461
bool
&isLocked) = 0;
462
467
//
468
virtual
void
Shutdown
() = 0;
469
470
// The following is common to all implementations
471
//
472
Channel
*
attBase
;
// -> First channel in attach queue or 0
473
Channel
*
tmoBase
;
// -> First channel in timeout queue or 0
474
475
pthread_t
pollTid
;
// Poller's thread ID
476
477
struct
pollfd
pipePoll
;
// Stucture to wait for pipe events
478
int
cmdFD
;
// FD to send PipeData commands
479
int
reqFD
;
// FD to recv PipeData requests
480
struct
PipeData
{
char
req
;
char
evt
;
short
ent
;
int
fd
;
481
XrdSysSemaphore
*
theSem
;
482
enum
cmd
{
NoOp
= 0,
MdFD
= 1,
Post
= 2,
483
MiFD
= 3,
RmFD
= 4,
Stop
= 5};
484
};
485
PipeData
reqBuff
;
// Buffer used by poller thread to recv data
486
char
*
pipeBuff
;
// Read resumption point in buffer
487
int
pipeBlen
;
// Number of outstanding bytes
488
bool
wakePend
;
// Wakeup is effectively pending (don't send)
489
bool
chDead
;
// True if channel deleted by callback
490
491
static
time_t
maxTime
;
// Maximum time allowed
492
493
private
:
494
495
void
Attach
(
Channel
*cP);
496
void
Detach
(
Channel
*cP,
bool
&isLocked,
bool
keep=
true
);
497
void
WakeUp
();
498
499
// newPoller() called to get a specialized new poll object at in response to
500
// Create(). A specialized implementation must be supplied.
501
//
502
static
Poller
*
newPoller
(
int
pFD[2],
int
&eNum,
const
char
**eTxt);
503
504
XrdSysMutex
adMutex
;
// Mutex for adding & detaching channels
505
XrdSysMutex
toMutex
;
// Mutex for handling the timeout list
506
};
507
};
508
};
509
#endif
Generated by
1.8.3.1