xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 
45 #include "XrdSys/XrdSysPthread.hh"
46 #include "XrdSys/XrdSysSemWait.hh"
47 
48 #include <time.h> // for time_t data type
49 
51  kNo = 0,
52  kYes = 1,
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 
65 class XrdClientSid;
66 class XrdClientThread;
67 class XrdSecProtocol;
68 
70 
71 private:
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 
105 public:
106  long fServerProto; // The server protocol
108  long fTTLsec;
109 
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 
134  int substreamid = 0);
135 
136  bool ExpiredTTL();
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 
152  void StartedReader();
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 
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
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 //
210 private:
212 
213 public:
215  // Constructor
216  phyconn = phyc;
217  phyconn->LockChannel();
218  }
219 
221  // Destructor.
223  }
224 
225 };
226 #endif
Definition: XrdClientPhyConnection.hh:52
void ReadUnLock()
Definition: XrdClientPhyConnection.hh:198
virtual void RestartSelectOnSubstream(Sockid)
Definition: XrdClientSock.hh:149
int fRequestTimeout
Definition: XrdClientPhyConnection.hh:79
void RestartSelectOnSubstream(int substreamid)
Definition: XrdClientPhyConnection.hh:191
void SetInterrupt()
Definition: XrdClientPhyConnection.hh:149
virtual void PauseSelectOnSubstream(Sockid)
Definition: XrdClientSock.hh:148
Definition: XrdSysPthread.hh:239
virtual void BanSockDescr(int sockdescr, int sockid)
Definition: XrdClientPhyConnection.hh:194
void ReinitFDTable()
Definition: XrdClientPhyConnection.hh:146
int Port
Definition: XrdClientUrlInfo.hh:56
bool IsAddress(const XrdOucString &addr)
Definition: XrdClientPhyConnection.hh:154
void SetLogged(ELoginState status)
Definition: XrdClientPhyConnection.hh:174
short fLogConnCnt
Definition: XrdClientPhyConnection.hh:101
Definition: XrdClientPhyConnection.hh:61
virtual void UnBanSockDescr(Sockdescr)
Definition: XrdClientSock.hh:100
virtual Sockid GetSockIdHint(int)
Definition: XrdClientSock.hh:142
time_t fLastUseTimestamp
Definition: XrdClientPhyConnection.hh:72
int WipeStreamid(int streamid)
Definition: XrdClientPhyConnection.hh:200
Definition: XrdClientThread.hh:40
long fTTLsec
Definition: XrdClientPhyConnection.hh:108
Definition: XrdClientPhyConnection.hh:69
Definition: XrdSecInterface.hh:130
virtual int RemoveParallelSock(Sockid)
Definition: XrdClientSock.hh:139
int TryConnectParallelStream(int port, int windowsz, int sockid)
Definition: XrdClientPhyConnection.hh:181
XrdClientPhyConnection(XrdClientAbsUnsolMsgHandler *h, XrdClientSid *sid)
Definition: XrdClientUrlInfo.hh:50
long GetTTL()
Definition: XrdClientPhyConnection.hh:140
bool fMStreamsGoing
Definition: XrdClientPhyConnection.hh:80
int fReaderthreadrunning
Definition: XrdClientPhyConnection.hh:91
int fSocket
Definition: XrdClientSock.hh:59
XrdSysRecMutex fRwMutex
Definition: XrdClientPhyConnection.hh:81
XrdClientInputBuffer fMsgQ
Definition: XrdClientPhyConnection.hh:77
Definition: XrdClientUnsolMsg.hh:63
XrdSecProtocol * fSecProtocol
Definition: XrdClientPhyConnection.hh:74
int EstablishPendingParallelStream(int tmpid, int newid)
Definition: XrdClientPhyConnection.hh:182
ERemoteServerType
Definition: XrdClientPhyConnection.hh:56
int GetSocket()
Definition: XrdClientPhyConnection.hh:143
Definition: XrdClientSid.hh:57
XrdClientSock * fSocket
Definition: XrdClientPhyConnection.hh:95
Definition: XrdClientPhyConnection.hh:60
XrdClientPhyConnLocker(XrdClientPhyConnection *phyc)
Definition: XrdClientPhyConnection.hh:214
int ReadRaw(void *buffer, int BufferLength, int substreamid=-1, int *usedsubstreamid=0)
Definition: XrdClientUnsolMsg.hh:51
virtual int GetSockIdCount()
Definition: XrdClientSock.hh:147
Definition: XrdClientMessage.hh:49
void CountLogConn(int d=1)
XrdSysRecMutex fMultireadMutex
Definition: XrdClientPhyConnection.hh:85
enum ELoginState fLogged
Definition: XrdClientPhyConnection.hh:73
Definition: XrdClientPhyConnection.hh:59
bool Connect(XrdClientUrlInfo RemoteHost, bool isUnix=0)
ERemoteServerType fServerType
Definition: XrdClientPhyConnection.hh:107
virtual int SaveSocket()
Definition: XrdClientSock.hh:75
XrdClientUrlInfo fServer
Definition: XrdClientPhyConnection.hh:93
UnsolRespProcResult
Definition: XrdClientUnsolMsg.hh:43
XrdSysRecMutex fMutex
Definition: XrdClientPhyConnection.hh:84
void ReinitFDTable()
Definition: XrdClientSock.hh:103
ELoginState IsLogged()
int SaveSocket()
Definition: XrdClientPhyConnection.hh:148
Definition: XrdClientSock.hh:50
UnsolRespProcResult HandleUnsolicited(XrdClientMessage *m)
XrdSecProtocol * GetSecProtocol() const
Definition: XrdClientPhyConnection.hh:142
bool IsPort(int port)
Definition: XrdClientPhyConnection.hh:161
ERemoteServerType DoHandShake(ServerInitHandShake &xbody, int substreamid=0)
XrdOucString User
Definition: XrdClientUrlInfo.hh:54
bool ReConnect(XrdClientUrlInfo RemoteHost)
bool IsUser(const XrdOucString &usr)
Definition: XrdClientPhyConnection.hh:162
Definition: XrdClientPhyConnection.hh:58
void ReadLock()
Definition: XrdClientPhyConnection.hh:197
Definition: XrdSysSemWait.hh:34
~XrdClientPhyConnLocker()
Definition: XrdClientPhyConnection.hh:220
void Lock()
Definition: XrdSysPthread.hh:220
Definition: XrdClientPhyConnection.hh:53
virtual int EstablishParallelSock(Sockid, Sockid)
Definition: XrdClientSock.hh:137
ELoginState
Definition: XrdClientPhyConnection.hh:50
long fServerProto
Definition: XrdClientPhyConnection.hh:106
XrdClientSid * fSidManager
Definition: XrdClientPhyConnection.hh:103
void SetInterrupt(int which=0)
Definition: XrdClientSock.hh:78
XrdClientPhyConnection * phyconn
Definition: XrdClientPhyConnection.hh:211
void SetSecProtocol(XrdSecProtocol *sp)
Definition: XrdClientPhyConnection.hh:150
int GetSockIdCount()
Definition: XrdClientPhyConnection.hh:189
XrdClientMessage * BuildMessage(bool IgnoreTimeouts, bool Enqueue)
Definition: XrdClientPhyConnection.hh:62
void RemoveParallelStream(int substreamid)
Definition: XrdClientPhyConnection.hh:183
virtual void UnBanSockDescr(int sockdescr)
Definition: XrdClientPhyConnection.hh:195
Definition: XrdClientInputBuffer.hh:50
XrdSysSemWait fReaderCV
Definition: XrdClientPhyConnection.hh:99
int GetSockIdHint(int reqsperstream)
Definition: XrdClientPhyConnection.hh:188
void SetTTL(long ttl)
Definition: XrdClientPhyConnection.hh:175
Definition: XProtocol.hh:870
int WriteRaw(const void *buffer, int BufferLength, int substreamid=0)
Definition: XrdClientPhyConnection.hh:209
void UnLock()
Definition: XrdSysPthread.hh:222
XrdClientThread * fReaderthreadhandler[64]
Definition: XrdClientPhyConnection.hh:88
Definition: XrdClientPhyConnection.hh:57
Definition: XrdClientPhyConnection.hh:51
int GetReaderThreadsCnt()
Definition: XrdClientPhyConnection.hh:138
Definition: XrdOucString.hh:254
virtual Sockdescr TryConnectParallelSock(int, int, Sockid &)
Definition: XrdClientSock.hh:132
Definition: XrdSysPthread.hh:260
short GetLogConnCnt() const
Definition: XrdClientPhyConnection.hh:137
int WipeStreamid(int streamid)
virtual void BanSockDescr(Sockdescr, Sockid)
Definition: XrdClientSock.hh:99
XrdOucString Host
Definition: XrdClientUrlInfo.hh:55
void PauseSelectOnSubstream(int substreamid)
Definition: XrdClientPhyConnection.hh:190
XrdClientMessage * ReadMessage(int streamid)
XrdOucString HostAddr
Definition: XrdClientUrlInfo.hh:57