46 #include "XrdOuc/XrdOucHash.hh"
47 #include "XrdSys/XrdSysPthread.hh"
49 #define ConnectionManager XrdClientConn::GetConnectionMgr()
58 enum ESrvErrorHandlerRetval {
59 kSEHRReturnMsgToCaller = 0,
62 kSEHRReturnNoMsgToCaller = 3,
63 kSEHRRedirLimitReached = 4
65 enum EThreeStateReadHandler {
67 kTSRHReturnNullMex = 1,
72 struct SessionIDInfo {
76 int fLastDataBytesRecv;
77 int fLastDataBytesSent;
78 XErrorCode fOpenError;
80 XrdOucString fRedirOpaque;
84 virtual ~XrdClientConn();
86 inline bool CacheWillFit(
long long bytes) {
89 return fMainReadCache->WillFit(bytes);
92 bool CheckHostDomain(XrdOucString hostToCheck);
93 short Connect(XrdClientUrlInfo Host2Conn,
94 XrdClientAbsUnsolMsgHandler *unsolhandler);
95 void Disconnect(
bool ForcePhysicalDisc);
96 virtual bool GetAccessToSrv();
97 XReqErrorType GoBackToRedirector();
99 XrdOucString GetClientHostDomain() {
return fgClientHostDomain; }
102 static XrdClientPhyConnection *GetPhyConn(
int LogConnID);
107 long GetDataFromCache(
const void *buffer,
108 long long begin_offs,
111 XrdClientIntvList &missingblks,
112 long &outstandingblks );
114 bool SubmitDataToCache(XrdClientMessage *xmsg,
115 long long begin_offs,
118 bool SubmitRawDataToCache(
const void *buffer,
119 long long begin_offs,
122 void SubmitPlaceholderToCache(
long long begin_offs,
123 long long end_offs) {
125 fMainReadCache->PutPlaceholder(begin_offs, end_offs);
129 void RemoveAllDataFromCache(
bool keepwriteblocks=
true) {
131 fMainReadCache->RemoveItems(keepwriteblocks);
134 void RemoveDataFromCache(
long long begin_offs,
135 long long end_offs,
bool remove_overlapped =
false) {
137 fMainReadCache->RemoveItems(begin_offs, end_offs, remove_overlapped);
140 void RemovePlaceholdersFromCache() {
142 fMainReadCache->RemovePlaceholders();
147 fMainReadCache->PrintCache();
156 long long &bytessubmitted,
163 long long &misscount,
169 long long &readreqcnt,
172 float &bytesusefulness
174 if (!fMainReadCache)
return false;
176 fMainReadCache->GetInfo(size,
187 void SetCacheSize(
int CacheSize) {
188 if (!fMainReadCache && CacheSize)
189 fMainReadCache =
new XrdClientReadCache();
192 fMainReadCache->SetSize(CacheSize);
195 void SetCacheRmPolicy(
int RmPolicy) {
197 fMainReadCache->SetBlkRemovalPolicy(RmPolicy);
200 void UnPinCacheBlk(
long long begin_offs,
long long end_offs) {
201 fMainReadCache->UnPinCacheBlk(begin_offs, end_offs);
203 fWriteWaitAck->Broadcast();
210 int GetLogConnID()
const {
return fLogConnID; }
212 ERemoteServerType GetServerType()
const {
return fServerType; }
214 kXR_unt16 GetStreamID()
const {
return fPrimaryStreamid; }
216 inline XrdClientUrlInfo *GetLBSUrl() {
return fLBSUrl; }
217 inline XrdClientUrlInfo *GetMetaUrl() {
return fMetaUrl; }
218 inline XrdClientUrlInfo GetCurrentUrl() {
return fUrl; }
219 inline XrdClientUrlInfo GetRedirUrl() {
return fREQUrl; }
221 XErrorCode GetOpenError()
const {
return fOpenError; }
222 virtual XReqErrorType GoToAnotherServer(XrdClientUrlInfo &newdest);
223 virtual XReqErrorType GoToMetaManager();
224 bool IsConnected()
const {
return fConnected; }
225 bool IsPhyConnConnected();
227 struct ServerResponseHeader
230 struct ServerResponseBody_Error
233 void ClearLastServerError() {
234 memset(&LastServerError, 0,
sizeof(LastServerError));
235 LastServerError.errnum = kXR_noErrorYet;
238 UnsolRespProcResult ProcessAsynResp(XrdClientMessage *unsolmsg);
240 virtual bool SendGenCommand(ClientRequest *req,
241 const void *reqMoreData,
242 void **answMoreDataAllocated,
243 void *answMoreData,
bool HasToAlloc,
244 char *CmdName,
int substreamid = 0);
246 int GetOpenSockFD()
const {
return fOpenSockFD; }
248 void SetClientHostDomain(
const char *src) { fgClientHostDomain = src; }
249 void SetConnected(
bool conn) { fConnected = conn; }
251 void SetOpenError(XErrorCode err) { fOpenError = err; }
254 int GetParallelStreamToUse(
int reqsperstream);
255 int GetParallelStreamCount();
257 void SetRedirHandler(XrdClientAbs *rh) { fRedirHandler = rh; }
259 void SetRequestedDestHost(
char *newh, kXR_int32 port) {
263 fREQUrl.SetAddrFromHost();
268 void SetREQPauseState(kXR_int32 wsec) {
273 fREQWaitTimeLimit = time(0) + wsec;
275 fREQWaitTimeLimit = 0;
276 fREQWait->Broadcast();
286 void SetREQDelayedConnectState(kXR_int32 wsec) {
288 fREQConnectWait->Lock();
291 fREQConnectWaitTimeLimit = time(0) + wsec;
293 fREQConnectWaitTimeLimit = 0;
294 fREQConnectWait->Broadcast();
298 fREQConnectWait->UnLock();
301 void SetSID(kXR_char *sid);
302 inline void SetUrl(XrdClientUrlInfo thisUrl) { fUrl = thisUrl; }
307 XReqErrorType WriteToServer_Async(ClientRequest *req,
308 const void* reqMoreData,
309 int substreamid = 0);
311 static XrdClientConnectionMgr *GetConnectionMgr()
312 {
return fgConnectionMgr;}
314 static void DelSessionIDRepo() {fSessionIDRMutex.Lock();
315 fSessionIDRepo.Purge();
316 fSessionIDRMutex.UnLock();
319 void GetSessionID(SessionIDInfo &sess) {sess = mySessionID;}
321 long GetServerProtocol() {
return fServerProto; }
323 short GetMaxRedirCnt()
const {
return fMaxGlobalRedirCnt; }
324 void SetMaxRedirCnt(
short mx) {fMaxGlobalRedirCnt = mx; }
325 short GetRedirCnt()
const {
return fGlobalRedirCnt; }
327 bool DoWriteSoftCheckPoint();
328 bool DoWriteHardCheckPoint();
329 void UnPinCacheBlk();
334 void SetOpTimeLimit(
int delta_secs);
335 bool IsOpTimeLimitElapsed(time_t timenow);
339 void SetLogConnID(
int cid) { fLogConnID = cid; }
340 void SetStreamID(kXR_unt16 sid) { fPrimaryStreamid = sid; }
345 XrdClientAbsUnsolMsgHandler *fUnsolMsgHandler;
347 XrdClientUrlInfo fUrl;
348 XrdClientUrlInfo *fLBSUrl;
349 XrdClientUrlInfo fREQUrl;
351 short fGlobalRedirCnt;
355 static XrdOucString fgClientHostDomain;
357 bool fGettingAccessToSrv;
358 time_t fGlobalRedirLastUpdateTimestamp;
361 kXR_unt16 fPrimaryStreamid;
365 short fMaxGlobalRedirCnt;
366 XrdClientReadCache *fMainReadCache;
371 XrdClientAbs *fRedirHandler;
375 XrdOucString fRedirInternalToken;
378 XrdSysCondVar *fREQWaitResp;
379 ServerResponseBody_Attn_asynresp *
382 time_t fREQWaitTimeLimit;
383 XrdSysCondVar *fREQWait;
384 time_t fREQConnectWaitTimeLimit;
385 XrdSysCondVar *fREQConnectWait;
388 ERemoteServerType fServerType;
389 SessionIDInfo mySessionID;
392 static XrdSysMutex fSessionIDRMutex;
393 static XrdOucHash<SessionIDInfo>
399 static XrdClientConnectionMgr *fgConnectionMgr;
401 XrdSysCondVar *fWriteWaitAck;
402 XrdClientVector<ClientRequest> fWriteReqsToRetry;
404 bool CheckErrorStatus(XrdClientMessage *,
short &,
char *);
405 void CheckPort(
int &port);
406 void CheckREQPauseState();
407 void CheckREQConnectWaitState();
408 bool CheckResp(
struct ServerResponseHeader *resp,
const char *method);
409 XrdClientMessage *ClientServerCmd(ClientRequest *req,
410 const void *reqMoreData,
411 void **answMoreDataAllocated,
414 int substreamid = 0);
415 XrdSecProtocol *DoAuthentication(
char *plist,
int plsiz);
417 ERemoteServerType DoHandShake(
short log);
420 bool DomainMatcher(XrdOucString dom, XrdOucString domlist);
422 XrdOucString GetDomainToMatch(XrdOucString hostname);
424 ESrvErrorHandlerRetval HandleServerError(XReqErrorType &, XrdClientMessage *,
426 bool MatchStreamid(
struct ServerResponseHeader *ServerResponse);
432 XrdOucString ParseDomainFromHostname(XrdOucString hostname);
434 XrdClientMessage *ReadPartialAnswer(XReqErrorType &,
size_t &,
435 ClientRequest *,
bool,
void**,
436 EThreeStateReadHandler &);
440 XReqErrorType WriteToServer(ClientRequest *req,
441 const void* reqMoreData,
443 int substreamid = 0);
445 bool WaitResp(
int secsmax);
447 XrdClientUrlInfo *fMetaUrl;
451 XrdOucString fRedirCGI;