xrootd
XrdLink.hh
Go to the documentation of this file.
1 #ifndef __XRD_LINK_H__
2 #define __XRD_LINK_H__
3 /******************************************************************************/
4 /* */
5 /* X r d L i n k . h h */
6 /* */
7 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* Produced by Andrew Hanushevsky for Stanford University under contract */
9 /* DE-AC02-76-SFO0515 with the Department of Energy */
10 /* */
11 /* This file is part of the XRootD software suite. */
12 /* */
13 /* XRootD is free software: you can redistribute it and/or modify it under */
14 /* the terms of the GNU Lesser General Public License as published by the */
15 /* Free Software Foundation, either version 3 of the License, or (at your */
16 /* option) any later version. */
17 /* */
18 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21 /* License for more details. */
22 /* */
23 /* You should have received a copy of the GNU Lesser General Public License */
24 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26 /* */
27 /* The copyright holder's institutional names and contributor's names may not */
28 /* be used to endorse or promote products derived from this software without */
29 /* specific prior written permission of the institution or contributor. */
30 /******************************************************************************/
31 
32 #include <sys/types.h>
33 #include <fcntl.h>
34 #include <time.h>
35 
36 #include "XrdNet/XrdNetAddr.hh"
37 #include "XrdOuc/XrdOucSFVec.hh"
38 #include "XrdSys/XrdSysPthread.hh"
39 
40 #include "Xrd/XrdJob.hh"
41 #include "Xrd/XrdLinkMatch.hh"
42 #include "Xrd/XrdProtocol.hh"
43 
44 /******************************************************************************/
45 /* X r d L i n k O p t i o n s */
46 /******************************************************************************/
47 
48 #define XRDLINK_RDLOCK 0x0001
49 #define XRDLINK_NOCLOSE 0x0002
50 
51 /******************************************************************************/
52 /* C l a s s D e f i n i t i o n */
53 /******************************************************************************/
54 
55 class XrdInet;
56 class XrdNetAddr;
57 class XrdPoll;
58 class XrdOucTrace;
59 class XrdScheduler;
60 class XrdSysError;
61 
62 class XrdLink : XrdJob
63 {
64 public:
65 friend class XrdLinkScan;
66 friend class XrdPoll;
67 friend class XrdPollPoll;
68 friend class XrdPollDev;
69 friend class XrdPollE;
70 
71 //-----------------------------------------------------------------------------
76 //-----------------------------------------------------------------------------
77 inline
78 XrdNetAddrInfo *AddrInfo() {return (XrdNetAddrInfo *)&Addr;}
79 
80 //-----------------------------------------------------------------------------
90 //-----------------------------------------------------------------------------
91 
92 static XrdLink *Alloc(XrdNetAddr &peer, int opts=0);
93 
94 void Bind() {} // Obsolete
95 void Bind(pthread_t tid) { (void)tid; } // Obsolete
96 
97 int Client(char *buff, int blen);
98 
99 int Close(int defer=0);
100 
101 void DoIt();
102 
103 void Enable();
104 
105 int FDnum() {return FD;}
106 
107 static XrdLink *fd2link(int fd)
108  {if (fd < 0) fd = -fd;
109  return (fd <= LTLast && LinkBat[fd] ? LinkTab[fd] : 0);
110  }
111 
112 static XrdLink *fd2link(int fd, unsigned int inst)
113  {if (fd < 0) fd = -fd;
114  if (fd <= LTLast && LinkBat[fd] && LinkTab[fd]
115  && LinkTab[fd]->Instance == inst) return LinkTab[fd];
116  return (XrdLink *)0;
117  }
118 
119 static XrdLink *Find(int &curr, XrdLinkMatch *who=0);
120 
121  int getIOStats(long long &inbytes, long long &outbytes,
122  int &numstall, int &numtardy)
123  { inbytes = BytesIn + BytesInTot;
124  outbytes = BytesOut+BytesOutTot;
125  numstall = stallCnt + stallCntTot;
126  numtardy = tardyCnt + tardyCntTot;
127  return InUse;
128  }
129 
130 static int getName(int &curr, char *bname, int blen, XrdLinkMatch *who=0);
131 
132 XrdProtocol *getProtocol() {return Protocol;} // opmutex must be locked
133 
134 void Hold(int lk) {(lk ? opMutex.Lock() : opMutex.UnLock());}
135 
136 //-----------------------------------------------------------------------------
141 //-----------------------------------------------------------------------------
142 
143 const char *Host() {return (const char *)HostName;}
144 
145 char *ID; // This is referenced a lot
146 
147 static void Init(XrdSysError *eP, XrdOucTrace *tP, XrdScheduler *sP)
148  {XrdLog = eP; XrdTrace = tP; XrdSched = sP;}
149 
150 static void Init(XrdInet *iP) {XrdNetTCP = iP;}
151 
152 //-----------------------------------------------------------------------------
156 //-----------------------------------------------------------------------------
157 inline
158 unsigned int Inst() {return Instance;}
159 
160 //-----------------------------------------------------------------------------
165 //-----------------------------------------------------------------------------
166 inline
167 bool isFlawed() {return Etext != 0;}
168 
169 //-----------------------------------------------------------------------------
177 //-----------------------------------------------------------------------------
178 inline
179 bool isInstance(unsigned int inst)
180  {return FD >= 0 && Instance == inst;}
181 
182 //-----------------------------------------------------------------------------
187 //-----------------------------------------------------------------------------
188 inline
189 const char *Name() {return (const char *)Lname;}
190 
191 //-----------------------------------------------------------------------------
196 //-----------------------------------------------------------------------------
197 inline const
198 XrdNetAddr *NetAddr() {return &Addr;}
199 
200 int Peek(char *buff, int blen, int timeout=-1);
201 
202 int Recv(char *buff, int blen);
203 int Recv(char *buff, int blen, int timeout);
204 
205 int RecvAll(char *buff, int blen, int timeout=-1);
206 
207 int Send(const char *buff, int blen);
208 int Send(const struct iovec *iov, int iocnt, int bytes=0);
209 
210 static int sfOK; // True if Send(sfVec) enabled
211 
212 typedef XrdOucSFVec sfVec;
213 
214 int Send(const sfVec *sdP, int sdn); // Iff sfOK > 0
215 
216 void Serialize(); // ASYNC Mode
217 
218 int setEtext(const char *text);
219 
220 void setID(const char *userid, int procid);
221 
222 static void setKWT(int wkSec, int kwSec);
223 
224 void setLocation(XrdNetAddrInfo::LocInfo &loc) {Addr.SetLocation(loc);}
225 
227 
228 void setRef(int cnt); // ASYNC Mode
229 
230 static int Setup(int maxfd, int idlewait);
231 
232 static int Stats(char *buff, int blen, int do_sync=0);
233 
234  void syncStats(int *ctime=0);
235 
236  int Terminate(const XrdLink *owner, int fdnum, unsigned int inst);
237 
238 time_t timeCon() {return conTime;}
239 
240 int UseCnt() {return InUse;}
241 
242 void armBridge() {isBridged = 1;}
243 int hasBridge() {return isBridged;}
244 
245  XrdLink();
246  ~XrdLink() {} // Is never deleted!
247 
248 private:
249 
250 void Reset();
251 int sendData(const char *Buff, int Blen);
252 
256 static XrdInet *XrdNetTCP;
257 
258 static XrdSysMutex LTMutex; // For the LinkTab only LTMutex->IOMutex allowed
259 static XrdLink **LinkTab;
260 static char *LinkBat;
261 static unsigned int LinkAlloc;
262 static int LTLast;
263 static const char *TraceID;
264 static int devNull;
265 static short killWait;
266 static short waitKill;
267 
268 // Statistical area (global and local)
269 //
270 static long long LinkBytesIn;
271 static long long LinkBytesOut;
272 static long long LinkConTime;
273 static long long LinkCountTot;
274 static int LinkCount;
275 static int LinkCountMax;
276 static int LinkTimeOuts;
277 static int LinkStalls;
278 static int LinkSfIntr;
279  long long BytesIn;
280  long long BytesInTot;
281  long long BytesOut;
282  long long BytesOutTot;
283  int stallCnt;
285  int tardyCnt;
287  int SfIntr;
289 
290 // Identification section
291 //
292 XrdNetAddr Addr;
293 char Uname[24]; // Uname and Lname must be adjacent!
294 char Lname[232];
295 char *HostName;
296 int HNlen;
297 pthread_t TID;
298 
303 XrdSysCondVar *KillcvP; // Protected by opMutex!
308 struct pollfd *PollEnt;
309 char *Etext;
310 int FD;
311 unsigned int Instance;
312 time_t conTime;
313 int InUse;
314 int doPost;
316 char KeepFD;
318 char isIdle;
319 char inQ;
321 char KillCnt; // Protected by opMutex!
322 static const char KillMax = 60;
323 static const char KillMsk = 0x7f;
324 static const char KillXwt = 0x80;
325 };
326 #endif
Definition: XrdProtocol.hh:116
Definition: XrdOucTrace.hh:35
Definition: XrdSysError.hh:87
Definition: XrdScheduler.hh:44
Definition: XrdSysPthread.hh:140
Definition: XrdSysPthread.hh:53
Definition: XrdSysPthread.hh:329
void Lock()
Definition: XrdSysPthread.hh:149
Definition: XrdLinkMatch.hh:35
void UnLock()
Definition: XrdSysPthread.hh:151
Definition: XrdJob.hh:42