XRootD
XrdXrootdTransit.hh
Go to the documentation of this file.
1 #ifndef __XRDXROOTDTRANSIT_HH_
2 #define __XRDXROOTDTRANSIT_HH_
3 /******************************************************************************/
4 /* */
5 /* X r d X r o o t d T r a n s i t . h h */
6 /* */
7 /* (c) 2012 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 #include <sys/types.h>
34 
35 #include "XrdSys/XrdSysPthread.hh"
38 
39 #include "Xrd/XrdObject.hh"
40 
41 #include <atomic>
42 
43 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
48 
49 struct XrdOucSFVec;
50 class XrdScheduler;
51 class XrdXrootdTransPend;
52 struct iovec;
53 
55 {
56 public:
57 
58 //-----------------------------------------------------------------------------
60 //-----------------------------------------------------------------------------
61 
62 static
64  XrdLink *linkP,
65  XrdSecEntity *seceP,
66  const char *nameP,
67  const char *protP
68  );
69 
70 //-----------------------------------------------------------------------------
72 //-----------------------------------------------------------------------------
73 
74 static int Attn(XrdLink *lP, short *theSID, int rcode,
75  const struct iovec *ioVec, int ioNum, int ioLen);
76 
77 //-----------------------------------------------------------------------------
79 //-----------------------------------------------------------------------------
80 
81 bool Disc();
82 
83 //-----------------------------------------------------------------------------
85 //-----------------------------------------------------------------------------
86 
87 static void Init(XrdScheduler *schedP, int qMax, int qTTL);
88 
89 //-----------------------------------------------------------------------------
91 //-----------------------------------------------------------------------------
92 
93 void Proceed();
94 
95 //-----------------------------------------------------------------------------
97 //-----------------------------------------------------------------------------
98 
99 int Process(XrdLink *lp); // XrdProtocol override
100 
101 //-----------------------------------------------------------------------------
103 //-----------------------------------------------------------------------------
104 
105 void Recycle(XrdLink *lp, int consec, const char *reason);
106 
107 //-----------------------------------------------------------------------------
109 //-----------------------------------------------------------------------------
110 
111 void Redrive();
112 
113 //-----------------------------------------------------------------------------
115 //-----------------------------------------------------------------------------
116 
117 static
118 const char *ReqTable();
119 
120 //-----------------------------------------------------------------------------
122 //-----------------------------------------------------------------------------
123 
124 bool Run(const char *xreqP,
125  char *xdataP=0,
126  int xdataL=0
127  );
128 
129 //-----------------------------------------------------------------------------
131 //-----------------------------------------------------------------------------
132 
133 int Send(int rcode, const struct iovec *ioVec, int ioNum, int ioLen);
134 
135 //-----------------------------------------------------------------------------
137 //-----------------------------------------------------------------------------
138 
139 int Send(long long offset, int dlen, int fdnum);
140 
141 int Send(XrdOucSFVec *sfvec, int sfvnum, int dlen);
142 
143 //-----------------------------------------------------------------------------
145 //-----------------------------------------------------------------------------
146 
147 int setSF(kXR_char *fhandle, bool seton=false)
148  {return SetSF(fhandle, seton);}
149 
150 //-----------------------------------------------------------------------------
152 //-----------------------------------------------------------------------------
153 
154 void SetWait(int wtime, bool notify=false)
155  {runWMax = wtime; runWCall = notify;}
156 
157 //-----------------------------------------------------------------------------
159 //-----------------------------------------------------------------------------
160 
161  XrdXrootdTransit() : TranLink(this),
162  respJob(this, &XrdXrootdTransit::Proceed,
163  "Transit proceed"),
164  waitJob(this, &XrdXrootdTransit::Redrive,
165  "Transit redrive")
166  {}
167 virtual ~XrdXrootdTransit() {}
168 
169 private:
170 int AttnCont(XrdXrootdTransPend *tP, int rcode,
171  const struct iovec *ioV, int ioN, int ioL);
172 bool Fail(int ecode, const char *etext);
173 int Fatal(int rc);
174 void Init(Result *rsltP, XrdLink *linkP, XrdSecEntity *seceP,
175  const char *nameP, const char *protP
176  );
177 bool ReqWrite(char *xdataP, int xdataL);
178 bool RunCopy(char *buffP, int buffL);
179 int Wait(XrdXrootd::Bridge::Context &rInfo,
180  const struct iovec *ioV, int ioN, int ioL);
181 int WaitResp(XrdXrootd::Bridge::Context &rInfo,
182  const struct iovec *ioV, int ioN, int ioL);
183 
184 class SchedReq : public XrdJob
185  {public:
186  typedef void (XrdXrootdTransit::*callbackFP)();
187  void DoIt() {(spanP->*cbFunc)();}
188 
189  SchedReq(XrdXrootdTransit *tP, callbackFP cbP, const char *why)
190  : XrdJob(why), spanP(tP), cbFunc(cbP) {}
191  ~SchedReq() {}
192  private:
193  XrdXrootdTransit *spanP;
194  callbackFP cbFunc;
195  };
196 
197 static XrdObjectQ<XrdXrootdTransit> TranStack;
199 
200 SchedReq respJob;
201 SchedReq waitJob;
202 XrdSysMutex runMutex;
203 static const char *reqTab;
204 XrdProtocol *realProt;
206 const char *runEText;
207 char *runArgs;
208 int runALen;
209 int runABsz;
210 int runError;
211 
212  // Set to 1 if there is a xroot request to the bridge; 0 otherwise. Used to prevent multiple
213  // active requests from going on at once for a given link - or for disconnecting while a
214  // request is ongoing.
215 std::atomic<int> runStatus;
216 int runWait;
217 int runWTot;
218 int runWMax;
219 bool runDone;
220 bool reInvoke;
221 bool runWCall;
222 int wBLen;
223 char *wBuff;
224 const char *pName;
225 time_t cTime;
226 };
227 #endif
unsigned char kXR_char
Definition: XPtypes.hh:65
Definition: XrdJob.hh:43
int SetSF(kXR_char *fhandle, bool seton=false)
void DoIt() override
bool Run(const char *xreqP, char *xdataP=0, int xdataL=0)
Inject an xrootd request into the protocol stack.
static const char * ReqTable()
Initialize the valid request table.
void Redrive()
Redrive a request after a wait.
int Send(int rcode, const struct iovec *ioVec, int ioNum, int ioLen)
Handle request data response.
void Recycle(XrdLink *lp, int consec, const char *reason)
Handle link shutdown.
static void Init(XrdScheduler *schedP, int qMax, int qTTL)
Perform one-time initialization.
static XrdXrootdTransit * Alloc(XrdXrootd::Bridge::Result *respP, XrdLink *linkP, XrdSecEntity *seceP, const char *nameP, const char *protP)
Get a new transit object.
int setSF(kXR_char *fhandle, bool seton=false)
Set sendfile() enablement.
static int Attn(XrdLink *lP, short *theSID, int rcode, const struct iovec *ioVec, int ioNum, int ioLen)
Handle attention response (i.e. async response)
virtual ~XrdXrootdTransit()
void SetWait(int wtime, bool notify=false)
Set maximum wait time.
XrdXrootdTransit()
Constructor & Destructor.
void Proceed()
Resume processing after a waitresp completion.
bool Disc()
Handle dismantlement.
int Process(XrdLink *lp)
Handle link activation (replaces parent activation).
XrdScheduler * schedP