XRootD
XrdSsiFileReq.hh
Go to the documentation of this file.
1 #ifndef __SSI_FILEREQ_H__
2 #define __SSI_FILEREQ_H__
3 /******************************************************************************/
4 /* */
5 /* X r d S s i F i l e R e q . h h */
6 /* */
7 /* (c) 2013 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* Produced by Andrew Hanushevsky for Stanford University under contract */
9 /* DE-AC02-76-SFO0515 with the Department of Energy */
10 /* */
11 /* This file is part of the XRootD software suite. */
12 /* */
13 /* XRootD is free software: you can redistribute it and/or modify it under */
14 /* the terms of the GNU Lesser General Public License as published by the */
15 /* Free Software Foundation, either version 3 of the License, or (at your */
16 /* option) any later version. */
17 /* */
18 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21 /* License for more details. */
22 /* */
23 /* You should have received a copy of the GNU Lesser General Public License */
24 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26 /* */
27 /* The copyright holder's institutional names and contributor's names may not */
28 /* be used to endorse or promote products derived from this software without */
29 /* specific prior written permission of the institution or contributor. */
30 /******************************************************************************/
31 
32 #include <cstring>
33 #include <sys/types.h>
34 
35 #include "Xrd/XrdJob.hh"
36 #include "Xrd/XrdScheduler.hh"
38 #include "XrdSfs/XrdSfsXio.hh"
39 #include "XrdSsi/XrdSsiRequest.hh"
41 #include "XrdSsi/XrdSsiStream.hh"
42 #include "XrdSys/XrdSysPthread.hh"
43 
44 class XrdOucErrInfo;
45 class XrdSsiAlert;
46 class XrdSsiFileResource;
47 class XrdSsiFileSess;
48 class XrdSsiRespInfoMsg;
49 class XrdSsiRRInfo;
50 class XrdSsiService;
51 class XrdSsiStream;
52 
53 class XrdSsiFileReq : public XrdSsiRequest, public XrdOucEICB, public XrdJob
54 {
55 public:
56 
57 
58 // SsiRequest methods
59 //
60  void Activate(XrdOucBuffer *oP, XrdSfsXioHandle bR, int rSz);
61 
62  void Alert(XrdSsiRespInfoMsg &aMsg);
63 
65  XrdSsiFileSess *fP, const char *sn,
66  const char *id, unsigned int rnum);
67 
68  void DeferredFinalize();
69 
70  void Finalize();
71 
73 
74  void Finished( XrdSsiRequest &rqstR,
75  const XrdSsiRespInfo &rInfo,
76  bool cancel=false) {}
77 
78  char *GetRequest(int &rLen);
79 
80  bool ProcessResponse(const XrdSsiErrInfo &eInfo,
81  const XrdSsiRespInfo &resp);
82 
83  XrdSfsXferSize Read(bool &done,
84  char *buffer,
85  XrdSfsXferSize blen);
86 
87  void RelRequestBuffer();
88 
89  int Send(XrdSfsDio *sfDio, XrdSfsXferSize size);
90 
91 static void SetMax(int mVal) {freeMax = mVal;}
92 
93  bool WantResponse(XrdOucErrInfo &eInfo);
94 
95 // OucEICB methods
96 //
97  void Done(int &Result, XrdOucErrInfo *cbInfo,
98  const char *path=0);
99 
100  int Same(unsigned long long arg1, unsigned long long arg2)
101  {return 0;}
102 // Job methods
103 //
104  void DoIt();
105 
106 // Constructor and destructor
107 //
108  XrdSsiFileReq(const char *cID=0)
109  : frqMutex(XrdSsiMutex::Recursive)
110  {Init(cID);}
111 
112 virtual ~XrdSsiFileReq() {if (tident) free(tident);}
113 
116 
117 private:
118 
119 void BindDone(); // Override
120 void Dispose(); // Override
121 int Emsg(const char *pfx, int ecode, const char *op);
122 int Emsg(const char *pfx, XrdSsiErrInfo &eObj,
123  const char *op);
124 void Init(const char *cID=0);
125 XrdSfsXferSize readStrmA(XrdSsiStream *strmP, char *buff,
126  XrdSfsXferSize blen);
127 XrdSfsXferSize readStrmP(XrdSsiStream *strmP, char *buff,
128  XrdSfsXferSize blen);
129 int sendStrmA(XrdSsiStream *strmP, XrdSfsDio *sfDio,
130  XrdSfsXferSize blen);
131 void Recycle();
132 void WakeUp(XrdSsiAlert *aP=0);
133 
134 static XrdSysMutex aqMutex;
135 static XrdSsiFileReq *freeReq;
136 static int freeCnt;
137 static int freeMax;
138 
139 XrdSsiMutex frqMutex;
140 XrdSsiFileReq *nextReq;
141 XrdSysSemaphore *finWait;
142 XrdOucEICB *respCB;
143 unsigned long long respCBarg;
144 
145 XrdSsiAlert *alrtSent;
146 XrdSsiAlert *alrtPend;
147 XrdSsiAlert *alrtLast;
148 
149 char *tident;
150 const char *sessN;
151 XrdOucErrInfo *cbInfo;
152 XrdSsiFileResource *fileR;
153 XrdSsiFileSess *fileP;
154 char *respBuf;
155 long long respOff;
156 union {long long fileSz;
157  int respLen;
158  };
159 XrdSfsXioHandle sfsBref;
160 XrdOucBuffer *oucBuff;
161 XrdSsiStream::Buffer *strBuff;
162 reqState myState;
163 rspState urState;
164 int reqSize;
165 unsigned int reqID;
166 bool haveResp;
167 bool respWait;
168 bool strmEOF;
169 bool schedDone;
170 bool isEnding;
171 char rID[8];
172 };
173 #endif
int XrdSfsXferSize
class XrdBuffer * XrdSfsXioHandle
Definition: XrdSfsXio.hh:46
Definition: XrdJob.hh:43
void Alert(XrdSsiRespInfoMsg &aMsg)
Send or receive a server generated alert.
bool WantResponse(XrdOucErrInfo &eInfo)
XrdSfsXferSize Read(bool &done, char *buffer, XrdSfsXferSize blen)
int Same(unsigned long long arg1, unsigned long long arg2)
char * GetRequest(int &rLen)
void Finished(XrdSsiRequest &rqstR, const XrdSsiRespInfo &rInfo, bool cancel=false)
void RelRequestBuffer()
bool ProcessResponse(const XrdSsiErrInfo &eInfo, const XrdSsiRespInfo &resp)
void DeferredFinalize()
XrdSsiFileReq(const char *cID=0)
int Send(XrdSfsDio *sfDio, XrdSfsXferSize size)
static XrdSsiFileReq * Alloc(XrdOucErrInfo *eP, XrdSsiFileResource *rP, XrdSsiFileSess *fP, const char *sn, const char *id, unsigned int rnum)
void Activate(XrdOucBuffer *oP, XrdSfsXioHandle bR, int rSz)
virtual ~XrdSsiFileReq()
void Done(int &Result, XrdOucErrInfo *cbInfo, const char *path=0)
static void SetMax(int mVal)
bool Finished(bool cancel=false)