23constexpr int kDefaultBlockSize = 128 * 1024;
30 RDavixFileDes() : fd(nullptr), pos(&ctx) {}
31 RDavixFileDes(
const RDavixFileDes &) =
delete;
32 RDavixFileDes &
operator=(
const RDavixFileDes &) =
delete;
33 ~RDavixFileDes() =
default;
45 :
RRawFile(url, options), fFileDes(new RDavixFileDes())
51 if (fFileDes->fd !=
nullptr)
52 fFileDes->pos.close(fFileDes->fd,
nullptr);
57 return std::make_unique<RRawFileDavix>(fUrl, fOptions);
63 Davix::DavixError *err =
nullptr;
64 if (fFileDes->pos.stat(
nullptr, fUrl, &buf, &err) == -1) {
65 throw std::runtime_error(
"Cannot determine size of '" + fUrl +
"', error: " + err->getErrMsg());
72 Davix::DavixError *err =
nullptr;
73 fFileDes->fd = fFileDes->pos.open(
nullptr, fUrl, O_RDONLY, &err);
74 if (fFileDes->fd ==
nullptr) {
75 throw std::runtime_error(
"Cannot open '" + fUrl +
"', error: " + err->getErrMsg());
77 if (fOptions.fBlockSize < 0)
78 fOptions.fBlockSize = kDefaultBlockSize;
83 Davix::DavixError *err =
nullptr;
84 auto retval = fFileDes->pos.pread(fFileDes->fd, buffer, nbytes, offset, &err);
86 throw std::runtime_error(
"Cannot read from '" + fUrl +
"', error: " + err->getErrMsg());
88 return static_cast<size_t>(retval);
93 Davix::DavixError *davixErr = NULL;
94 Davix::DavIOVecInput in[nReq];
95 Davix::DavIOVecOuput out[nReq];
97 for (
unsigned int i = 0; i < nReq; ++i) {
98 in[i].diov_buffer = ioVec[i].
fBuffer;
99 in[i].diov_offset = ioVec[i].
fOffset;
100 in[i].diov_size = ioVec[i].
fSize;
104 auto ret = fFileDes->pos.preadVec(fFileDes->fd, in, out, nReq, &davixErr);
106 throw std::runtime_error(
"Cannot do vector read from '" + fUrl +
"', error: " + davixErr->getErrMsg());
109 for (
unsigned int i = 0; i < nReq; ++i) {
Binding & operator=(OUT(*fun)(void))
void ReadVImpl(RIOVec *ioVec, unsigned int nReq) final
By default implemented as a loop of ReadAt calls but can be overwritten, e.g. XRootD or DAVIX impleme...
size_t ReadAtImpl(void *buffer, size_t nbytes, std::uint64_t offset) final
Derived classes should implement low-level reading without buffering.
std::unique_ptr< RRawFile > Clone() const final
Create a new RawFile that accesses the same resource. The file pointer is reset to zero.
RRawFileDavix(std::string_view url, RRawFile::ROptions options)
std::uint64_t GetSizeImpl() final
Derived classes should return the file size or kUnknownFileSize.
void OpenImpl() final
OpenImpl() is called at most once and before any call to either DoReadAt or DoGetSize.
The RRawFile provides read-only access to local and remote files.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Used for vector reads from multiple offsets into multiple buffers.
std::size_t fOutBytes
The number of actually read bytes, set by ReadV()
std::size_t fSize
The number of desired bytes.
void * fBuffer
The destination for reading.
std::uint64_t fOffset
The file offset.
On construction, an ROptions parameter can customize the RRawFile behavior.