00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef XRD_CLIENT_H
00017 #define XRD_CLIENT_H
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "XrdClient/XrdClientAbs.hh"
00044 #include "XrdOuc/XrdOucString.hh"
00045 #include "XrdClient/XrdClientThread.hh"
00046 #include "XrdSys/XrdSysSemWait.hh"
00047 #include "XrdVersion.hh"
00048
00049
00050 class XrdClientReadAheadMgr;
00051
00052 struct XrdClientOpenInfo {
00053 bool inprogress;
00054 bool opened;
00055 kXR_unt16 mode;
00056 kXR_unt16 options;
00057 };
00058
00059 struct XrdClientStatInfo {
00060 int stated;
00061 long long size;
00062 long id;
00063 long flags;
00064 long modtime;
00065 };
00066
00067 struct XrdClientCounters {
00068 int CacheSize;
00069
00070
00071
00072
00073
00074 long long ReadBytes;
00075 long long WrittenBytes;
00076 long long WriteRequests;
00077
00078 long long ReadRequests;
00079 long long ReadMisses;
00080 long long ReadHits;
00081 float ReadMissRate;
00082
00083 long long ReadVRequests;
00084 long long ReadVSubRequests;
00085 long long ReadVSubChunks;
00086 long long ReadVBytes;
00087
00088 long long ReadVAsyncRequests;
00089 long long ReadVAsyncSubRequests;
00090 long long ReadVAsyncSubChunks;
00091 long long ReadVAsyncBytes;
00092
00093 long long ReadAsyncRequests;
00094 long long ReadAsyncBytes;
00095 };
00096
00097
00098 class XrdClient : public XrdClientAbs {
00099 friend void *FileOpenerThread(void*, XrdClientThread*);
00100
00101
00102 private:
00103
00104 struct XrdClientOpenInfo fOpenPars;
00105
00106
00107
00108
00109 XrdSysCondVar *fOpenProgCnd;
00110
00111
00112 XrdClientThread *fOpenerTh;
00113
00114
00115 static XrdSysSemWait fConcOpenSem;
00116
00117 bool fOpenWithRefresh;
00118
00119 XrdSysCondVar *fReadWaitData;
00120
00121 struct XrdClientStatInfo fStatInfo;
00122
00123 long fReadTrimBlockSize;
00124
00125 bool fUseCache;
00126
00127 XrdOucString fInitialUrl;
00128 XrdClientUrlInfo fUrl;
00129
00130 bool TryOpen(kXR_unt16 mode,
00131 kXR_unt16 options,
00132 bool doitparallel);
00133
00134 bool LowOpen(const char *file,
00135 kXR_unt16 mode,
00136 kXR_unt16 options,
00137 char *additionalquery = 0);
00138
00139 void TerminateOpenAttempt();
00140
00141 void WaitForNewAsyncData();
00142
00143
00144
00145
00146 kXR_int64 ReadVEach(char *buf, kXR_int64 *offsets, int *lens, int &nbuf);
00147
00148 bool IsOpenedForWrite() {
00149
00150 if (!fOpenPars.options) return false;
00151
00152 if (fOpenPars.options & kXR_open_read) return false;
00153
00154 return true;
00155 }
00156
00157 XrdClientReadAheadMgr *fReadAheadMgr;
00158
00159 void PrintCounters();
00160 protected:
00161
00162 XrdClientCounters fCounters;
00163
00164 virtual bool OpenFileWhenRedirected(char *newfhandle,
00165 bool &wasopen);
00166
00167 virtual bool CanRedirOnError() {
00168
00169
00170
00171 if ( !fOpenPars.opened ) return true;
00172
00173 return !IsOpenedForWrite();
00174
00175 }
00176
00177
00178 public:
00179
00180 XrdClient(const char *url, XrdClientCallback *XrdCcb = 0, void *XrdCcbArg = 0);
00181 virtual ~XrdClient();
00182
00183 UnsolRespProcResult ProcessUnsolicitedMsg(XrdClientUnsolMsgSender *sender,
00184 XrdClientMessage *unsolmsg);
00185
00186 bool Close();
00187
00188
00189 bool Sync();
00190
00191
00192 bool Copy(const char *localpath);
00193
00194
00195 bool GetCacheInfo(
00196
00197 int &size,
00198
00199
00200 long long &bytessubmitted,
00201
00202
00203 long long &byteshit,
00204
00205
00206
00207 long long &misscount,
00208
00209
00210 float &missrate,
00211
00212
00213 long long &readreqcnt,
00214
00215
00216 float &bytesusefulness
00217 );
00218
00219
00220
00221
00222 bool GetCounters( XrdClientCounters *cnt );
00223
00224
00225 inline bool IsOpen() { return fOpenPars.opened; }
00226
00227
00228 bool IsOpen_inprogress();
00229
00230
00231 bool IsOpen_wait();
00232
00233
00234
00235
00236 bool Open(kXR_unt16 mode, kXR_unt16 options, bool doitparallel=true);
00237
00238
00239 int Read(void *buf, long long offset, int len);
00240
00241
00242
00243
00244
00245
00246
00247
00248 kXR_int64 ReadV(char *buf, long long *offsets, int *lens, int nbuf);
00249
00250
00251
00252 XReqErrorType Read_Async(long long offset, int len, bool updatecounters=true);
00253
00254
00255
00256 bool Stat(struct XrdClientStatInfo *stinfo, bool force = false);
00257
00258
00259 bool UseCache(bool u = TRUE);
00260
00261
00262 void RemoveAllDataFromCache() {
00263 if (fConnModule)
00264 fConnModule->RemoveAllDataFromCache();
00265 }
00266
00267
00268 void RemoveDataFromCache(long long begin_offs,
00269 long long end_offs, bool remove_overlapped = false) {
00270 if (fConnModule)
00271 fConnModule->RemoveDataFromCache(begin_offs, end_offs, remove_overlapped);
00272 }
00273
00274
00275
00276
00277 void SetCacheParameters(int CacheSize, int ReadAheadSize, int RmPolicy);
00278
00279
00280 void SetReadAheadStrategy(int strategy);
00281
00282
00283
00284
00285
00286 void SetBlockReadTrimming(int blocksize);
00287
00288
00289 bool Truncate(long long len);
00290
00291
00292 bool Write(const void *buf, long long offset, int len);
00293
00294
00295
00296 };
00297
00298 #endif