xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
XrdHttpReadRangeHandler.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of XrdHTTP: A pragmatic implementation of the
3 // HTTP/WebDAV protocol for the Xrootd framework
4 //
5 // Copyright (c) 2013 by European Organization for Nuclear Research (CERN)
6 // Authors: Cedric Caffy <ccaffy@cern.ch>, David Smith
7 // File Date: Aug 2023
8 //------------------------------------------------------------------------------
9 // XRootD is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU Lesser General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // XRootD is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public License
20 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
21 //------------------------------------------------------------------------------
22 
23 #ifndef XROOTD_XRDHTTPREADRANGEHANDLER_HH
24 #define XROOTD_XRDHTTPREADRANGEHANDLER_HH
25 
26 #include "XrdHttpUtils.hh"
27 #include <vector>
28 #include <string>
29 
30 
37 public:
38 
45  static constexpr size_t READV_MAXCHUNKS = 512;
46  static constexpr size_t READV_MAXCHUNKSIZE = 512*1024;
47  static constexpr size_t RREQ_MAXSIZE = 8*1024*1024;
48 
54  struct Configuration {
55  Configuration() : haveSizes(false) { }
56 
57  Configuration(const size_t vectorReadMaxChunkSize,
58  const size_t vectorReadMaxChunks,
59  const size_t rRequestMaxBytes) :
60  haveSizes(true), readv_ior_max(vectorReadMaxChunkSize),
61  readv_iov_max(vectorReadMaxChunks), reqs_max(rRequestMaxBytes) { }
62 
63 
64  bool haveSizes;
65  size_t readv_ior_max; // max chunk size
66  size_t readv_iov_max; // max number of chunks
67  size_t reqs_max; // max bytes in read or readv
68  };
69 
74  struct Error {
75  bool errSet{false};
76  int httpRetCode{0};
77  std::string errMsg;
78 
79  explicit operator bool() const { return errSet; }
80 
81  void set(int rc, const std::string &m)
82  { httpRetCode = rc; errMsg = m; errSet = true; }
83 
84  void reset() { httpRetCode = 0; errMsg.clear(); errSet = false; }
85  };
86 
91  struct UserRange {
92  bool start_set;
93  bool end_set;
94  off_t start;
95  off_t end;
96 
97  UserRange() : start_set(false), end_set(false), start(0), end(0) { }
98 
99  UserRange(off_t st, off_t en) : start_set(true), end_set(true), start(st),
100  end(en) { }
101  };
102 
103  typedef std::vector<UserRange> UserRangeList;
104 
114  {
118 
119  if( conf.haveSizes )
120  {
124  }
125  reset();
126  }
127 
135  static int Configure(XrdSysError &Eroute, const char *const parms,
136  Configuration &cfg);
137 
143  const Error& getError() const;
144 
150  bool isFullFile();
151 
158  bool isSingleRange();
159 
170 
184  const XrdHttpIOList &NextReadList();
185 
190  void NotifyError();
191 
209  int NotifyReadResult(const ssize_t ret,
210  const UserRange** const urp,
211  bool &start,
212  bool &allend);
213 
222  void ParseContentRange(const char* const line);
223 
227  void reset();
228 
240  int SetFilesize(const off_t sz);
241 
242 private:
243  int parseOneRange(char* const str);
244  int rangeFig(const char* const s, bool &set, off_t &start);
245  void resolveRanges();
246  void splitRanges();
247  void trimSplit();
248 
250 
252 
254 
256 
258 
259  // the position in resolvedUserRanges_ corresponding to all the
260  // bytes notified via the NotifyReadResult() method
263 
264  // position of the method splitRanges() in within resolvedUserRanges_
265  // from where it split ranges into chunks for sending to read/readv
268 
269  // the position in splitRange_ corresponding to all the
270  // bytes notified via the NotifyReadResult() method
273 
274  off_t filesize_;
275 
279 };
280 
281 
282 #endif //XROOTD_XRDHTTPREADRANGEHANDLER_HH
UserRangeList rawUserRanges_
Definition: XrdHttpReadRangeHandler.hh:251
off_t start
Definition: XrdHttpReadRangeHandler.hh:94
UserRange(off_t st, off_t en)
Definition: XrdHttpReadRangeHandler.hh:99
Definition: XrdHttpReadRangeHandler.hh:74
std::vector< XrdOucIOVec2 > XrdHttpIOList
Definition: XrdHttpUtils.hh:95
std::vector< UserRange > UserRangeList
Definition: XrdHttpReadRangeHandler.hh:103
size_t currSplitRangeIdx_
Definition: XrdHttpReadRangeHandler.hh:271
size_t rRequestMaxBytes_
Definition: XrdHttpReadRangeHandler.hh:278
size_t reqs_max
Definition: XrdHttpReadRangeHandler.hh:67
std::string errMsg
Definition: XrdHttpReadRangeHandler.hh:77
Configuration(const size_t vectorReadMaxChunkSize, const size_t vectorReadMaxChunks, const size_t rRequestMaxBytes)
Definition: XrdHttpReadRangeHandler.hh:57
size_t vectorReadMaxChunks_
Definition: XrdHttpReadRangeHandler.hh:277
Utility functions for XrdHTTP.
const XrdHttpIOList & NextReadList()
size_t readv_ior_max
Definition: XrdHttpReadRangeHandler.hh:65
int parseOneRange(char *const str)
Error error_
Definition: XrdHttpReadRangeHandler.hh:249
XrdHttpIOList splitRange_
Definition: XrdHttpReadRangeHandler.hh:257
static constexpr size_t READV_MAXCHUNKS
Definition: XrdHttpReadRangeHandler.hh:45
static constexpr size_t READV_MAXCHUNKSIZE
Definition: XrdHttpReadRangeHandler.hh:46
Definition: XrdSysError.hh:89
int rangeFig(const char *const s, bool &set, off_t &start)
UserRange()
Definition: XrdHttpReadRangeHandler.hh:97
size_t resolvedRangeIdx_
Definition: XrdHttpReadRangeHandler.hh:261
void ParseContentRange(const char *const line)
Definition: XrdHttpReadRangeHandler.hh:91
const Error & getError() const
bool end_set
Definition: XrdHttpReadRangeHandler.hh:93
size_t readv_iov_max
Definition: XrdHttpReadRangeHandler.hh:66
int NotifyReadResult(const ssize_t ret, const UserRange **const urp, bool &start, bool &allend)
XrdHttpReadRangeHandler(const Configuration &conf)
Definition: XrdHttpReadRangeHandler.hh:113
off_t end
Definition: XrdHttpReadRangeHandler.hh:95
int httpRetCode
Definition: XrdHttpReadRangeHandler.hh:76
static int Configure(XrdSysError &Eroute, const char *const parms, Configuration &cfg)
Definition: XrdHttpReadRangeHandler.hh:54
int SetFilesize(const off_t sz)
void reset()
Definition: XrdHttpReadRangeHandler.hh:84
void set(int rc, const std::string &m)
Definition: XrdHttpReadRangeHandler.hh:81
size_t splitRangeIdx_
Definition: XrdHttpReadRangeHandler.hh:266
Configuration()
Definition: XrdHttpReadRangeHandler.hh:55
off_t filesize_
Definition: XrdHttpReadRangeHandler.hh:274
bool rangesResolved_
Definition: XrdHttpReadRangeHandler.hh:253
UserRangeList resolvedUserRanges_
Definition: XrdHttpReadRangeHandler.hh:255
size_t vectorReadMaxChunkSize_
Definition: XrdHttpReadRangeHandler.hh:276
const UserRangeList & ListResolvedRanges()
off_t splitRangeOff_
Definition: XrdHttpReadRangeHandler.hh:267
bool start_set
Definition: XrdHttpReadRangeHandler.hh:92
static constexpr size_t RREQ_MAXSIZE
Definition: XrdHttpReadRangeHandler.hh:47
Definition: XrdTlsNotaryUtils.hh:42
off_t resolvedRangeOff_
Definition: XrdHttpReadRangeHandler.hh:262
int currSplitRangeOff_
Definition: XrdHttpReadRangeHandler.hh:272
bool haveSizes
Definition: XrdHttpReadRangeHandler.hh:64
Definition: XrdHttpReadRangeHandler.hh:36