00001 #ifndef __SSI_FILEREQ_H__
00002 #define __SSI_FILEREQ_H__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <string.h>
00033 #include <sys/types.h>
00034
00035 #include "Xrd/XrdJob.hh"
00036 #include "Xrd/XrdScheduler.hh"
00037 #include "XrdSfs/XrdSfsInterface.hh"
00038 #include "XrdSsi/XrdSsiRequest.hh"
00039 #include "XrdSsi/XrdSsiResponder.hh"
00040 #include "XrdSsi/XrdSsiStream.hh"
00041 #include "XrdSys/XrdSysPthread.hh"
00042
00043 class XrdOucErrInfo;
00044 class XrdSfsXioHandle;
00045 class XrdSsiAlert;
00046 class XrdSsiFileResource;
00047 class XrdSsiFileSess;
00048 class XrdSsiRespInfoMsg;
00049 class XrdSsiRRInfo;
00050 class XrdSsiService;
00051 class XrdSsiStream;
00052
00053 class XrdSsiFileReq : public XrdSsiRequest, public XrdOucEICB, public XrdJob
00054 {
00055 public:
00056
00057
00058
00059
00060 void Activate(XrdOucBuffer *oP, XrdSfsXioHandle *bR, int rSz);
00061
00062 void Alert(XrdSsiRespInfoMsg &aMsg);
00063
00064 static XrdSsiFileReq *Alloc(XrdOucErrInfo *eP, XrdSsiFileResource *rP,
00065 XrdSsiFileSess *fP, const char *sn,
00066 const char *id, unsigned int rnum);
00067
00068 void Finalize();
00069
00070 using XrdSsiRequest::Finished;
00071
00072 void Finished( XrdSsiRequest &rqstR,
00073 const XrdSsiRespInfo &rInfo,
00074 bool cancel=false) {}
00075
00076 char *GetRequest(int &rLen);
00077
00078 bool ProcessResponse(const XrdSsiErrInfo &eInfo,
00079 const XrdSsiRespInfo &resp);
00080
00081 XrdSfsXferSize Read(bool &done,
00082 char *buffer,
00083 XrdSfsXferSize blen);
00084
00085 void RelRequestBuffer();
00086
00087 int Send(XrdSfsDio *sfDio, XrdSfsXferSize size);
00088
00089 static void SetMax(int mVal) {freeMax = mVal;}
00090
00091 bool WantResponse(XrdOucErrInfo &eInfo);
00092
00093
00094
00095 void Done(int &Result, XrdOucErrInfo *cbInfo,
00096 const char *path=0);
00097
00098 int Same(unsigned long long arg1, unsigned long long arg2)
00099 {return 0;}
00100
00101
00102 void DoIt();
00103
00104
00105
00106 XrdSsiFileReq(const char *cID=0)
00107 : frqMutex(XrdSsiMutex::Recursive)
00108 {Init(cID);}
00109
00110 virtual ~XrdSsiFileReq() {if (tident) free(tident);}
00111
00112 enum reqState {wtReq=0, xqReq, wtRsp, doRsp, odRsp, erRsp, rsEnd};
00113 enum rspState {isNew=0, isBegun, isBound, isAbort, isDone, isMax};
00114
00115 private:
00116
00117 void BindDone();
00118 void Dispose();
00119 int Emsg(const char *pfx, int ecode, const char *op);
00120 int Emsg(const char *pfx, XrdSsiErrInfo &eObj,
00121 const char *op);
00122 void Init(const char *cID=0);
00123 XrdSfsXferSize readStrmA(XrdSsiStream *strmP, char *buff,
00124 XrdSfsXferSize blen);
00125 XrdSfsXferSize readStrmP(XrdSsiStream *strmP, char *buff,
00126 XrdSfsXferSize blen);
00127 int sendStrmA(XrdSsiStream *strmP, XrdSfsDio *sfDio,
00128 XrdSfsXferSize blen);
00129 void Recycle();
00130 void WakeUp(XrdSsiAlert *aP=0);
00131
00132 static XrdSysMutex aqMutex;
00133 static XrdSsiFileReq *freeReq;
00134 static int freeCnt;
00135 static int freeMax;
00136
00137 XrdSsiMutex frqMutex;
00138 XrdSsiFileReq *nextReq;
00139 XrdSysSemaphore *finWait;
00140 XrdOucEICB *respCB;
00141 unsigned long long respCBarg;
00142
00143 XrdSsiAlert *alrtSent;
00144 XrdSsiAlert *alrtPend;
00145 XrdSsiAlert *alrtLast;
00146
00147 char *tident;
00148 const char *sessN;
00149 XrdOucErrInfo *cbInfo;
00150 XrdSsiFileResource *fileR;
00151 XrdSsiFileSess *fileP;
00152 char *respBuf;
00153 long long respOff;
00154 union {long long fileSz;
00155 int respLen;
00156 };
00157 XrdSfsXioHandle *sfsBref;
00158 XrdOucBuffer *oucBuff;
00159 XrdSsiStream::Buffer *strBuff;
00160 reqState myState;
00161 rspState urState;
00162 int reqSize;
00163 unsigned int reqID;
00164 bool haveResp;
00165 bool respWait;
00166 bool strmEOF;
00167 bool schedDone;
00168 bool isEnding;
00169 char rID[8];
00170 };
00171 #endif