XrdLink.hh

Go to the documentation of this file.
00001 #ifndef __XRD_LINK_H__
00002 #define __XRD_LINK_H__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                            X r d L i n k . h h                             */
00006 /*                                                                            */
00007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University  */
00008 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00009 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00010 /*                                                                            */
00011 /* This file is part of the XRootD software suite.                            */
00012 /*                                                                            */
00013 /* XRootD is free software: you can redistribute it and/or modify it under    */
00014 /* the terms of the GNU Lesser General Public License as published by the     */
00015 /* Free Software Foundation, either version 3 of the License, or (at your     */
00016 /* option) any later version.                                                 */
00017 /*                                                                            */
00018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
00019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
00020 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
00021 /* License for more details.                                                  */
00022 /*                                                                            */
00023 /* You should have received a copy of the GNU Lesser General Public License   */
00024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
00025 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
00026 /*                                                                            */
00027 /* The copyright holder's institutional names and contributor's names may not */
00028 /* be used to endorse or promote products derived from this software without  */
00029 /* specific prior written permission of the institution or contributor.       */
00030 /******************************************************************************/
00031 
00032 #include <sys/types.h>
00033 #include <fcntl.h>
00034 #include <time.h>
00035 
00036 #include "XrdNet/XrdNetAddr.hh"
00037 #include "XrdOuc/XrdOucSFVec.hh"
00038 #include "XrdSys/XrdSysPthread.hh"
00039 
00040 #include "Xrd/XrdJob.hh"
00041 #include "Xrd/XrdLinkMatch.hh"
00042 #include "Xrd/XrdProtocol.hh"
00043   
00044 /******************************************************************************/
00045 /*                       X r d L i n k   O p t i o n s                        */
00046 /******************************************************************************/
00047   
00048 #define XRDLINK_RDLOCK  0x0001
00049 #define XRDLINK_NOCLOSE 0x0002
00050 
00051 /******************************************************************************/
00052 /*                      C l a s s   D e f i n i t i o n                       */
00053 /******************************************************************************/
00054   
00055 class XrdInet;
00056 class XrdNetAddr;
00057 class XrdPoll;
00058 class XrdOucTrace;
00059 class XrdScheduler;
00060 class XrdSendQ;
00061 class XrdSysError;
00062 
00063 class XrdLink : XrdJob
00064 {
00065 public:
00066 friend class XrdLinkScan;
00067 friend class XrdPoll;
00068 friend class XrdPollPoll;
00069 friend class XrdPollDev;
00070 friend class XrdPollE;
00071 
00072 //-----------------------------------------------------------------------------
00077 //-----------------------------------------------------------------------------
00078 inline
00079 XrdNetAddrInfo *AddrInfo() {return (XrdNetAddrInfo *)&Addr;}
00080 
00081 //-----------------------------------------------------------------------------
00091 //-----------------------------------------------------------------------------
00092 
00093 static XrdLink *Alloc(XrdNetAddr &peer, int opts=0);
00094 
00095 int           Backlog();
00096 
00097 void          Bind() {}                // Obsolete
00098 void          Bind(pthread_t tid) { (void)tid; }   // Obsolete
00099 
00100 int           Client(char *buff, int blen);
00101 
00102 int           Close(int defer=0);
00103 
00104 void          DoIt();
00105 
00106 void          Enable();
00107 
00108 int           FDnum() {int fd = FD; return (fd < 0 ? -fd : fd);}
00109 
00110 static XrdLink *fd2link(int fd)
00111                 {if (fd < 0) fd = -fd; 
00112                  return (fd <= LTLast && LinkBat[fd] ? LinkTab[fd] : 0);
00113                 }
00114 
00115 static XrdLink *fd2link(int fd, unsigned int inst)
00116                 {if (fd < 0) fd = -fd; 
00117                  if (fd <= LTLast && LinkBat[fd] && LinkTab[fd]
00118                  && LinkTab[fd]->Instance == inst) return LinkTab[fd];
00119                  return (XrdLink *)0;
00120                 }
00121 
00122 static XrdLink *Find(int &curr, XrdLinkMatch *who=0);
00123 
00124        int    getIOStats(long long &inbytes, long long &outbytes,
00125                               int  &numstall,     int  &numtardy)
00126                         { inbytes = BytesIn + BytesInTot;
00127                          outbytes = BytesOut+BytesOutTot;
00128                          numstall = stallCnt + stallCntTot;
00129                          numtardy = tardyCnt + tardyCntTot;
00130                          return InUse;
00131                         }
00132 
00133 static int    getName(int &curr, char *bname, int blen, XrdLinkMatch *who=0);
00134 
00135 XrdProtocol  *getProtocol() {return Protocol;} // opmutex must be locked
00136 
00137 void          Hold(int lk) {(lk ? opMutex.Lock() : opMutex.UnLock());}
00138 
00139 //-----------------------------------------------------------------------------
00144 //-----------------------------------------------------------------------------
00145 
00146 const char   *Host() {return (const char *)HostName;}
00147 
00148 char         *ID;      // This is referenced a lot
00149 
00150 static   void Init(XrdSysError *eP, XrdOucTrace *tP, XrdScheduler *sP)
00151                   {XrdLog = eP; XrdTrace = tP; XrdSched = sP;}
00152 
00153 static   void Init(XrdInet *iP) {XrdNetTCP = iP;}
00154 
00155 //-----------------------------------------------------------------------------
00159 //-----------------------------------------------------------------------------
00160 inline
00161 unsigned int  Inst() {return Instance;}
00162 
00163 //-----------------------------------------------------------------------------
00168 //-----------------------------------------------------------------------------
00169 inline
00170 bool          isFlawed() {return Etext != 0;}
00171 
00172 //-----------------------------------------------------------------------------
00180 //-----------------------------------------------------------------------------
00181 inline
00182 bool          isInstance(unsigned int inst)
00183                         {return FD >= 0 && Instance == inst;}
00184 
00185 //-----------------------------------------------------------------------------
00190 //-----------------------------------------------------------------------------
00191 inline
00192 const char   *Name() {return (const char *)Lname;}
00193 
00194 //-----------------------------------------------------------------------------
00199 //-----------------------------------------------------------------------------
00200 inline const
00201 XrdNetAddr   *NetAddr() {return &Addr;}
00202 
00203 int           Peek(char *buff, int blen, int timeout=-1);
00204 
00205 int           Recv(char *buff, int blen);
00206 int           Recv(char *buff, int blen, int timeout);
00207 
00208 int           RecvAll(char *buff, int blen, int timeout=-1);
00209 
00210 int           Send(const char *buff, int blen);
00211 int           Send(const struct iovec *iov, int iocnt, int bytes=0);
00212 
00213 static int    sfOK;                   // True if Send(sfVec) enabled
00214 
00215 typedef XrdOucSFVec sfVec;
00216 
00217 int           Send(const sfVec *sdP, int sdn); // Iff sfOK > 0
00218 
00219 void          Serialize();                              // ASYNC Mode
00220 
00221 int           setEtext(const char *text);
00222 
00223 void          setID(const char *userid, int procid);
00224 
00225 static void   setKWT(int wkSec, int kwSec);
00226 
00227 void          setLocation(XrdNetAddrInfo::LocInfo &loc) {Addr.SetLocation(loc);}
00228 
00229 bool          setNB();
00230 
00231 XrdProtocol  *setProtocol(XrdProtocol *pp);
00232 
00233 void          setRef(int cnt);                          // ASYNC Mode
00234 
00235 static int    Setup(int maxfd, int idlewait);
00236 
00237        void   Shutdown(bool getLock);
00238 
00239 static int    Stats(char *buff, int blen, int do_sync=0);
00240 
00241        void   syncStats(int *ctime=0);
00242 
00243        int    Terminate(const XrdLink *owner, int fdnum, unsigned int inst);
00244 
00245 time_t        timeCon() {return conTime;}
00246 
00247 int           UseCnt() {return InUse;}
00248 
00249 void          armBridge() {isBridged = 1;}
00250 int           hasBridge() {return isBridged;}
00251 
00252               XrdLink();
00253              ~XrdLink() {}  // Is never deleted!
00254 
00255 private:
00256 
00257 void   Reset();
00258 int    sendData(const char *Buff, int Blen);
00259 
00260 static XrdSysError  *XrdLog;
00261 static XrdOucTrace  *XrdTrace;
00262 static XrdScheduler *XrdSched;
00263 static XrdInet      *XrdNetTCP;
00264 
00265 static XrdSysMutex   LTMutex;    // For the LinkTab only LTMutex->IOMutex allowed
00266 static XrdLink     **LinkTab;
00267 static char         *LinkBat;
00268 static unsigned int  LinkAlloc;
00269 static int           LTLast;
00270 static const char   *TraceID;
00271 static int           devNull;
00272 static short         killWait;
00273 static short         waitKill;
00274 
00275 // Statistical area (global and local)
00276 //
00277 static long long    LinkBytesIn;
00278 static long long    LinkBytesOut;
00279 static long long    LinkConTime;
00280 static long long    LinkCountTot;
00281 static int          LinkCount;
00282 static int          LinkCountMax;
00283 static int          LinkTimeOuts;
00284 static int          LinkStalls;
00285 static int          LinkSfIntr;
00286        long long        BytesIn;
00287        long long        BytesInTot;
00288        long long        BytesOut;
00289        long long        BytesOutTot;
00290        int              stallCnt;
00291        int              stallCntTot;
00292        int              tardyCnt;
00293        int              tardyCntTot;
00294        int              SfIntr;
00295 static XrdSysMutex  statsMutex;
00296 
00297 // Identification section
00298 //
00299 XrdNetAddr          Addr;
00300 char                Uname[24];       // Uname and Lname must be adjacent!
00301 char                Lname[232];
00302 char               *HostName;
00303 int                 HNlen;
00304 #if defined( __linux__ ) || defined( __solaris__ )
00305 pthread_t           TID;     // Hack to keep abi compatability
00306 #else
00307 XrdLink            *Next;    // Only used by PollPoll.icc
00308 #endif
00309 XrdSysMutex         opMutex;
00310 XrdSysMutex         rdMutex;
00311 XrdSysMutex         wrMutex;
00312 XrdSysSemaphore     IOSemaphore;
00313 XrdSysCondVar      *KillcvP;        // Protected by opMutex!
00314 XrdSendQ           *sendQ;          // Protected by wrMutex && opMutex
00315 XrdProtocol        *Protocol;
00316 XrdProtocol        *ProtoAlt;
00317 XrdPoll            *Poller;
00318 struct pollfd      *PollEnt;
00319 char               *Etext;
00320 int                 FD;
00321 unsigned int        Instance;
00322 time_t              conTime;
00323 int                 InUse;
00324 int                 doPost;
00325 char                LockReads;
00326 char                KeepFD;
00327 char                isEnabled;
00328 char                isIdle;
00329 char                inQ;    // Only used by PollPoll.icc
00330 char                isBridged;
00331 char                KillCnt;        // Protected by opMutex!
00332 static const char   KillMax =   60;
00333 static const char   KillMsk = 0x7f;
00334 static const char   KillXwt = 0x80;
00335 };
00336 #endif

Generated on 13 Mar 2017 for xrootd by  doxygen 1.4.7