Logo ROOT   6.14/05
Reference Guide
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 
33 //////////////////////////////////////////////////////////////////////////
34 // //
35 // Class handling physical connections to xrootd servers //
36 // //
37 //////////////////////////////////////////////////////////////////////////
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 
103  XrdClientSid *fSidManager;
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  //--------------------------------------------------------------------------
119  //! Connect to a remote location
120  //!
121  //! @param RemoteHost address descriptor
122  //! @param isUnix true if the address points to a Unix socket
123  //! @param fd a descriptor pointing to a connected socket
124  //! if the subroutine is supposed to reuse an existing
125  //! connection, -1 otherwise
126  //--------------------------------------------------------------------------
127  bool Connect( XrdClientUrlInfo RemoteHost, bool isUnix , int fd );
128 
129  void CountLogConn(int d = 1);
130  void Disconnect();
131 
133  DoHandShake(ServerInitHandShake &xbody,
134  int substreamid = 0);
135 
136  bool ExpiredTTL();
137  short GetLogConnCnt() const { return fLogConnCnt; }
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 
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 
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 //
210 private:
212 
213 public:
215  // Constructor
216  phyconn = phyc;
217  phyconn->LockChannel();
218  }
219 
221  // Destructor.
222  phyconn->UnlockChannel();
223  }
224 
225 };
226 #endif
virtual void RestartSelectOnSubstream(Sockid)
void RestartSelectOnSubstream(int substreamid)
virtual void PauseSelectOnSubstream(Sockid)
auto * m
Definition: textangle.C:8
virtual void BanSockDescr(int sockdescr, int sockid)
bool IsAddress(const XrdOucString &addr)
void SetLogged(ELoginState status)
virtual void UnBanSockDescr(Sockdescr)
virtual Sockid GetSockIdHint(int)
#define XrdSysRecMutex
Definition: XrdSysToOuc.h:18
virtual int RemoveParallelSock(Sockid)
XrdSecProtocol * GetSecProtocol() const
int TryConnectParallelStream(int port, int windowsz, int sockid)
XrdClientPhyConnection(XrdClientAbsUnsolMsgHandler *h, XrdClientSid *sid)
XrdClientInputBuffer fMsgQ
int EstablishPendingParallelStream(int tmpid, int newid)
#define XrdSysSemWait
Definition: XpdSysSemWait.h:8
XrdClientPhyConnLocker(XrdClientPhyConnection *phyc)
int ReadRaw(void *buffer, int BufferLength, int substreamid=-1, int *usedsubstreamid=0)
virtual int GetSockIdCount()
void CountLogConn(int d=1)
bool Connect(XrdClientUrlInfo RemoteHost, bool isUnix=0)
virtual int SaveSocket()
UnsolRespProcResult
void ReinitFDTable()
ELoginState IsLogged()
#define XrdSysMutexHelper
Definition: XrdSysToOuc.h:17
UnsolRespProcResult HandleUnsolicited(XrdClientMessage *m)
ERemoteServerType DoHandShake(ServerInitHandShake &xbody, int substreamid=0)
bool ReConnect(XrdClientUrlInfo RemoteHost)
bool IsUser(const XrdOucString &usr)
#define h(i)
Definition: RSha256.hxx:106
#define d(i)
Definition: RSha256.hxx:102
virtual int EstablishParallelSock(Sockid, Sockid)
void SetInterrupt(int which=0)
XrdClientPhyConnection * phyconn
void SetSecProtocol(XrdSecProtocol *sp)
XrdClientMessage * BuildMessage(bool IgnoreTimeouts, bool Enqueue)
void RemoveParallelStream(int substreamid)
virtual void UnBanSockDescr(int sockdescr)
int GetSockIdHint(int reqsperstream)
auto * l
Definition: textangle.C:4
int WriteRaw(const void *buffer, int BufferLength, int substreamid=0)
XrdClientThread * fReaderthreadhandler[64]
virtual Sockdescr TryConnectParallelSock(int, int, Sockid &)
int WipeStreamid(int streamid)
virtual void BanSockDescr(Sockdescr, Sockid)
void PauseSelectOnSubstream(int substreamid)
XrdClientMessage * ReadMessage(int streamid)
XrdOucString HostAddr