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"
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
55class XrdInet;
56class XrdNetAddr;
57class XrdPoll;
58class XrdOucTrace;
59class XrdScheduler;
60class XrdSendQ;
61class XrdSysError;
62
64{
65public:
66friend class XrdLinkScan;
67friend class XrdPoll;
68friend class XrdPollPoll;
69friend class XrdPollDev;
70friend class XrdPollE;
71
72//-----------------------------------------------------------------------------
77//-----------------------------------------------------------------------------
78inline
80
81//-----------------------------------------------------------------------------
91//-----------------------------------------------------------------------------
92
93static XrdLink *Alloc(XrdNetAddr &peer, int opts=0);
94
95int Backlog();
96
97void Bind() {} // Obsolete
98void Bind(pthread_t tid) { (void)tid; } // Obsolete
99
100int Client(char *buff, int blen);
101
102int Close(int defer=0);
103
104void DoIt();
105
106void Enable();
107
108int FDnum() {int fd = FD; return (fd < 0 ? -fd : fd);}
109
110static XrdLink *fd2link(int fd)
111 {if (fd < 0) fd = -fd;
112 return (fd <= LTLast && LinkBat[fd] ? LinkTab[fd] : 0);
113 }
114
115static XrdLink *fd2link(int fd, unsigned int inst)
116 {if (fd < 0) fd = -fd;
117 if (fd <= LTLast && LinkBat[fd] && LinkTab[fd]
118 && LinkTab[fd]->Instance == inst) return LinkTab[fd];
119 return (XrdLink *)0;
120 }
121
122static XrdLink *Find(int &curr, XrdLinkMatch *who=0);
123
124 int getIOStats(long long &inbytes, long long &outbytes,
125 int &numstall, int &numtardy)
126 { inbytes = BytesIn + BytesInTot;
127 outbytes = BytesOut+BytesOutTot;
128 numstall = stallCnt + stallCntTot;
129 numtardy = tardyCnt + tardyCntTot;
130 return InUse;
131 }
132
133static int getName(int &curr, char *bname, int blen, XrdLinkMatch *who=0);
134
135XrdProtocol *getProtocol() {return Protocol;} // opmutex must be locked
136
137void Hold(int lk) {(lk ? opMutex.Lock() : opMutex.UnLock());}
138
139//-----------------------------------------------------------------------------
144//-----------------------------------------------------------------------------
145
146const char *Host() {return (const char *)HostName;}
147
148char *ID; // This is referenced a lot
149
150static void Init(XrdSysError *eP, XrdOucTrace *tP, XrdScheduler *sP)
151 {XrdLog = eP; XrdTrace = tP; XrdSched = sP;}
152
153static void Init(XrdInet *iP) {XrdNetTCP = iP;}
154
155//-----------------------------------------------------------------------------
159//-----------------------------------------------------------------------------
160inline
161unsigned int Inst() {return Instance;}
162
163//-----------------------------------------------------------------------------
168//-----------------------------------------------------------------------------
169inline
170bool isFlawed() {return Etext != 0;}
171
172//-----------------------------------------------------------------------------
180//-----------------------------------------------------------------------------
181inline
182bool isInstance(unsigned int inst)
183 {return FD >= 0 && Instance == inst;}
184
185//-----------------------------------------------------------------------------
190//-----------------------------------------------------------------------------
191inline
192const char *Name() {return (const char *)Lname;}
193
194//-----------------------------------------------------------------------------
199//-----------------------------------------------------------------------------
200inline const
202
203int Peek(char *buff, int blen, int timeout=-1);
204
205int Recv(char *buff, int blen);
206int Recv(char *buff, int blen, int timeout);
207
208int RecvAll(char *buff, int blen, int timeout=-1);
209
210int Send(const char *buff, int blen);
211int Send(const struct iovec *iov, int iocnt, int bytes=0);
212
213static int sfOK; // True if Send(sfVec) enabled
214
216
217int Send(const sfVec *sdP, int sdn); // Iff sfOK > 0
218
219void Serialize(); // ASYNC Mode
220
221int setEtext(const char *text);
222
223void setID(const char *userid, int procid);
224
225static void setKWT(int wkSec, int kwSec);
226
228
229bool setNB();
230
232
233void setRef(int cnt); // ASYNC Mode
234
235static int Setup(int maxfd, int idlewait);
236
237 void Shutdown(bool getLock);
238
239static int Stats(char *buff, int blen, int do_sync=0);
240
241 void syncStats(int *ctime=0);
242
243 int Terminate(const XrdLink *owner, int fdnum, unsigned int inst);
244
245time_t timeCon() {return conTime;}
246
247int UseCnt() {return InUse;}
248
249void armBridge() {isBridged = 1;}
250int hasBridge() {return isBridged;}
251
253 ~XrdLink() {} // Is never deleted!
254
255private:
256
257void Reset();
258int sendData(const char *Buff, int Blen);
259
264
265static XrdSysMutex LTMutex; // For the LinkTab only LTMutex->IOMutex allowed
267static char *LinkBat;
268static unsigned int LinkAlloc;
269static int LTLast;
270static const char *TraceID;
271static int devNull;
272static short killWait;
273static short waitKill;
274
275// Statistical area (global and local)
276//
277static long long LinkBytesIn;
278static long long LinkBytesOut;
279static long long LinkConTime;
280static long long LinkCountTot;
281static int LinkCount;
282static int LinkCountMax;
283static int LinkTimeOuts;
284static int LinkStalls;
285static int LinkSfIntr;
286static int maxFD;
287 long long BytesIn;
288 long long BytesInTot;
289 long long BytesOut;
290 long long BytesOutTot;
297
298// Identification section
299//
301char Uname[24]; // Uname and Lname must be adjacent!
302char Lname[232];
305#if defined( __linux__ ) || defined( __solaris__ )
306pthread_t TID; // Hack to keep abi compatability
307#else
308XrdLink *Next; // Only used by PollPoll.icc
309#endif
314XrdSysCondVar *KillcvP; // Protected by opMutex!
315XrdSendQ *sendQ; // Protected by wrMutex && opMutex
319struct pollfd *PollEnt;
320char *Etext;
321int FD;
322unsigned int Instance;
323time_t conTime;
330char inQ; // Only used by PollPoll.icc
332char KillCnt; // Protected by opMutex!
333static const char KillMax = 60;
334static const char KillMsk = 0x7f;
335static const char KillXwt = 0x80;
336};
337#endif
Definition: XrdInet.hh:49
Definition: XrdJob.hh:43
Definition: XrdLinkMatch.hh:36
Definition: XrdNetAddrInfo.hh:54
Definition: XrdNetAddr.hh:42
void SetLocation(XrdNetAddrInfo::LocInfo &loc)
Definition: XrdNetAddr.hh:221
Definition: XrdOucTrace.hh:36
Definition: XrdPollDev.hh:37
Definition: XrdPollE.hh:41
Definition: XrdPollPoll.hh:39
Definition: XrdPoll.hh:44
pthread_t TID
Definition: XrdPoll.hh:91
Definition: XrdProtocol.hh:117
Definition: XrdScheduler.hh:45
Definition: XrdSendQ.hh:43
Definition: XrdSysPthread.hh:79
Definition: XrdSysError.hh:90
Definition: XrdSysPthread.hh:166
void Lock()
Definition: XrdSysPthread.hh:220
void UnLock()
Definition: XrdSysPthread.hh:222
Definition: XrdSysPthread.hh:404
Definition: XrdNetAddrInfo.hh:176
Definition: XrdOucSFVec.hh:43