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 Finalize();
69 
71 
72  void Finished( XrdSsiRequest &rqstR,
73  const XrdSsiRespInfo &rInfo,
74  bool cancel=false) {}
75 
76  char *GetRequest(int &rLen);
77 
78  bool ProcessResponse(const XrdSsiErrInfo &eInfo,
79  const XrdSsiRespInfo &resp);
80 
81  XrdSfsXferSize Read(bool &done,
82  char *buffer,
83  XrdSfsXferSize blen);
84 
85  void RelRequestBuffer();
86 
87  int Send(XrdSfsDio *sfDio, XrdSfsXferSize size);
88 
89 static void SetMax(int mVal) {freeMax = mVal;}
90 
91  bool WantResponse(XrdOucErrInfo &eInfo);
92 
93 // OucEICB methods
94 //
95  void Done(int &Result, XrdOucErrInfo *cbInfo,
96  const char *path=0);
97 
98  int Same(unsigned long long arg1, unsigned long long arg2)
99  {return 0;}
100 // Job methods
101 //
102  void DoIt();
103 
104 // Constructor and destructor
105 //
106  XrdSsiFileReq(const char *cID=0)
107  : frqMutex(XrdSsiMutex::Recursive)
108  {Init(cID);}
109 
110 virtual ~XrdSsiFileReq() {if (tident) free(tident);}
111 
114 
115 private:
116 
117 void BindDone(); // Override
118 void Dispose(); // Override
119 int Emsg(const char *pfx, int ecode, const char *op);
120 int Emsg(const char *pfx, XrdSsiErrInfo &eObj,
121  const char *op);
122 void Init(const char *cID=0);
123 XrdSfsXferSize readStrmA(XrdSsiStream *strmP, char *buff,
124  XrdSfsXferSize blen);
125 XrdSfsXferSize readStrmP(XrdSsiStream *strmP, char *buff,
126  XrdSfsXferSize blen);
127 int sendStrmA(XrdSsiStream *strmP, XrdSfsDio *sfDio,
128  XrdSfsXferSize blen);
129 void Recycle();
130 void WakeUp(XrdSsiAlert *aP=0);
131 
132 static XrdSysMutex aqMutex;
133 static XrdSsiFileReq *freeReq;
134 static int freeCnt;
135 static int freeMax;
136 
137 XrdSsiMutex frqMutex;
138 XrdSsiFileReq *nextReq;
139 XrdSysSemaphore *finWait;
140 XrdOucEICB *respCB;
141 unsigned long long respCBarg;
142 
143 XrdSsiAlert *alrtSent;
144 XrdSsiAlert *alrtPend;
145 XrdSsiAlert *alrtLast;
146 
147 char *tident;
148 const char *sessN;
149 XrdOucErrInfo *cbInfo;
150 XrdSsiFileResource *fileR;
151 XrdSsiFileSess *fileP;
152 char *respBuf;
153 long long respOff;
154 union {long long fileSz;
155  int respLen;
156  };
157 XrdSfsXioHandle sfsBref;
158 XrdOucBuffer *oucBuff;
159 XrdSsiStream::Buffer *strBuff;
160 reqState myState;
161 rspState urState;
162 int reqSize;
163 unsigned int reqID;
164 bool haveResp;
165 bool respWait;
166 bool strmEOF;
167 bool schedDone;
168 bool isEnding;
169 char rID[8];
170 };
171 #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)
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)