XRootD
Loading...
Searching...
No Matches
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
39
40#include "Xrd/XrdObject.hh"
41
42#include <atomic>
43
44//-----------------------------------------------------------------------------
48//-----------------------------------------------------------------------------
49
50struct XrdOucSFVec;
51class XrdScheduler;
53struct iovec;
54
56{
57public:
58
59//-----------------------------------------------------------------------------
61//-----------------------------------------------------------------------------
62
63static
65 XrdLink *linkP,
66 XrdSecEntity *seceP,
67 const char *nameP,
68 const char *protP
69 );
70
71//-----------------------------------------------------------------------------
73//-----------------------------------------------------------------------------
74
75static int Attn(XrdLink *lP, short *theSID, int rcode,
76 const struct iovec *ioVec, int ioNum, int ioLen);
77
78//-----------------------------------------------------------------------------
80//-----------------------------------------------------------------------------
81
82bool Disc();
83
84//-----------------------------------------------------------------------------
86//-----------------------------------------------------------------------------
87
88static void Init(XrdScheduler *schedP, int qMax, int qTTL);
89
90//-----------------------------------------------------------------------------
92//-----------------------------------------------------------------------------
93
94void Proceed();
95
96//-----------------------------------------------------------------------------
98//-----------------------------------------------------------------------------
99
100int Process(XrdLink *lp); // XrdProtocol override
101
102//-----------------------------------------------------------------------------
104//-----------------------------------------------------------------------------
105
106void Recycle(XrdLink *lp, int consec, const char *reason);
107
108//-----------------------------------------------------------------------------
110//-----------------------------------------------------------------------------
111
112void Redrive();
113
114//-----------------------------------------------------------------------------
116//-----------------------------------------------------------------------------
117
118static
119const char *ReqTable();
120
121//-----------------------------------------------------------------------------
123//-----------------------------------------------------------------------------
124
125bool Run(const char *xreqP,
126 char *xdataP=0,
127 int xdataL=0
128 );
129
130//-----------------------------------------------------------------------------
132//-----------------------------------------------------------------------------
133
134int Send(int rcode, const struct iovec *ioVec, int ioNum, int ioLen);
135
136//-----------------------------------------------------------------------------
138//-----------------------------------------------------------------------------
139
140int Send(long long offset, int dlen, int fdnum);
141
142int Send(XrdOucSFVec *sfvec, int sfvnum, int dlen);
143
144//-----------------------------------------------------------------------------
146//-----------------------------------------------------------------------------
147
148int setSF(kXR_char *fhandle, bool seton=false)
149 {return SetSF(fhandle, seton);}
150
151//-----------------------------------------------------------------------------
153//-----------------------------------------------------------------------------
154
155void SetWait(int wtime, bool notify=false)
156 {runWMax = wtime; runWCall = notify;}
157
158//-----------------------------------------------------------------------------
160//-----------------------------------------------------------------------------
161
162 XrdXrootdTransit() : TranLink(this),
163 respJob(this, &XrdXrootdTransit::Proceed,
164 "Transit proceed"),
165 waitJob(this, &XrdXrootdTransit::Redrive,
166 "Transit redrive")
167 {}
169
170private:
171int AttnCont(XrdXrootdTransPend *tP, int rcode,
172 const struct iovec *ioV, int ioN, int ioL);
173bool Fail(int ecode, const char *etext);
174int Fatal(int rc);
175void Init(Result *rsltP, XrdLink *linkP, XrdSecEntity *seceP,
176 const char *nameP, const char *protP
177 );
178bool ReqWrite(char *xdataP, int xdataL);
179bool RunCopy(char *buffP, int buffL);
180int Wait(XrdXrootd::Bridge::Context &rInfo,
181 const struct iovec *ioV, int ioN, int ioL);
182int WaitResp(XrdXrootd::Bridge::Context &rInfo,
183 const struct iovec *ioV, int ioN, int ioL);
184
185class SchedReq : public XrdJob
186 {public:
187 typedef void (XrdXrootdTransit::*callbackFP)();
188 void DoIt() {(spanP->*cbFunc)();}
189
190 SchedReq(XrdXrootdTransit *tP, callbackFP cbP, const char *why)
191 : XrdJob(why), spanP(tP), cbFunc(cbP) {}
192 ~SchedReq() {}
193 private:
194 XrdXrootdTransit *spanP;
195 callbackFP cbFunc;
196 };
197
198static XrdObjectQ<XrdXrootdTransit> TranStack;
200
201SchedReq respJob;
202SchedReq waitJob;
203XrdSysMutex runMutex;
204static const char *reqTab;
205XrdProtocol *realProt;
207const char *runEText;
208char *runArgs;
209int runALen;
210int runABsz;
211int runError;
212
213 // Set to 1 if there is a xroot request to the bridge; 0 otherwise. Used to prevent multiple
214 // active requests from going on at once for a given link - or for disconnecting while a
215 // request is ongoing.
216std::atomic<int> runStatus;
217RAtomic_int runWait;
218int runWTot;
219int runWMax;
220bool runDone;
221bool reInvoke;
222bool runWCall;
223int wBLen;
224char *wBuff;
225const char *pName;
226time_t cTime;
227};
228#endif
unsigned char kXR_char
Definition XPtypes.hh:65
int SetSF(kXR_char *fhandle, bool seton=false)
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)
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).