XRootD
Loading...
Searching...
No Matches
XrdOucCache.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d O u c C a c h e . c c */
4/* */
5/* (c) 2020 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* All Rights Reserved */
7/* Produced by Andrew Hanushevsky for Stanford University under contract */
8/* DE-AC02-76-SFO0515 with the Department of Energy */
9/* */
10/* This file is part of the XRootD software suite. */
11/* */
12/* XRootD is free software: you can redistribute it and/or modify it under */
13/* the terms of the GNU Lesser General Public License as published by the */
14/* Free Software Foundation, either version 3 of the License, or (at your */
15/* option) any later version. */
16/* */
17/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20/* License for more details. */
21/* */
22/* You should have received a copy of the GNU Lesser General Public License */
23/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25/* */
26/* The copyright holder's institutional names and contributor's names may not */
27/* be used to endorse or promote products derived from this software without */
28/* specific prior written permission of the institution or contributor. */
29/******************************************************************************/
30
31#include "XrdOuc/XrdOucCache.hh"
34
35/******************************************************************************/
36/* p g R e a d */
37/******************************************************************************/
38
39int XrdOucCacheIO::pgRead(char *buff,
40 long long offs,
41 int rdlen,
42 std::vector<uint32_t> &csvec,
43 uint64_t opts,
44 int *csfix)
45{
46 (void)csfix;
47 int bytes;
48
49// Read the data into the buffer
50//
51 bytes = Read(buff, offs, rdlen);
52
53// Calculate checksums if so wanted
54//
55 if (bytes > 0 && (opts & forceCS))
56 XrdOucPgrwUtils::csCalc((const char *)buff, (ssize_t)offs,
57 (size_t)bytes, csvec);
58
59// All done
60//
61 return bytes;
62}
63
64/******************************************************************************/
65/* p g W r i t e */
66/******************************************************************************/
67
69 long long offs,
70 int wrlen,
71 std::vector<uint32_t> &csvec,
72 uint64_t opts,
73 int *csfix)
74{
75 (void)csvec; (void)opts; (void)csfix;
76
77// Now just return the result of a plain write
78//
79 return Write(buff, offs, wrlen);
80}
81
82/******************************************************************************/
83/* R e a d V */
84/******************************************************************************/
85
86int XrdOucCacheIO::ReadV(const XrdOucIOVec *readV, int rnum)
87{
88 int nbytes = 0, curCount = 0;
89
90 for (int i = 0; i < rnum; i++)
91 {curCount = Read(readV[i].data, readV[i].offset, readV[i].size);
92 if (curCount != readV[i].size)
93 return (curCount < 0 ? curCount : -ESPIPE);
94 nbytes += curCount;
95 }
96 return nbytes;
97}
98
99/******************************************************************************/
100/* W r i t e V */
101/******************************************************************************/
102
103int XrdOucCacheIO::WriteV(const XrdOucIOVec *writV, int wnum)
104{
105 int nbytes = 0, curCount = 0;
106
107 for (int i = 0; i < wnum; i++)
108 {curCount = Write(writV[i].data, writV[i].offset, writV[i].size);
109 if (curCount != writV[i].size)
110 {if (curCount < 0) return curCount;
111 return -ESPIPE;
112 }
113 nbytes += curCount;
114 }
115 return nbytes;
116}
struct myOpts opts
virtual int WriteV(const XrdOucIOVec *writV, int wnum)
virtual int Read(char *buff, long long offs, int rlen)=0
virtual int Write(char *buff, long long offs, int wlen)=0
static const uint64_t forceCS
virtual int pgRead(char *buff, long long offs, int rdlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0)
virtual int pgWrite(char *buff, long long offs, int wrlen, std::vector< uint32_t > &csvec, uint64_t opts=0, int *csfix=0)
virtual int ReadV(const XrdOucIOVec *readV, int rnum)
static void csCalc(const char *data, off_t offs, size_t count, uint32_t *csval)