xrootd
Main Page
Namespaces
Classes
Files
File List
File Members
src
XrdClient
XrdClientPhyConnection.hh
Go to the documentation of this file.
1
2
// //
3
// XrdClientPhyConnection //
4
// Author: Fabrizio Furano (INFN Padova, 2004) //
5
// Adapted from TXNetFile (root.cern.ch) originally done by //
6
// Alvise Dorigo, Fabrizio Furano //
7
// INFN Padova, 2003 //
8
// //
9
// Class handling physical connections to xrootd servers //
10
// //
12
13
// $Id$
14
15
#ifndef _XrdClientPhyConnection
16
#define _XrdClientPhyConnection
17
18
#include "
XrdClient/XrdClientPSock.hh
"
19
#include "
XrdClient/XrdClientMessage.hh
"
20
#include "
XrdClient/XrdClientUnsolMsg.hh
"
21
#include "
XrdClient/XrdClientInputBuffer.hh
"
22
#include "
XrdClient/XrdClientUrlInfo.hh
"
23
#include "
XrdClient/XrdClientThread.hh
"
24
#include "
XrdSys/XrdSysPthread.hh
"
25
#include "
XrdSys/XrdSysSemWait.hh
"
26
27
#include <time.h>
// for time_t data type
28
29
enum
ELoginState
{
30
kNo
= 0,
31
kYes
= 1,
32
kPending
= 2
33
};
34
35
enum
ERemoteServerType
{
36
kSTError
= -1,
// Some error occurred: server type undetermined
37
kSTNone
= 0,
// Remote server type un-recognized
38
kSTRootd
= 1,
// Remote server type: old rootd server
39
kSTBaseXrootd
= 2,
// Remote server type: xrootd dynamic load balancer
40
kSTDataXrootd
= 3,
// Remote server type: xrootd data server
41
kSTMetaXrootd
= 4
// Remote server type: xrootd meta manager
42
};
43
44
class
XrdClientSid
;
45
class
XrdSecProtocol
;
46
47
class
XrdClientPhyConnection
:
public
XrdClientUnsolMsgSender
{
48
49
private
:
50
time_t
fLastUseTimestamp
;
51
enum
ELoginState
fLogged
;
// only 1 login/auth is needed for physical
52
XrdSecProtocol
*
fSecProtocol
;
// authentication protocol
53
54
XrdClientInputBuffer
55
fMsgQ
;
// The queue used to hold incoming messages
56
57
int
fRequestTimeout
;
58
bool
fMStreamsGoing
;
59
XrdSysRecMutex
fRwMutex
;
// Lock before using the physical channel
60
// (for reading and/or writing)
61
62
XrdSysRecMutex
fMutex
;
63
XrdSysRecMutex
fMultireadMutex
;
// Used to arbitrate between multiple
64
// threads reading msgs from the same conn
65
66
XrdClientThread
*
fReaderthreadhandler
[64];
// The thread which is going to pump
67
// out the data from the socket
68
69
int
fReaderthreadrunning
;
70
71
XrdClientUrlInfo
fServer
;
72
73
XrdClientSock
*
fSocket
;
74
75
UnsolRespProcResult
HandleUnsolicited
(
XrdClientMessage
*m);
76
77
XrdSysSemWait
fReaderCV
;
78
79
short
fLogConnCnt
;
// Number of logical connections using this phyconn
80
81
XrdClientSid
*
fSidManager
;
82
83
public
:
84
long
fServerProto
;
// The server protocol
85
ERemoteServerType
fServerType
;
86
long
fTTLsec
;
87
88
XrdClientPhyConnection
(
XrdClientAbsUnsolMsgHandler
*h,
XrdClientSid
*sid);
89
~XrdClientPhyConnection
();
90
91
XrdClientMessage
*
BuildMessage
(
bool
IgnoreTimeouts,
bool
Enqueue);
92
bool
CheckAutoTerm
();
93
94
bool
Connect
(
XrdClientUrlInfo
RemoteHost,
bool
isUnix = 0);
95
96
//--------------------------------------------------------------------------
104
//--------------------------------------------------------------------------
105
bool
Connect
(
XrdClientUrlInfo
RemoteHost,
bool
isUnix ,
int
fd );
106
107
void
CountLogConn
(
int
d = 1);
108
void
Disconnect
();
109
110
ERemoteServerType
111
DoHandShake
(
ServerInitHandShake
&xbody,
112
int
substreamid = 0);
113
114
bool
ExpiredTTL
();
115
short
GetLogConnCnt
()
const
{
return
fLogConnCnt
; }
116
int
GetReaderThreadsCnt
() {
XrdSysMutexHelper
l(
fMutex
);
return
fReaderthreadrunning
; }
117
118
long
GetTTL
() {
return
fTTLsec
; }
119
120
XrdSecProtocol
*
GetSecProtocol
()
const
{
return
fSecProtocol
; }
121
int
GetSocket
() {
return
fSocket
?
fSocket
->
fSocket
: -1; }
122
123
// Tells to the sock to rebuild the list of interesting selectors
124
void
ReinitFDTable
() {
if
(
fSocket
)
fSocket
->
ReinitFDTable
(); }
125
126
int
SaveSocket
() {
fTTLsec
= 0;
return
fSocket
? (
fSocket
->
SaveSocket
()) : -1; }
127
void
SetInterrupt
() {
if
(
fSocket
)
fSocket
->
SetInterrupt
(); }
128
void
SetSecProtocol
(
XrdSecProtocol
*sp) {
fSecProtocol
= sp; }
129
130
void
StartedReader
();
131
132
bool
IsAddress
(
const
XrdOucString
&addr) {
133
return
( (
fServer
.
Host
== addr) ||
134
(
fServer
.
HostAddr
== addr) );
135
}
136
137
ELoginState
IsLogged
();
138
139
bool
IsPort
(
int
port
) {
return
(
fServer
.
Port
== port); };
140
bool
IsUser
(
const
XrdOucString
&usr) {
return
(
fServer
.
User
== usr); };
141
bool
IsValid
();
142
143
144
void
LockChannel
();
145
146
// see XrdClientSock for the meaning of the parameters
147
int
ReadRaw
(
void
*buffer,
int
BufferLength,
int
substreamid = -1,
148
int
*usedsubstreamid = 0);
149
150
XrdClientMessage
*
ReadMessage
(
int
streamid);
151
bool
ReConnect
(
XrdClientUrlInfo
RemoteHost);
152
void
SetLogged
(
ELoginState
status) {
fLogged
= status; }
153
inline
void
SetTTL
(
long
ttl) {
fTTLsec
= ttl; }
154
void
StartReader
();
155
void
Touch
();
156
void
UnlockChannel
();
157
int
WriteRaw
(
const
void
*buffer,
int
BufferLength,
int
substreamid = 0);
158
159
int
TryConnectParallelStream
(
int
port
,
int
windowsz,
int
sockid) {
return
(
fSocket
?
fSocket
->
TryConnectParallelSock
(port, windowsz, sockid) : -1); }
160
int
EstablishPendingParallelStream
(
int
tmpid,
int
newid) {
return
(
fSocket
?
fSocket
->
EstablishParallelSock
(tmpid, newid) : -1); }
161
void
RemoveParallelStream
(
int
substreamid) {
if
(
fSocket
)
fSocket
->
RemoveParallelSock
(substreamid); }
162
// Tells if the attempt to establish the parallel streams is ongoing or was done
163
// and mark it as ongoing or done
164
bool
TestAndSetMStreamsGoing
();
165
166
int
GetSockIdHint
(
int
reqsperstream) {
return
(
fSocket
?
fSocket
->
GetSockIdHint
(reqsperstream) : 0); }
167
int
GetSockIdCount
() {
return
(
fSocket
?
fSocket
->
GetSockIdCount
() : 0); }
168
void
PauseSelectOnSubstream
(
int
substreamid) {
if
(
fSocket
)
fSocket
->
PauseSelectOnSubstream
(substreamid); }
169
void
RestartSelectOnSubstream
(
int
substreamid) {
if
(
fSocket
)
fSocket
->
RestartSelectOnSubstream
(substreamid); }
170
171
// To prohibit/re-enable a socket descriptor from being looked at by the reader threads
172
virtual
void
BanSockDescr
(
int
sockdescr,
int
sockid) {
if
(
fSocket
)
fSocket
->
BanSockDescr
(sockdescr, sockid); }
173
virtual
void
UnBanSockDescr
(
int
sockdescr) {
if
(
fSocket
)
fSocket
->
UnBanSockDescr
(sockdescr); }
174
175
void
ReadLock
() {
fMultireadMutex
.
Lock
(); }
176
void
ReadUnLock
() {
fMultireadMutex
.
UnLock
(); }
177
178
int
WipeStreamid
(
int
streamid) {
return
fMsgQ
.
WipeStreamid
(streamid); }
179
};
180
181
182
183
184
//
185
// Class implementing a trick to automatically unlock an XrdClientPhyConnection
186
//
187
class
XrdClientPhyConnLocker
{
188
private
:
189
XrdClientPhyConnection
*
phyconn
;
190
191
public
:
192
XrdClientPhyConnLocker
(
XrdClientPhyConnection
*phyc) {
193
// Constructor
194
phyconn
= phyc;
195
phyconn
->
LockChannel
();
196
}
197
198
~XrdClientPhyConnLocker
(){
199
// Destructor.
200
phyconn
->
UnlockChannel
();
201
}
202
203
};
204
205
206
#endif
Generated by
1.8.1.2