xrootd
XrdLinkCtl.hh
Go to the documentation of this file.
1 #ifndef __XRD_LINKCTL_H__
2 #define __XRD_LINKCTL_H__
3 /******************************************************************************/
4 /* */
5 /* X r d L i n k C t l . h h */
6 /* */
7 /* (c) 2018 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 "Xrd/XrdLinkXeq.hh"
33 
34 #include "XrdSys/XrdSysPthread.hh"
35 
36 /******************************************************************************/
37 /* C l a s s D e f i n i t i o n */
38 /******************************************************************************/
39 
40 class XrdLinkMatch;
41 
42 class XrdLinkCtl : protected XrdLinkXeq
43 {
44 public:
45 
46 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
57 
58 #define XRDLINK_RDLOCK 0x0001
59 #define XRDLINK_NOCLOSE 0x0002
60 
61 static XrdLink *Alloc(XrdNetAddr &peer, int opts=0);
62 
63 //-----------------------------------------------------------------------------
70 //-----------------------------------------------------------------------------
71 
72 static XrdLink *fd2link(int fd)
73  {if (fd < 0) fd = -fd;
74  return (fd <= LTLast && LinkBat[fd] ? LinkTab[fd] : 0);
75  }
76 
77 //-----------------------------------------------------------------------------
85 //-----------------------------------------------------------------------------
86 
87 static XrdLink *fd2link(int fd, unsigned int inst)
88  {if (fd < 0) fd = -fd;
89  if (fd <= LTLast && LinkBat[fd] && LinkTab[fd]
90  && LinkTab[fd]->Instance == inst) return LinkTab[fd];
91  return (XrdLink *)0;
92  }
93 
94 //-----------------------------------------------------------------------------
101 //-----------------------------------------------------------------------------
102 
103 static XrdPollInfo *fd2PollInfo(int fd)
104  {if (fd < 0) fd = -fd;
105  if (fd <= LTLast && LinkBat[fd])
106  return &(LinkTab[fd]->PollInfo);
107  return 0;
108  }
109 
110 //-----------------------------------------------------------------------------
124 //-----------------------------------------------------------------------------
125 
126 static XrdLink *Find(int &curr, XrdLinkMatch *who=0);
127 
128 //-----------------------------------------------------------------------------
142 //-----------------------------------------------------------------------------
143 
144 static int getName(int &curr, char *bname, int blen, XrdLinkMatch *who=0);
145 
146 //-----------------------------------------------------------------------------
148 //-----------------------------------------------------------------------------
149 
150 static void idleScan();
151 
152 //-----------------------------------------------------------------------------
158 //-----------------------------------------------------------------------------
159 
160 static void setKWT(int wkSec, int kwSec);
161 
162 //-----------------------------------------------------------------------------
170 //-----------------------------------------------------------------------------
171 
172 static int Setup(int maxfds, int idlewt);
173 
174 //-----------------------------------------------------------------------------
176 //-----------------------------------------------------------------------------
177 
178 static void SyncAll();
179 
180 //-----------------------------------------------------------------------------
182 //-----------------------------------------------------------------------------
183 
184 static void Unhook(int fd);
185 
186 //-----------------------------------------------------------------------------
188 //-----------------------------------------------------------------------------
189 
190 static short killWait; // Kill then wait;
191 static short waitKill; // Wait then kill
192 
193 //-----------------------------------------------------------------------------
195 //-----------------------------------------------------------------------------
196 
198 
199 private:
200  ~XrdLinkCtl() {} // Is never deleted!
201 
202 static XrdSysMutex LTMutex; // For the LinkTab only LTMutex->IOMutex allowed
204 static char *LinkBat;
205 static unsigned int LinkAlloc;
206 static int LTLast;
207 static int maxFD;
208 static const char *TraceID;
209 };
210 #endif
static void Unhook(int fd)
Unhook a link from the active table of links.
static XrdLink * fd2link(int fd)
Definition: XrdLinkCtl.hh:72
static XrdSysMutex LTMutex
Definition: XrdLinkCtl.hh:202
static XrdPollInfo * fd2PollInfo(int fd)
Definition: XrdLinkCtl.hh:103
static void idleScan()
Look for idle links and close hem down.
static int getName(int &curr, char *bname, int blen, XrdLinkMatch *who=0)
static char * LinkBat
Definition: XrdLinkCtl.hh:204
static short waitKill
Definition: XrdLinkCtl.hh:191
static unsigned int LinkAlloc
Definition: XrdLinkCtl.hh:205
Definition: XrdPollInfo.hh:36
Definition: XrdNetAddr.hh:41
~XrdLinkCtl()
Definition: XrdLinkCtl.hh:200
static void setKWT(int wkSec, int kwSec)
Definition: XrdSysPthread.hh:165
static int LTLast
Definition: XrdLinkCtl.hh:206
static XrdLink * Alloc(XrdNetAddr &peer, int opts=0)
static const char * TraceID
Definition: XrdLinkCtl.hh:208
XrdPollInfo PollInfo
Definition: XrdLinkXeq.hh:145
Definition: XrdLinkXeq.hh:52
Definition: XrdLinkCtl.hh:42
static XrdLink * fd2link(int fd, unsigned int inst)
Definition: XrdLinkCtl.hh:87
static int Setup(int maxfds, int idlewt)
Definition: XrdLinkMatch.hh:35
static void SyncAll()
Synchronize statustics for ll links.
static int maxFD
Definition: XrdLinkCtl.hh:207
XrdLinkCtl()
Constructor.
Definition: XrdLinkCtl.hh:197
static XrdLink * Find(int &curr, XrdLinkMatch *who=0)
static short killWait
Link destruction control constants.
Definition: XrdLinkCtl.hh:190
static XrdLinkCtl ** LinkTab
Definition: XrdLinkCtl.hh:203