File indexing completed on 2026-01-08 10:33:33
0001 #ifndef __OFS_HANDLE__
0002 #define __OFS_HANDLE__
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 #include <cstdlib>
0038
0039 #include "XrdOuc/XrdOucCRC.hh"
0040 #include "XrdSys/XrdSysPthread.hh"
0041
0042
0043
0044
0045
0046 class XrdOfsHanKey
0047 {
0048 public:
0049
0050 const char *Val;
0051 unsigned int Links;
0052 unsigned int Hash;
0053 short Len;
0054
0055 inline XrdOfsHanKey& operator=(const XrdOfsHanKey &rhs)
0056 {Val = strdup(rhs.Val); Hash = rhs.Hash;
0057 Len = rhs.Len;
0058 return *this;
0059 }
0060
0061 inline int operator==(const XrdOfsHanKey &oth)
0062 {return Hash == oth.Hash && Len == oth.Len
0063 && !strcmp(Val, oth.Val);
0064 }
0065
0066 inline int operator!=(const XrdOfsHanKey &oth)
0067 {return Hash != oth.Hash || Len != oth.Len
0068 || strcmp(Val, oth.Val);
0069 }
0070
0071 XrdOfsHanKey(const char *key=0, int kln=0)
0072 : Val(key), Links(0), Len(kln)
0073 {Hash = (key && kln ?
0074 XrdOucCRC::CRC32((const unsigned char *)key,kln) : 0);
0075 }
0076
0077 XrdOfsHanKey(const XrdOfsHanKey&) = default;
0078
0079 ~XrdOfsHanKey() {};
0080 };
0081
0082
0083
0084
0085
0086 class XrdOfsHandle;
0087
0088 class XrdOfsHanTab
0089 {
0090 public:
0091 void Add(XrdOfsHandle *hP);
0092
0093 XrdOfsHandle *Find(XrdOfsHanKey &Key);
0094
0095 int Remove(XrdOfsHandle *rip);
0096
0097
0098
0099
0100
0101 XrdOfsHanTab(int psize = 987, int size = 1597);
0102 ~XrdOfsHanTab() {}
0103
0104 private:
0105
0106 static const int LoadMax = 80;
0107
0108 void Expand();
0109
0110 XrdOfsHandle **nashtable;
0111 int prevtablesize;
0112 int nashtablesize;
0113 int nashnum;
0114 int Threshold;
0115 };
0116
0117
0118
0119
0120
0121 class XrdOssDF;
0122 class XrdOfsHanCB;
0123 class XrdOfsHanPsc;
0124
0125 class XrdOfsHandle
0126 {
0127 friend class XrdOfsHanTab;
0128 friend class XrdOfsHanXpr;
0129 public:
0130
0131 char isPending;
0132 char isChanged;
0133 char isCompressed;
0134 char isRW;
0135
0136 void Activate(XrdOssDF *ssP) {ssi = ssP;}
0137
0138 static const int opRW = 1;
0139 static const int opPC = 3;
0140
0141 static int Alloc(const char *thePath,int Opts,XrdOfsHandle **Handle);
0142 static int Alloc( XrdOfsHandle **Handle);
0143
0144 static void Hide(const char *thePath);
0145
0146 inline int Inactive() {return (ssi == ossDF);}
0147
0148 inline const char *Name() {return Path.Val;}
0149
0150 int PoscGet(short &Mode, int Done=0);
0151
0152 int PoscSet(const char *User, int Unum, short Mode);
0153
0154 const char *PoscUsr();
0155
0156 int Retire(int &retc, long long *retsz=0,
0157 char *buff=0, int blen=0);
0158
0159 int Retire(XrdOfsHanCB *, int DSec);
0160
0161 XrdOssDF &Select(void) {return *ssi;}
0162
0163 static int StartXpr(int Init=0);
0164
0165 void Suppress(int rrc=-EDOM, int wrc=-EDOM);
0166
0167 int Usage() {return Path.Links;}
0168
0169 inline void Lock() {hMutex.Lock();}
0170 inline void UnLock() {hMutex.UnLock();}
0171
0172 XrdOfsHandle() : Path(0,0) {}
0173
0174 ~XrdOfsHandle() {int retc; Retire(retc);}
0175
0176 private:
0177 static int Alloc(XrdOfsHanKey, int Opts, XrdOfsHandle **Handle);
0178 int WaitLock(void);
0179
0180 static const int LockTries = 3;
0181 static const int LockWait = 333;
0182 static const int nolokDelay= 3;
0183 static const int nomemDelay= 15;
0184
0185 static XrdSysMutex myMutex;
0186 static XrdOfsHanTab roTable;
0187 static XrdOfsHanTab rwTable;
0188 static XrdOssDF *ossDF;
0189 static XrdOfsHandle *Free;
0190
0191 XrdSysMutex hMutex;
0192 XrdOssDF *ssi;
0193 XrdOfsHandle *Next;
0194 XrdOfsHanKey Path;
0195 XrdOfsHanPsc *Posc;
0196 };
0197
0198
0199
0200
0201
0202 class XrdOfsHanCB
0203 {
0204 public:
0205
0206 virtual void Retired(XrdOfsHandle *) = 0;
0207
0208 XrdOfsHanCB() {}
0209 virtual ~XrdOfsHanCB() {}
0210 };
0211 #endif