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 int Process(XrdLink *lp); 00092 00093 //----------------------------------------------------------------------------- 00095 //----------------------------------------------------------------------------- 00096 00097 int Process(); 00098 00099 //----------------------------------------------------------------------------- 00101 //----------------------------------------------------------------------------- 00102 00103 void Recycle(XrdLink *lp, int consec, const char *reason); 00104 00105 //----------------------------------------------------------------------------- 00107 //----------------------------------------------------------------------------- 00108 00109 void Reissue(); 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), waitJob(this) {} 00160 virtual ~XrdXrootdTransit() {} 00161 00162 private: 00163 int AttnCont(XrdXrootdTransPend *tP, int rcode, 00164 const struct iovec *ioV, int ioN, int ioL); 00165 bool Fail(int ecode, const char *etext); 00166 int Fatal(int rc); 00167 void Init(Result *rsltP, XrdLink *linkP, XrdSecEntity *seceP, 00168 const char *nameP, const char *protP 00169 ); 00170 bool ReqWrite(char *xdataP, int xdataL); 00171 bool RunCopy(char *buffP, int buffL); 00172 int Wait(XrdXrootd::Bridge::Context &rInfo, 00173 const struct iovec *ioV, int ioN, int ioL); 00174 int WaitResp(XrdXrootd::Bridge::Context &rInfo, 00175 const struct iovec *ioV, int ioN, int ioL); 00176 00177 class WaitReq : public XrdJob 00178 {public: 00179 void DoIt() {spanP->Process();} 00180 00181 WaitReq(XrdXrootdTransit *tP) 00182 : XrdJob("Transit Redrive"), spanP(tP) 00183 {} 00184 ~WaitReq() {} 00185 private: 00186 XrdXrootdTransit *spanP; 00187 }; 00188 00189 static XrdObjectQ<XrdXrootdTransit> TranStack; 00190 XrdObject<XrdXrootdTransit> TranLink; 00191 00192 WaitReq waitJob; 00193 XrdSysMutex runMutex; 00194 static const char *reqTab; 00195 XrdProtocol *realProt; 00196 XrdXrootd::Bridge::Result *respObj; 00197 const char *runEText; 00198 char *runArgs; 00199 int runALen; 00200 int runABsz; 00201 int runError; 00202 int runStatus; 00203 int runWait; 00204 int runWTot; 00205 int runWMax; 00206 bool runDone; 00207 bool reInvoke; 00208 bool runWCall; 00209 int wBLen; 00210 char *wBuff; 00211 const char *pName; 00212 time_t cTime; 00213 }; 00214 #endif