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