00001 #ifndef __XRD_LINKCTL_H__ 00002 #define __XRD_LINKCTL_H__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d L i n k C t l . h h */ 00006 /* */ 00007 /* (c) 2018 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 "Xrd/XrdLinkXeq.hh" 00033 00034 #include "XrdSys/XrdSysPthread.hh" 00035 00036 /******************************************************************************/ 00037 /* C l a s s D e f i n i t i o n */ 00038 /******************************************************************************/ 00039 00040 class XrdLinkMatch; 00041 00042 class XrdLinkCtl : protected XrdLinkXeq 00043 { 00044 public: 00045 00046 //----------------------------------------------------------------------------- 00056 //----------------------------------------------------------------------------- 00057 00058 #define XRDLINK_RDLOCK 0x0001 00059 #define XRDLINK_NOCLOSE 0x0002 00060 00061 static XrdLink *Alloc(XrdNetAddr &peer, int opts=0); 00062 00063 //----------------------------------------------------------------------------- 00070 //----------------------------------------------------------------------------- 00071 00072 static XrdLink *fd2link(int fd) 00073 {if (fd < 0) fd = -fd; 00074 return (fd <= LTLast && LinkBat[fd] ? LinkTab[fd] : 0); 00075 } 00076 00077 //----------------------------------------------------------------------------- 00085 //----------------------------------------------------------------------------- 00086 00087 static XrdLink *fd2link(int fd, unsigned int inst) 00088 {if (fd < 0) fd = -fd; 00089 if (fd <= LTLast && LinkBat[fd] && LinkTab[fd] 00090 && LinkTab[fd]->Instance == inst) return LinkTab[fd]; 00091 return (XrdLink *)0; 00092 } 00093 00094 //----------------------------------------------------------------------------- 00101 //----------------------------------------------------------------------------- 00102 00103 static XrdPollInfo *fd2PollInfo(int fd) 00104 {if (fd < 0) fd = -fd; 00105 if (fd <= LTLast && LinkBat[fd]) 00106 return &(LinkTab[fd]->PollInfo); 00107 return 0; 00108 } 00109 00110 //----------------------------------------------------------------------------- 00124 //----------------------------------------------------------------------------- 00125 00126 static XrdLink *Find(int &curr, XrdLinkMatch *who=0); 00127 00128 //----------------------------------------------------------------------------- 00142 //----------------------------------------------------------------------------- 00143 00144 static int getName(int &curr, char *bname, int blen, XrdLinkMatch *who=0); 00145 00146 //----------------------------------------------------------------------------- 00148 //----------------------------------------------------------------------------- 00149 00150 static void idleScan(); 00151 00152 //----------------------------------------------------------------------------- 00158 //----------------------------------------------------------------------------- 00159 00160 static void setKWT(int wkSec, int kwSec); 00161 00162 //----------------------------------------------------------------------------- 00170 //----------------------------------------------------------------------------- 00171 00172 static int Setup(int maxfds, int idlewt); 00173 00174 //----------------------------------------------------------------------------- 00176 //----------------------------------------------------------------------------- 00177 00178 static void SyncAll(); 00179 00180 //----------------------------------------------------------------------------- 00182 //----------------------------------------------------------------------------- 00183 00184 static void Unhook(int fd); 00185 00186 //----------------------------------------------------------------------------- 00188 //----------------------------------------------------------------------------- 00189 00190 static short killWait; // Kill then wait; 00191 static short waitKill; // Wait then kill 00192 00193 //----------------------------------------------------------------------------- 00195 //----------------------------------------------------------------------------- 00196 00197 XrdLinkCtl() {} 00198 00199 private: 00200 ~XrdLinkCtl() {} // Is never deleted! 00201 00202 static XrdSysMutex LTMutex; // For the LinkTab only LTMutex->IOMutex allowed 00203 static XrdLinkCtl **LinkTab; 00204 static char *LinkBat; 00205 static unsigned int LinkAlloc; 00206 static int LTLast; 00207 static int maxFD; 00208 static const char *TraceID; 00209 }; 00210 #endif