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