xrootd
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
47
48#include <time.h> // for time_t data type
49
51 kNo = 0,
52 kYes = 1,
53 kPending = 2
54};
55
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
65class XrdClientSid;
66class XrdClientThread;
67class XrdSecProtocol;
68
70
71private:
73 enum ELoginState fLogged; // only 1 login/auth is needed for physical
74 XrdSecProtocol *fSecProtocol; // authentication protocol
75
77 fMsgQ; // The queue used to hold incoming messages
78
81 XrdSysRecMutex fRwMutex; // Lock before using the physical channel
82 // (for reading and/or writing)
83
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
92
94
96
98
100
101 short fLogConnCnt; // Number of logical connections using this phyconn
102
104
105public:
106 long fServerProto; // The server protocol
109
112
113 XrdClientMessage *BuildMessage(bool IgnoreTimeouts, bool Enqueue);
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);
131
134 int substreamid = 0);
135
137 short GetLogConnCnt() const { return fLogConnCnt; }
139
140 long GetTTL() { return fTTLsec; }
141
143 int GetSocket() { return fSocket ? fSocket->fSocket : -1; }
144
145 // Tells to the sock to rebuild the list of interesting selectors
147
148 int SaveSocket() { fTTLsec = 0; return fSocket ? (fSocket->SaveSocket()) : -1; }
151
153
154 bool IsAddress(const XrdOucString &addr) {
155 return ( (fServer.Host == addr) ||
156 (fServer.HostAddr == addr) );
157 }
158
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
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
173 bool ReConnect(XrdClientUrlInfo RemoteHost);
174 void SetLogged(ELoginState status) { fLogged = status; }
175 inline void SetTTL(long ttl) { fTTLsec = ttl; }
177 void Touch();
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
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
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//
210private:
212
213public:
215 // Constructor
216 phyconn = phyc;
218 }
219
221 // Destructor.
223 }
224
225};
226#endif
ELoginState
Definition: XrdClientPhyConnection.hh:50
@ kNo
Definition: XrdClientPhyConnection.hh:51
@ kYes
Definition: XrdClientPhyConnection.hh:52
@ kPending
Definition: XrdClientPhyConnection.hh:53
ERemoteServerType
Definition: XrdClientPhyConnection.hh:56
@ kSTMetaXrootd
Definition: XrdClientPhyConnection.hh:62
@ kSTRootd
Definition: XrdClientPhyConnection.hh:59
@ kSTDataXrootd
Definition: XrdClientPhyConnection.hh:61
@ kSTBaseXrootd
Definition: XrdClientPhyConnection.hh:60
@ kSTNone
Definition: XrdClientPhyConnection.hh:58
@ kSTError
Definition: XrdClientPhyConnection.hh:57
UnsolRespProcResult
Definition: XrdClientUnsolMsg.hh:43
Definition: XrdClientUnsolMsg.hh:51
Definition: XrdClientInputBuffer.hh:50
int WipeStreamid(int streamid)
Definition: XrdClientMessage.hh:49
Definition: XrdClientPhyConnection.hh:209
~XrdClientPhyConnLocker()
Definition: XrdClientPhyConnection.hh:220
XrdClientPhyConnection * phyconn
Definition: XrdClientPhyConnection.hh:211
XrdClientPhyConnLocker(XrdClientPhyConnection *phyc)
Definition: XrdClientPhyConnection.hh:214
Definition: XrdClientPhyConnection.hh:69
UnsolRespProcResult HandleUnsolicited(XrdClientMessage *m)
void SetInterrupt()
Definition: XrdClientPhyConnection.hh:149
int GetSocket()
Definition: XrdClientPhyConnection.hh:143
long fTTLsec
Definition: XrdClientPhyConnection.hh:108
bool fMStreamsGoing
Definition: XrdClientPhyConnection.hh:80
enum ELoginState fLogged
Definition: XrdClientPhyConnection.hh:73
long GetTTL()
Definition: XrdClientPhyConnection.hh:140
bool ReConnect(XrdClientUrlInfo RemoteHost)
int GetSockIdHint(int reqsperstream)
Definition: XrdClientPhyConnection.hh:188
long fServerProto
Definition: XrdClientPhyConnection.hh:106
void SetTTL(long ttl)
Definition: XrdClientPhyConnection.hh:175
ERemoteServerType DoHandShake(ServerInitHandShake &xbody, int substreamid=0)
short fLogConnCnt
Definition: XrdClientPhyConnection.hh:101
int GetReaderThreadsCnt()
Definition: XrdClientPhyConnection.hh:138
short GetLogConnCnt() const
Definition: XrdClientPhyConnection.hh:137
int ReadRaw(void *buffer, int BufferLength, int substreamid=-1, int *usedsubstreamid=0)
XrdClientMessage * BuildMessage(bool IgnoreTimeouts, bool Enqueue)
virtual void BanSockDescr(int sockdescr, int sockid)
Definition: XrdClientPhyConnection.hh:194
int WriteRaw(const void *buffer, int BufferLength, int substreamid=0)
ELoginState IsLogged()
int WipeStreamid(int streamid)
Definition: XrdClientPhyConnection.hh:200
int GetSockIdCount()
Definition: XrdClientPhyConnection.hh:189
XrdClientPhyConnection(XrdClientAbsUnsolMsgHandler *h, XrdClientSid *sid)
ERemoteServerType fServerType
Definition: XrdClientPhyConnection.hh:107
void SetLogged(ELoginState status)
Definition: XrdClientPhyConnection.hh:174
int SaveSocket()
Definition: XrdClientPhyConnection.hh:148
time_t fLastUseTimestamp
Definition: XrdClientPhyConnection.hh:72
bool IsAddress(const XrdOucString &addr)
Definition: XrdClientPhyConnection.hh:154
XrdSecProtocol * fSecProtocol
Definition: XrdClientPhyConnection.hh:74
XrdClientSock * fSocket
Definition: XrdClientPhyConnection.hh:95
XrdClientSid * fSidManager
Definition: XrdClientPhyConnection.hh:103
void CountLogConn(int d=1)
virtual void UnBanSockDescr(int sockdescr)
Definition: XrdClientPhyConnection.hh:195
void RemoveParallelStream(int substreamid)
Definition: XrdClientPhyConnection.hh:183
bool Connect(XrdClientUrlInfo RemoteHost, bool isUnix, int fd)
void RestartSelectOnSubstream(int substreamid)
Definition: XrdClientPhyConnection.hh:191
int fRequestTimeout
Definition: XrdClientPhyConnection.hh:79
XrdClientThread * fReaderthreadhandler[64]
Definition: XrdClientPhyConnection.hh:88
XrdSysRecMutex fRwMutex
Definition: XrdClientPhyConnection.hh:81
XrdSecProtocol * GetSecProtocol() const
Definition: XrdClientPhyConnection.hh:142
void SetSecProtocol(XrdSecProtocol *sp)
Definition: XrdClientPhyConnection.hh:150
XrdClientMessage * ReadMessage(int streamid)
int EstablishPendingParallelStream(int tmpid, int newid)
Definition: XrdClientPhyConnection.hh:182
bool IsUser(const XrdOucString &usr)
Definition: XrdClientPhyConnection.hh:162
void ReinitFDTable()
Definition: XrdClientPhyConnection.hh:146
bool IsPort(int port)
Definition: XrdClientPhyConnection.hh:161
int TryConnectParallelStream(int port, int windowsz, int sockid)
Definition: XrdClientPhyConnection.hh:181
XrdClientUrlInfo fServer
Definition: XrdClientPhyConnection.hh:93
XrdSysRecMutex fMutex
Definition: XrdClientPhyConnection.hh:84
int fReaderthreadrunning
Definition: XrdClientPhyConnection.hh:91
void PauseSelectOnSubstream(int substreamid)
Definition: XrdClientPhyConnection.hh:190
XrdSysRecMutex fMultireadMutex
Definition: XrdClientPhyConnection.hh:85
bool Connect(XrdClientUrlInfo RemoteHost, bool isUnix=0)
void ReadLock()
Definition: XrdClientPhyConnection.hh:197
XrdSysSemWait fReaderCV
Definition: XrdClientPhyConnection.hh:99
void ReadUnLock()
Definition: XrdClientPhyConnection.hh:198
XrdClientInputBuffer fMsgQ
Definition: XrdClientPhyConnection.hh:77
Definition: XrdClientSid.hh:57
Definition: XrdClientSock.hh:50
void SetInterrupt(int which=0)
Definition: XrdClientSock.hh:78
virtual Sockdescr TryConnectParallelSock(int, int, Sockid &)
Definition: XrdClientSock.hh:132
virtual void PauseSelectOnSubstream(Sockid)
Definition: XrdClientSock.hh:148
int fSocket
Definition: XrdClientSock.hh:59
virtual int GetSockIdCount()
Definition: XrdClientSock.hh:147
virtual void BanSockDescr(Sockdescr, Sockid)
Definition: XrdClientSock.hh:99
virtual Sockid GetSockIdHint(int)
Definition: XrdClientSock.hh:142
virtual int EstablishParallelSock(Sockid, Sockid)
Definition: XrdClientSock.hh:137
virtual int RemoveParallelSock(Sockid)
Definition: XrdClientSock.hh:139
void ReinitFDTable()
Definition: XrdClientSock.hh:103
virtual void RestartSelectOnSubstream(Sockid)
Definition: XrdClientSock.hh:149
virtual int SaveSocket()
Definition: XrdClientSock.hh:75
virtual void UnBanSockDescr(Sockdescr)
Definition: XrdClientSock.hh:100
Definition: XrdClientThread.hh:40
Definition: XrdClientUnsolMsg.hh:63
Definition: XrdClientUrlInfo.hh:50
int Port
Definition: XrdClientUrlInfo.hh:56
XrdOucString Host
Definition: XrdClientUrlInfo.hh:55
XrdOucString User
Definition: XrdClientUrlInfo.hh:54
XrdOucString HostAddr
Definition: XrdClientUrlInfo.hh:57
Definition: XrdOucString.hh:254
Definition: XrdSecInterface.hh:131
Definition: XrdSysPthread.hh:261
void Lock()
Definition: XrdSysPthread.hh:220
void UnLock()
Definition: XrdSysPthread.hh:222
Definition: XrdSysPthread.hh:240
Definition: XrdSysSemWait.hh:34
Definition: XProtocol.hh:870