xrootd
Main Page
Namespaces
Classes
Files
File List
File Members
src
Xrd
XrdLink.hh
Go to the documentation of this file.
1
#ifndef __XRD_LINK_H__
2
#define __XRD_LINK_H__
3
/******************************************************************************/
4
/* */
5
/* X r d L i n k . 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/socket.h>
33
#include <sys/types.h>
34
#include <fcntl.h>
35
#include <time.h>
36
37
#include "
XrdSys/XrdSysPthread.hh
"
38
39
#include "
Xrd/XrdJob.hh
"
40
#include "
Xrd/XrdLinkMatch.hh
"
41
#include "
Xrd/XrdProtocol.hh
"
42
43
/******************************************************************************/
44
/* X r d L i n k O p t i o n s */
45
/******************************************************************************/
46
47
#define XRDLINK_RDLOCK 0x0001
48
#define XRDLINK_NOCLOSE 0x0002
49
50
/******************************************************************************/
51
/* C l a s s D e f i n i t i o n */
52
/******************************************************************************/
53
54
class
XrdInet;
55
class
XrdNetBuffer;
56
class
XrdNetPeer;
57
class
XrdPoll;
58
class
XrdOucTrace
;
59
class
XrdScheduler
;
60
class
XrdSysError
;
61
62
class
XrdLink
:
XrdJob
63
{
64
public
:
65
friend
class
XrdLinkScan
;
66
friend
class
XrdPoll
;
67
friend
class
XrdPollPoll
;
68
friend
class
XrdPollDev
;
69
friend
class
XrdPollE
;
70
71
static
XrdLink
*
Alloc
(XrdNetPeer &Peer,
int
opts=0);
72
73
void
Bind
();
74
void
Bind
(pthread_t tid);
75
76
int
Client
(
char
*buff,
int
blen);
77
78
int
Close
(
int
defer=0);
79
80
void
DoIt
();
81
82
int
FDnum
() {
return
FD
;}
83
84
static
XrdLink
*
fd2link
(
int
fd)
85
{
if
(fd < 0) fd = -fd;
86
return
(fd <=
LTLast
&&
LinkBat
[fd] ?
LinkTab
[fd] : 0);
87
}
88
89
static
XrdLink
*
fd2link
(
int
fd,
unsigned
int
inst)
90
{
if
(fd < 0) fd = -fd;
91
if
(fd <=
LTLast
&&
LinkBat
[fd] &&
LinkTab
[fd]
92
&&
LinkTab
[fd]->
Instance
== inst)
return
LinkTab
[fd];
93
return
(
XrdLink
*)0;
94
}
95
96
static
XrdLink
*
Find
(
int
&curr,
XrdLinkMatch
*who=0);
97
98
int
getIOStats
(
long
long
&inbytes,
long
long
&outbytes,
99
int
&numstall,
int
&numtardy)
100
{ inbytes =
BytesIn
+
BytesInTot
;
101
outbytes =
BytesOut
+
BytesOutTot
;
102
numstall =
stallCnt
+
stallCntTot
;
103
numtardy =
tardyCnt
+
tardyCntTot
;
104
return
InUse
;
105
}
106
107
static
int
getName
(
int
&curr,
char
*bname,
int
blen,
XrdLinkMatch
*who=0);
108
109
XrdProtocol
*
getProtocol
() {
return
Protocol
;}
// opmutex must be locked
110
111
void
Hold
(
int
lk) {(lk ?
opMutex
.
Lock
() :
opMutex
.
UnLock
());}
112
113
char
*
ID
;
// This is referenced a lot
114
115
static
void
Init
(
XrdSysError
*eP,
XrdOucTrace
*tP,
XrdScheduler
*sP)
116
{
XrdLog
= eP;
XrdTrace
= tP;
XrdSched
= sP;}
117
118
static
void
Init
(XrdInet *iP) {
XrdNetTCP
= iP;}
119
120
unsigned
int
Inst
() {
return
Instance
;}
121
122
int
isFlawed
() {
return
Etext
!= 0;}
123
124
int
isInstance
(
unsigned
int
inst)
125
{
return
FD
>= 0 &&
Instance
== inst;}
126
127
const
char
*
Name
(sockaddr *ipaddr=0)
128
{
if
(ipaddr) memcpy(ipaddr, &
InetAddr
,
sizeof
(sockaddr));
129
return
(
const
char
*)
Lname
;
130
}
131
132
const
char
*
Host
(sockaddr *ipaddr=0)
133
{
if
(ipaddr) memcpy(ipaddr, &
InetAddr
,
sizeof
(sockaddr));
134
return
(
const
char
*)
HostName
;
135
}
136
137
int
Peek
(
char
*buff,
int
blen,
int
timeout=-1);
138
139
int
Recv
(
char
*buff,
int
blen);
140
int
Recv
(
char
*buff,
int
blen,
int
timeout);
141
142
int
RecvAll
(
char
*buff,
int
blen,
int
timeout=-1);
143
144
int
Send
(
const
char
*buff,
int
blen);
145
int
Send
(
const
struct
iovec *iov,
int
iocnt,
int
bytes=0);
146
147
struct
sfVec
{
union
{
char
*
buffer
;
// ->Data if fdnum < 0
148
off_t
offset
;
// File offset of data
149
};
150
int
sendsz
;
// Length of data at offset
151
int
fdnum
;
// File descriptor for data
152
};
153
static
const
int
sfMax
= 8;
154
155
static
int
sfOK
;
// True if Send(sfVec) enabled
156
157
int
Send
(
const
struct
sfVec
*sdP,
int
sdn);
// Iff sfOK > 0
158
159
void
Serialize
();
// ASYNC Mode
160
161
int
setEtext
(
const
char
*text);
162
163
void
setID
(
const
char
*userid,
int
procid);
164
165
static
void
setKWT
(
int
wkSec,
int
kwSec);
166
167
XrdProtocol
*
setProtocol
(
XrdProtocol
*pp);
168
169
void
setRef
(
int
cnt);
// ASYNC Mode
170
171
static
int
Setup
(
int
maxfd,
int
idlewait);
172
173
static
int
Stats
(
char
*buff,
int
blen,
int
do_sync=0);
174
175
void
syncStats
(
int
*ctime=0);
176
177
int
Terminate
(
const
XrdLink
*owner,
int
fdnum,
unsigned
int
inst);
178
179
time_t
timeCon
() {
return
conTime
;}
180
181
int
UseCnt
() {
return
InUse
;}
182
183
XrdLink
();
184
~XrdLink
() {}
// Is never deleted!
185
186
private
:
187
188
void
Reset
();
189
int
sendData
(
const
char
*Buff,
int
Blen);
190
191
static
XrdSysError
*
XrdLog
;
192
static
XrdOucTrace
*
XrdTrace
;
193
static
XrdScheduler
*
XrdSched
;
194
static
XrdInet *
XrdNetTCP
;
195
196
static
XrdSysMutex
LTMutex
;
// For the LinkTab only LTMutex->IOMutex allowed
197
static
XrdLink
**
LinkTab
;
198
static
char
*
LinkBat
;
199
static
unsigned
int
LinkAlloc
;
200
static
int
LTLast
;
201
static
const
char
*
TraceID
;
202
static
int
devNull
;
203
static
short
killWait
;
204
static
short
waitKill
;
205
206
// Statistical area (global and local)
207
//
208
static
long
long
LinkBytesIn
;
209
static
long
long
LinkBytesOut
;
210
static
long
long
LinkConTime
;
211
static
long
long
LinkCountTot
;
212
static
int
LinkCount
;
213
static
int
LinkCountMax
;
214
static
int
LinkTimeOuts
;
215
static
int
LinkStalls
;
216
static
int
LinkSfIntr
;
217
long
long
BytesIn
;
218
long
long
BytesInTot
;
219
long
long
BytesOut
;
220
long
long
BytesOutTot
;
221
int
stallCnt
;
222
int
stallCntTot
;
223
int
tardyCnt
;
224
int
tardyCntTot
;
225
int
SfIntr
;
226
static
XrdSysMutex
statsMutex
;
227
228
// Identification section
229
//
230
struct
sockaddr
InetAddr
;
231
char
Uname
[24];
// Uname and Lname must be adjacent!
232
char
Lname
[232];
233
char
*
HostName
;
234
int
HNlen
;
235
pthread_t
TID
;
236
237
XrdSysMutex
opMutex
;
238
XrdSysMutex
rdMutex
;
239
XrdSysMutex
wrMutex
;
240
XrdSysSemaphore
IOSemaphore
;
241
XrdSysCondVar
*
KillcvP
;
// Protected by opMutex!
242
XrdLink
*
Next
;
243
XrdNetBuffer *
udpbuff
;
244
XrdProtocol
*
Protocol
;
245
XrdProtocol
*
ProtoAlt
;
246
XrdPoll
*
Poller
;
247
struct
pollfd *
PollEnt
;
248
char
*
Etext
;
249
int
FD
;
250
unsigned
int
Instance
;
251
time_t
conTime
;
252
int
InUse
;
253
int
doPost
;
254
char
LockReads
;
255
char
KeepFD
;
256
char
isEnabled
;
257
char
isIdle
;
258
char
inQ
;
259
char
tBound
;
260
char
KillCnt
;
// Protected by opMutex!
261
static
const
char
KillMax
= 60;
262
static
const
char
KillMsk
= 0x7f;
263
static
const
char
KillXwt
= 0x80;
264
};
265
#endif
Generated by
1.8.4