00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef _XrdClientPhyConnection
00016 #define _XrdClientPhyConnection
00017
00018 #include "XrdClient/XrdClientPSock.hh"
00019 #include "XrdClient/XrdClientMessage.hh"
00020 #include "XrdClient/XrdClientUnsolMsg.hh"
00021 #include "XrdClient/XrdClientInputBuffer.hh"
00022 #include "XrdClient/XrdClientUrlInfo.hh"
00023 #include "XrdClient/XrdClientThread.hh"
00024 #include "XrdSys/XrdSysPthread.hh"
00025 #include "XrdSys/XrdSysSemWait.hh"
00026
00027 #include <time.h>
00028
00029 enum ELoginState {
00030 kNo = 0,
00031 kYes = 1,
00032 kPending = 2
00033 };
00034
00035 enum ERemoteServerType {
00036 kSTError = -1,
00037 kSTNone = 0,
00038 kSTRootd = 1,
00039 kSTBaseXrootd = 2,
00040 kSTDataXrootd = 3
00041 };
00042
00043 class XrdClientSid;
00044 class XrdSecProtocol;
00045
00046 class XrdClientPhyConnection: public XrdClientUnsolMsgSender {
00047
00048 private:
00049 time_t fLastUseTimestamp;
00050 enum ELoginState fLogged;
00051 XrdSecProtocol *fSecProtocol;
00052
00053 XrdClientInputBuffer
00054 fMsgQ;
00055
00056 int fRequestTimeout;
00057 bool fMStreamsGoing;
00058 XrdSysRecMutex fRwMutex;
00059
00060
00061 XrdSysRecMutex fMutex;
00062 XrdSysRecMutex fMultireadMutex;
00063
00064
00065 XrdClientThread *fReaderthreadhandler[64];
00066
00067
00068 int fReaderthreadrunning;
00069
00070 XrdClientUrlInfo fServer;
00071
00072 XrdClientSock *fSocket;
00073
00074 UnsolRespProcResult HandleUnsolicited(XrdClientMessage *m);
00075
00076 XrdSysSemWait fReaderCV;
00077
00078 short fLogConnCnt;
00079
00080 XrdClientSid *fSidManager;
00081
00082 public:
00083 long fServerProto;
00084 ERemoteServerType fServerType;
00085 long fTTLsec;
00086
00087 XrdClientPhyConnection(XrdClientAbsUnsolMsgHandler *h, XrdClientSid *sid);
00088 ~XrdClientPhyConnection();
00089
00090 XrdClientMessage *BuildMessage(bool IgnoreTimeouts, bool Enqueue);
00091 bool CheckAutoTerm();
00092
00093 bool Connect(XrdClientUrlInfo RemoteHost, bool isUnix = 0);
00094 void CountLogConn(int d = 1);
00095 void Disconnect();
00096
00097 ERemoteServerType
00098 DoHandShake(ServerInitHandShake &xbody,
00099 int substreamid = 0);
00100
00101 bool ExpiredTTL();
00102 short GetLogConnCnt() const { return fLogConnCnt; }
00103 int GetReaderThreadsCnt() { XrdSysMutexHelper l(fMutex); return fReaderthreadrunning; }
00104
00105 long GetTTL() { return fTTLsec; }
00106
00107 XrdSecProtocol *GetSecProtocol() const { return fSecProtocol; }
00108 int GetSocket() { return fSocket ? fSocket->fSocket : -1; }
00109
00110
00111 void ReinitFDTable() { if (fSocket) fSocket->ReinitFDTable(); }
00112
00113 int SaveSocket() { fTTLsec = 0; return fSocket ? (fSocket->SaveSocket()) : -1; }
00114 void SetInterrupt() { if (fSocket) fSocket->SetInterrupt(); }
00115 void SetSecProtocol(XrdSecProtocol *sp) { fSecProtocol = sp; }
00116
00117 void StartedReader();
00118
00119 bool IsAddress(const XrdOucString &addr) {
00120 return ( (fServer.Host == addr) ||
00121 (fServer.HostAddr == addr) );
00122 }
00123
00124 ELoginState IsLogged();
00125
00126 bool IsPort(int port) { return (fServer.Port == port); };
00127 bool IsUser(const XrdOucString &usr) { return (fServer.User == usr); };
00128 bool IsValid();
00129
00130
00131 void LockChannel();
00132
00133
00134 int ReadRaw(void *buffer, int BufferLength, int substreamid = -1,
00135 int *usedsubstreamid = 0);
00136
00137 XrdClientMessage *ReadMessage(int streamid);
00138 bool ReConnect(XrdClientUrlInfo RemoteHost);
00139 void SetLogged(ELoginState status) { fLogged = status; }
00140 inline void SetTTL(long ttl) { fTTLsec = ttl; }
00141 void StartReader();
00142 void Touch();
00143 void UnlockChannel();
00144 int WriteRaw(const void *buffer, int BufferLength, int substreamid = 0);
00145
00146 int TryConnectParallelStream(int port, int windowsz, int sockid) { return ( fSocket ? fSocket->TryConnectParallelSock(port, windowsz, sockid) : -1); }
00147 int EstablishPendingParallelStream(int tmpid, int newid) { return ( fSocket ? fSocket->EstablishParallelSock(tmpid, newid) : -1); }
00148 void RemoveParallelStream(int substreamid) { if (fSocket) fSocket->RemoveParallelSock(substreamid); }
00149
00150
00151 bool TestAndSetMStreamsGoing();
00152
00153 int GetSockIdHint(int reqsperstream) { return ( fSocket ? fSocket->GetSockIdHint(reqsperstream) : 0); }
00154 int GetSockIdCount() {return ( fSocket ? fSocket->GetSockIdCount() : 0); }
00155 void PauseSelectOnSubstream(int substreamid) { if (fSocket) fSocket->PauseSelectOnSubstream(substreamid); }
00156 void RestartSelectOnSubstream(int substreamid) { if (fSocket) fSocket->RestartSelectOnSubstream(substreamid); }
00157
00158
00159 virtual void BanSockDescr(int sockdescr, int sockid) { if (fSocket) fSocket->BanSockDescr(sockdescr, sockid); }
00160 virtual void UnBanSockDescr(int sockdescr) { if (fSocket) fSocket->UnBanSockDescr(sockdescr); }
00161
00162 void ReadLock() { fMultireadMutex.Lock(); }
00163 void ReadUnLock() { fMultireadMutex.UnLock(); }
00164
00165 int WipeStreamid(int streamid) { return fMsgQ.WipeStreamid(streamid); }
00166 };
00167
00168
00169
00170
00171
00172
00173
00174 class XrdClientPhyConnLocker {
00175 private:
00176 XrdClientPhyConnection *phyconn;
00177
00178 public:
00179 XrdClientPhyConnLocker(XrdClientPhyConnection *phyc) {
00180
00181 phyconn = phyc;
00182 phyconn->LockChannel();
00183 }
00184
00185 ~XrdClientPhyConnLocker(){
00186
00187 phyconn->UnlockChannel();
00188 }
00189
00190 };
00191
00192
00193 #endif