xrootd
Loading...
Searching...
No Matches
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
37public:
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
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
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};
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 {
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
127
135 static int Configure(XrdSysError &Eroute, const char *const parms,
136 Configuration &cfg);
137
143 const Error& getError() const;
144
151
159
170
185
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
242private:
243 int parseOneRange(char* const str);
244 int rangeFig(const char* const s, bool &set, off_t &start);
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
275
279};
280
281
282#endif //XROOTD_XRDHTTPREADRANGEHANDLER_HH
Utility functions for XrdHTTP.
std::vector< XrdOucIOVec2 > XrdHttpIOList
Definition XrdHttpUtils.hh:95
Definition XrdHttpReadRangeHandler.hh:36
off_t splitRangeOff_
Definition XrdHttpReadRangeHandler.hh:267
static constexpr size_t READV_MAXCHUNKSIZE
Definition XrdHttpReadRangeHandler.hh:46
off_t resolvedRangeOff_
Definition XrdHttpReadRangeHandler.hh:262
const XrdHttpIOList & NextReadList()
void ParseContentRange(const char *const line)
int SetFilesize(const off_t sz)
XrdHttpReadRangeHandler(const Configuration &conf)
Definition XrdHttpReadRangeHandler.hh:113
UserRangeList resolvedUserRanges_
Definition XrdHttpReadRangeHandler.hh:255
static int Configure(XrdSysError &Eroute, const char *const parms, Configuration &cfg)
int parseOneRange(char *const str)
bool rangesResolved_
Definition XrdHttpReadRangeHandler.hh:253
size_t currSplitRangeIdx_
Definition XrdHttpReadRangeHandler.hh:271
std::vector< UserRange > UserRangeList
Definition XrdHttpReadRangeHandler.hh:103
size_t vectorReadMaxChunks_
Definition XrdHttpReadRangeHandler.hh:277
XrdHttpIOList splitRange_
Definition XrdHttpReadRangeHandler.hh:257
const Error & getError() const
int NotifyReadResult(const ssize_t ret, const UserRange **const urp, bool &start, bool &allend)
size_t splitRangeIdx_
Definition XrdHttpReadRangeHandler.hh:266
UserRangeList rawUserRanges_
Definition XrdHttpReadRangeHandler.hh:251
size_t rRequestMaxBytes_
Definition XrdHttpReadRangeHandler.hh:278
int currSplitRangeOff_
Definition XrdHttpReadRangeHandler.hh:272
int rangeFig(const char *const s, bool &set, off_t &start)
size_t vectorReadMaxChunkSize_
Definition XrdHttpReadRangeHandler.hh:276
size_t resolvedRangeIdx_
Definition XrdHttpReadRangeHandler.hh:261
const UserRangeList & ListResolvedRanges()
Error error_
Definition XrdHttpReadRangeHandler.hh:249
static constexpr size_t RREQ_MAXSIZE
Definition XrdHttpReadRangeHandler.hh:47
off_t filesize_
Definition XrdHttpReadRangeHandler.hh:274
static constexpr size_t READV_MAXCHUNKS
Definition XrdHttpReadRangeHandler.hh:45
Definition XrdSysError.hh:90
Definition XrdHttpReadRangeHandler.hh:54
size_t readv_iov_max
Definition XrdHttpReadRangeHandler.hh:66
Configuration(const size_t vectorReadMaxChunkSize, const size_t vectorReadMaxChunks, const size_t rRequestMaxBytes)
Definition XrdHttpReadRangeHandler.hh:57
Configuration()
Definition XrdHttpReadRangeHandler.hh:55
size_t reqs_max
Definition XrdHttpReadRangeHandler.hh:67
bool haveSizes
Definition XrdHttpReadRangeHandler.hh:64
size_t readv_ior_max
Definition XrdHttpReadRangeHandler.hh:65
Definition XrdHttpReadRangeHandler.hh:74
void set(int rc, const std::string &m)
Definition XrdHttpReadRangeHandler.hh:81
bool errSet
Definition XrdHttpReadRangeHandler.hh:75
void reset()
Definition XrdHttpReadRangeHandler.hh:84
std::string errMsg
Definition XrdHttpReadRangeHandler.hh:77
int httpRetCode
Definition XrdHttpReadRangeHandler.hh:76
Definition XrdHttpReadRangeHandler.hh:91
off_t start
Definition XrdHttpReadRangeHandler.hh:94
bool start_set
Definition XrdHttpReadRangeHandler.hh:92
bool end_set
Definition XrdHttpReadRangeHandler.hh:93
UserRange(off_t st, off_t en)
Definition XrdHttpReadRangeHandler.hh:99
off_t end
Definition XrdHttpReadRangeHandler.hh:95
UserRange()
Definition XrdHttpReadRangeHandler.hh:97