00001 #ifndef __XRDXROOTDTRANSIT_HH_ 00002 #define __XRDXROOTDTRANSIT_HH_ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d X r o o t d T r a n s i t . h h */ 00006 /* */ 00007 /* (c) 2012 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00011 /* */ 00012 /* This file is part of the XRootD software suite. */ 00013 /* */ 00014 /* XRootD is free software: you can redistribute it and/or modify it under */ 00015 /* the terms of the GNU Lesser General Public License as published by the */ 00016 /* Free Software Foundation, either version 3 of the License, or (at your */ 00017 /* option) any later version. */ 00018 /* */ 00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00022 /* License for more details. */ 00023 /* */ 00024 /* You should have received a copy of the GNU Lesser General Public License */ 00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00027 /* */ 00028 /* The copyright holder's institutional names and contributor's names may not */ 00029 /* be used to endorse or promote products derived from this software without */ 00030 /* specific prior written permission of the institution or contributor. */ 00031 /******************************************************************************/ 00032 00033 #include <sys/types.h> 00034 00035 #include "XrdSys/XrdSysPthread.hh" 00036 #include "XrdXrootd/XrdXrootdBridge.hh" 00037 #include "XrdXrootd/XrdXrootdProtocol.hh" 00038 00039 #include "Xrd/XrdObject.hh" 00040 00041 //----------------------------------------------------------------------------- 00045 //----------------------------------------------------------------------------- 00046 00047 class XrdOucSFVec; 00048 class XrdScheduler; 00049 class XrdXrootdTransPend; 00050 struct iovec; 00051 00052 class XrdXrootdTransit : public XrdXrootd::Bridge, public XrdXrootdProtocol 00053 { 00054 public: 00055 00056 //----------------------------------------------------------------------------- 00058 //----------------------------------------------------------------------------- 00059 00060 static 00061 XrdXrootdTransit *Alloc(XrdXrootd::Bridge::Result *respP, 00062 XrdLink *linkP, 00063 XrdSecEntity *seceP, 00064 const char *nameP, 00065 const char *protP 00066 ); 00067 00068 //----------------------------------------------------------------------------- 00070 //----------------------------------------------------------------------------- 00071 00072 static int Attn(XrdLink *lP, short *theSID, int rcode, 00073 const struct iovec *ioVec, int ioNum, int ioLen); 00074 00075 //----------------------------------------------------------------------------- 00077 //----------------------------------------------------------------------------- 00078 00079 bool Disc(); 00080 00081 //----------------------------------------------------------------------------- 00083 //----------------------------------------------------------------------------- 00084 00085 static void Init(XrdScheduler *schedP, int qMax, int qTTL); 00086 00087 //----------------------------------------------------------------------------- 00089 //----------------------------------------------------------------------------- 00090 00091 void Proceed(); 00092 00093 //----------------------------------------------------------------------------- 00095 //----------------------------------------------------------------------------- 00096 00097 int Process(XrdLink *lp); // XrdProtocol override 00098 00099 //----------------------------------------------------------------------------- 00101 //----------------------------------------------------------------------------- 00102 00103 void Recycle(XrdLink *lp, int consec, const char *reason); 00104 00105 //----------------------------------------------------------------------------- 00107 //----------------------------------------------------------------------------- 00108 00109 void Redrive(); 00110 00111 //----------------------------------------------------------------------------- 00113 //----------------------------------------------------------------------------- 00114 00115 static 00116 const char *ReqTable(); 00117 00118 //----------------------------------------------------------------------------- 00120 //----------------------------------------------------------------------------- 00121 00122 bool Run(const char *xreqP, 00123 char *xdataP=0, 00124 int xdataL=0 00125 ); 00126 00127 //----------------------------------------------------------------------------- 00129 //----------------------------------------------------------------------------- 00130 00131 int Send(int rcode, const struct iovec *ioVec, int ioNum, int ioLen); 00132 00133 //----------------------------------------------------------------------------- 00135 //----------------------------------------------------------------------------- 00136 00137 int Send(long long offset, int dlen, int fdnum); 00138 00139 int Send(XrdOucSFVec *sfvec, int sfvnum, int dlen); 00140 00141 //----------------------------------------------------------------------------- 00143 //----------------------------------------------------------------------------- 00144 00145 int setSF(kXR_char *fhandle, bool seton=false) 00146 {return SetSF(fhandle, seton);} 00147 00148 //----------------------------------------------------------------------------- 00150 //----------------------------------------------------------------------------- 00151 00152 void SetWait(int wtime, bool notify=false) 00153 {runWMax = wtime; runWCall = notify;} 00154 00155 //----------------------------------------------------------------------------- 00157 //----------------------------------------------------------------------------- 00158 00159 XrdXrootdTransit() : TranLink(this), 00160 respJob(this, &XrdXrootdTransit::Proceed, 00161 "Transit proceed"), 00162 waitJob(this, &XrdXrootdTransit::Redrive, 00163 "Transit redrive") 00164 {} 00165 virtual ~XrdXrootdTransit() {} 00166 00167 private: 00168 int AttnCont(XrdXrootdTransPend *tP, int rcode, 00169 const struct iovec *ioV, int ioN, int ioL); 00170 bool Fail(int ecode, const char *etext); 00171 int Fatal(int rc); 00172 void Init(Result *rsltP, XrdLink *linkP, XrdSecEntity *seceP, 00173 const char *nameP, const char *protP 00174 ); 00175 bool ReqWrite(char *xdataP, int xdataL); 00176 bool RunCopy(char *buffP, int buffL); 00177 int Wait(XrdXrootd::Bridge::Context &rInfo, 00178 const struct iovec *ioV, int ioN, int ioL); 00179 int WaitResp(XrdXrootd::Bridge::Context &rInfo, 00180 const struct iovec *ioV, int ioN, int ioL); 00181 00182 class SchedReq : public XrdJob 00183 {public: 00184 typedef void (XrdXrootdTransit::*callbackFP)(); 00185 void DoIt() {(spanP->*cbFunc)();} 00186 00187 SchedReq(XrdXrootdTransit *tP, callbackFP cbP, const char *why) 00188 : XrdJob(why), spanP(tP), cbFunc(cbP) {} 00189 ~SchedReq() {} 00190 private: 00191 XrdXrootdTransit *spanP; 00192 callbackFP cbFunc; 00193 }; 00194 00195 static XrdObjectQ<XrdXrootdTransit> TranStack; 00196 XrdObject<XrdXrootdTransit> TranLink; 00197 00198 SchedReq respJob; 00199 SchedReq waitJob; 00200 XrdSysMutex runMutex; 00201 static const char *reqTab; 00202 XrdProtocol *realProt; 00203 XrdXrootd::Bridge::Result *respObj; 00204 const char *runEText; 00205 char *runArgs; 00206 int runALen; 00207 int runABsz; 00208 int runError; 00209 int runStatus; 00210 int runWait; 00211 int runWTot; 00212 int runWMax; 00213 bool runDone; 00214 bool reInvoke; 00215 bool runWCall; 00216 int wBLen; 00217 char *wBuff; 00218 const char *pName; 00219 time_t cTime; 00220 }; 00221 #endif