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/socket.h>
00033 #include <sys/types.h>
00034 #include <fcntl.h>
00035 #include <time.h>
00036 
00037 #include "XrdSys/XrdSysPthread.hh"
00038 
00039 #include "Xrd/XrdJob.hh"
00040 #include "Xrd/XrdLinkMatch.hh"
00041 #include "Xrd/XrdProtocol.hh"
00042   
00043 /******************************************************************************/
00044 /*                       X r d L i n k   O p t i o n s                        */
00045 /******************************************************************************/
00046   
00047 #define XRDLINK_RDLOCK  0x0001
00048 #define XRDLINK_NOCLOSE 0x0002
00049 
00050 /******************************************************************************/
00051 /*                      C l a s s   D e f i n i t i o n                       */
00052 /******************************************************************************/
00053   
00054 class XrdInet;
00055 class XrdNetBuffer;
00056 class XrdNetPeer;
00057 class XrdPoll;
00058 class XrdOucTrace;
00059 class XrdScheduler;
00060 class XrdSysError;
00061 
00062 class XrdLink : XrdJob
00063 {
00064 public:
00065 friend class XrdLinkScan;
00066 friend class XrdPoll;
00067 friend class XrdPollPoll;
00068 friend class XrdPollDev;
00069 friend class XrdPollE;
00070 
00071 static XrdLink *Alloc(XrdNetPeer &Peer, int opts=0);
00072 
00073 void          Bind();
00074 void          Bind(pthread_t tid);
00075 
00076 int           Client(char *buff, int blen);
00077 
00078 int           Close(int defer=0);
00079 
00080 void          DoIt();
00081 
00082 int           FDnum() {return FD;}
00083 
00084 static XrdLink *fd2link(int fd)
00085                 {if (fd < 0) fd = -fd; 
00086                  return (fd <= LTLast && LinkBat[fd] ? LinkTab[fd] : 0);
00087                 }
00088 
00089 static XrdLink *fd2link(int fd, unsigned int inst)
00090                 {if (fd < 0) fd = -fd; 
00091                  if (fd <= LTLast && LinkBat[fd] && LinkTab[fd]
00092                  && LinkTab[fd]->Instance == inst) return LinkTab[fd];
00093                  return (XrdLink *)0;
00094                 }
00095 
00096 static XrdLink *Find(int &curr, XrdLinkMatch *who=0);
00097 
00098        int    getIOStats(long long &inbytes, long long &outbytes,
00099                               int  &numstall,     int  &numtardy)
00100                         { inbytes = BytesIn + BytesInTot;
00101                          outbytes = BytesOut+BytesOutTot;
00102                          numstall = stallCnt + stallCntTot;
00103                          numtardy = tardyCnt + tardyCntTot;
00104                          return InUse;
00105                         }
00106 
00107 static int    getName(int &curr, char *bname, int blen, XrdLinkMatch *who=0);
00108 
00109 XrdProtocol  *getProtocol() {return Protocol;} // opmutex must be locked
00110 
00111 void          Hold(int lk) {(lk ? opMutex.Lock() : opMutex.UnLock());}
00112 
00113 char         *ID;      // This is referenced a lot
00114 
00115 static   void Init(XrdSysError *eP, XrdOucTrace *tP, XrdScheduler *sP)
00116                   {XrdLog = eP; XrdTrace = tP; XrdSched = sP;}
00117 
00118 static   void Init(XrdInet *iP) {XrdNetTCP = iP;}
00119 
00120 unsigned int  Inst() {return Instance;}
00121 
00122 int           isFlawed() {return Etext != 0;}
00123 
00124 int           isInstance(unsigned int inst)
00125                         {return FD >= 0 && Instance == inst;}
00126 
00127 const char   *Name(sockaddr *ipaddr=0)
00128                      {if (ipaddr) memcpy(ipaddr, &InetAddr, sizeof(sockaddr));
00129                       return (const char *)Lname;
00130                      }
00131 
00132 const char   *Host(sockaddr *ipaddr=0)
00133                      {if (ipaddr) memcpy(ipaddr, &InetAddr, sizeof(sockaddr));
00134                       return (const char *)HostName;
00135                      }
00136 
00137 int           Peek(char *buff, int blen, int timeout=-1);
00138 
00139 int           Recv(char *buff, int blen);
00140 int           Recv(char *buff, int blen, int timeout);
00141 
00142 int           RecvAll(char *buff, int blen, int timeout=-1);
00143 
00144 int           Send(const char *buff, int blen);
00145 int           Send(const struct iovec *iov, int iocnt, int bytes=0);
00146 
00147 struct sfVec {union {char *buffer;    // ->Data if fdnum < 0
00148                      off_t offset;    // File offset      of data
00149                     };
00150               int   sendsz;           // Length of data at offset
00151               int   fdnum;            // File descriptor for data
00152              };
00153 static const int sfMax = 8;
00154 
00155 static int    sfOK;                   // True if Send(sfVec) enabled
00156 
00157 int           Send(const struct sfVec *sdP, int sdn); // Iff sfOK > 0
00158 
00159 void          Serialize();                              // ASYNC Mode
00160 
00161 int           setEtext(const char *text);
00162 
00163 void          setID(const char *userid, int procid);
00164 
00165 static void   setKWT(int wkSec, int kwSec);
00166 
00167 XrdProtocol  *setProtocol(XrdProtocol *pp);
00168 
00169 void          setRef(int cnt);                          // ASYNC Mode
00170 
00171 static int    Setup(int maxfd, int idlewait);
00172 
00173 static int    Stats(char *buff, int blen, int do_sync=0);
00174 
00175        void   syncStats(int *ctime=0);
00176 
00177        int    Terminate(const XrdLink *owner, int fdnum, unsigned int inst);
00178 
00179 time_t        timeCon() {return conTime;}
00180 
00181 int           UseCnt() {return InUse;}
00182 
00183               XrdLink();
00184              ~XrdLink() {}  // Is never deleted!
00185 
00186 private:
00187 
00188 void   Reset();
00189 int    sendData(const char *Buff, int Blen);
00190 
00191 static XrdSysError  *XrdLog;
00192 static XrdOucTrace  *XrdTrace;
00193 static XrdScheduler *XrdSched;
00194 static XrdInet      *XrdNetTCP;
00195 
00196 static XrdSysMutex   LTMutex;    // For the LinkTab only LTMutex->IOMutex allowed
00197 static XrdLink     **LinkTab;
00198 static char         *LinkBat;
00199 static unsigned int  LinkAlloc;
00200 static int           LTLast;
00201 static const char   *TraceID;
00202 static int           devNull;
00203 static short         killWait;
00204 static short         waitKill;
00205 
00206 // Statistical area (global and local)
00207 //
00208 static long long    LinkBytesIn;
00209 static long long    LinkBytesOut;
00210 static long long    LinkConTime;
00211 static long long    LinkCountTot;
00212 static int          LinkCount;
00213 static int          LinkCountMax;
00214 static int          LinkTimeOuts;
00215 static int          LinkStalls;
00216 static int          LinkSfIntr;
00217        long long        BytesIn;
00218        long long        BytesInTot;
00219        long long        BytesOut;
00220        long long        BytesOutTot;
00221        int              stallCnt;
00222        int              stallCntTot;
00223        int              tardyCnt;
00224        int              tardyCntTot;
00225        int              SfIntr;
00226 static XrdSysMutex  statsMutex;
00227 
00228 // Identification section
00229 //
00230 struct sockaddr     InetAddr;
00231 char                Uname[24];  // Uname and Lname must be adjacent!
00232 char                Lname[232];
00233 char               *HostName;
00234 int                 HNlen;
00235 pthread_t           TID;
00236 
00237 XrdSysMutex         opMutex;
00238 XrdSysMutex         rdMutex;
00239 XrdSysMutex         wrMutex;
00240 XrdSysSemaphore     IOSemaphore;
00241 XrdSysCondVar      *KillcvP;        // Protected by opMutex!
00242 XrdLink            *Next;
00243 XrdNetBuffer       *udpbuff;
00244 XrdProtocol        *Protocol;
00245 XrdProtocol        *ProtoAlt;
00246 XrdPoll            *Poller;
00247 struct pollfd      *PollEnt;
00248 char               *Etext;
00249 int                 FD;
00250 unsigned int        Instance;
00251 time_t              conTime;
00252 int                 InUse;
00253 int                 doPost;
00254 char                LockReads;
00255 char                KeepFD;
00256 char                isEnabled;
00257 char                isIdle;
00258 char                inQ;
00259 char                tBound;
00260 char                KillCnt;        // Protected by opMutex!
00261 static const char   KillMax =   60;
00262 static const char   KillMsk = 0x7f;
00263 static const char   KillXwt = 0x80;
00264 };
00265 #endif

Generated on 27 Jul 2013 for xrootd by  doxygen 1.4.7