xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
XrdXrootdPgwFob.hh
Go to the documentation of this file.
1 #ifndef __XRDXROOTDPGWFOB_HH_
2 #define __XRDXROOTDPGWFOB_HH_
3 /******************************************************************************/
4 /* */
5 /* X r d X r o o t d P g w F o b . h h */
6 /* */
7 /* (c) 2021 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 <set>
33 #include <cstring>
34 
35 #include "XProtocol/XProtocol.hh"
36 #include "XrdSys/XrdSysPthread.hh"
37 
38 class XrdOucString;
39 class XrdXrootdFile;
40 
42 {
43 public:
44 
45 
46 bool addOffs(kXR_int64 foffs, int dlen)
48  foffs = foffs << XrdProto::kXR_pgPageBL;
49  if (dlen < XrdProto::kXR_pgPageSZ) foffs |= dlen;
50  badOffs.insert(foffs);
51  numErrs++;
52  return badOffs.size() <= XrdProto::kXR_pgMaxEos;
53  }
54 
55 bool delOffs(kXR_int64 foffs, int dlen)
57  foffs = foffs << XrdProto::kXR_pgPageBL;
58  if (dlen < XrdProto::kXR_pgPageSZ) foffs |= dlen;
59  numFixd++;
60  return badOffs.erase(foffs) != 0;
61  }
62 
63 bool hasOffs(kXR_int64 foffs, int dlen)
65  foffs = foffs << XrdProto::kXR_pgPageBL;
66  if (dlen < XrdProto::kXR_pgPageSZ) foffs |= dlen;
67  return badOffs.find(foffs) != badOffs.end();
68  }
69 
70 int numOffs(int *errs=0, int *fixs=0)
72  if (errs) *errs = numErrs;
73  if (fixs) *fixs = numFixd;
74  return badOffs.size();
75  }
76 
78  : fileP(fP), numErrs(0), numFixd(0) {}
79 
81 
82 private:
83 
86 std::set<kXR_int64> badOffs; // Uncorrected offsets
87 int numErrs;
88 int numFixd;
89 };
90 #endif
int numOffs(int *errs=0, int *fixs=0)
Definition: XrdXrootdPgwFob.hh:70
XrdXrootdFile * fileP
Definition: XrdXrootdPgwFob.hh:84
int numErrs
Definition: XrdXrootdPgwFob.hh:87
bool hasOffs(kXR_int64 foffs, int dlen)
Definition: XrdXrootdPgwFob.hh:63
XrdXrootdPgwFob(XrdXrootdFile *fP)
Definition: XrdXrootdPgwFob.hh:77
Definition: XrdXrootdPgwFob.hh:41
Definition: XrdXrootdFile.hh:100
Definition: XrdSysPthread.hh:164
static const int kXR_pgPageBL
Definition: XProtocol.hh:490
bool addOffs(kXR_int64 foffs, int dlen)
Definition: XrdXrootdPgwFob.hh:46
XrdSysMutex fobMutex
Definition: XrdXrootdPgwFob.hh:85
bool delOffs(kXR_int64 foffs, int dlen)
Definition: XrdXrootdPgwFob.hh:55
static const int kXR_pgMaxEos
Definition: XProtocol.hh:493
static const int kXR_pgPageSZ
Definition: XProtocol.hh:489
std::set< kXR_int64 > badOffs
Definition: XrdXrootdPgwFob.hh:86
int numFixd
Definition: XrdXrootdPgwFob.hh:88
long long kXR_int64
Definition: XPtypes.hh:98
Definition: XrdOucString.hh:254
Definition: XrdSysPthread.hh:262