xrootd
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 
24 #include "XrdSys/XrdSysPthread.hh"
25 #include "XrdSys/XrdSysSemWait.hh"
26 
27 #include <time.h> // for time_t data type
28 
30  kNo = 0,
31  kYes = 1,
33 };
34 
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 
48 
49 private:
51  enum ELoginState fLogged; // only 1 login/auth is needed for physical
52  XrdSecProtocol *fSecProtocol; // authentication protocol
53 
55  fMsgQ; // The queue used to hold incoming messages
56 
59  XrdSysRecMutex fRwMutex; // Lock before using the physical channel
60  // (for reading and/or writing)
61 
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 
70 
72 
74 
76 
78 
79  short fLogConnCnt; // Number of logical connections using this phyconn
80 
82 
83 public:
84  long fServerProto; // The server protocol
86  long fTTLsec;
87 
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 
112  int substreamid = 0);
113 
114  bool ExpiredTTL();
115  short GetLogConnCnt() const { return fLogConnCnt; }
117 
118  long GetTTL() { return fTTLsec; }
119 
121  int GetSocket() { return fSocket ? fSocket->fSocket : -1; }
122 
123  // Tells to the sock to rebuild the list of interesting selectors
125 
126  int SaveSocket() { fTTLsec = 0; return fSocket ? (fSocket->SaveSocket()) : -1; }
129 
130  void StartedReader();
131 
132  bool IsAddress(const XrdOucString &addr) {
133  return ( (fServer.Host == addr) ||
134  (fServer.HostAddr == addr) );
135  }
136 
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
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 
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 //
188 private:
190 
191 public:
193  // Constructor
194  phyconn = phyc;
195  phyconn->LockChannel();
196  }
197 
199  // Destructor.
201  }
202 
203 };
204 
205 
206 #endif