ewmscp  ..
Public Member Functions | List of all members
inputHandler::dcap::readerDcap Class Reference

#include <inputHandlerDcap.h>

Inheritance diagram for inputHandler::dcap::readerDcap:
[legend]
Collaboration diagram for inputHandler::dcap::readerDcap:
[legend]

Public Member Functions

 readerDcap (const std::string &aPath, copyRequest::stateType &state, const genericStat &inititalStat)
 
 ~readerDcap () override
 
bool readBlock (block &b) override
 
void checkUnchangedness () override
 
- Public Member Functions inherited from dcapIoCommon
 dcapIoCommon (const std::string &aPath)
 
std::unique_ptr< const genericStatgetStat () override
 
- Public Member Functions inherited from ioHandle
 ioHandle ()
 
virtual ~ioHandle () noexcept(false)
 
virtual bool parallelizable () const
 tell if this handler is capable of parallel IO. Unsually not the case More...
 
virtual void setXattr (const std::string &, const std::string &)
 
virtual std::string getXattr (const std::string &)
 get one extended attribute value More...
 
virtual void removeXattr (const std::string &)
 
virtual size_t getBlockSize () const
 
virtual void setBlockSize (size_t newSize)
 
virtual std::unique_ptr< attrDataTypegetAttrData (const outputHandler::base *)
 get attributes in the optimal way for setting with aOutputHandler More...
 
virtual std::unique_ptr< acl::listgetAclData ()
 get acls More...
 

Additional Inherited Members

- Protected Attributes inherited from dcapIoCommon
const std::string path
 
int fd = -1
 
- Protected Attributes inherited from ioHandle
size_t blockSize
 in bytes, block size to be used when reading or writing More...
 

Detailed Description

Definition at line 18 of file inputHandlerDcap.h.

Constructor & Destructor Documentation

◆ readerDcap()

inputHandler::dcap::readerDcap::readerDcap ( const std::string &  aPath,
copyRequest::stateType state,
const genericStat inititalStat 
)

Definition at line 22 of file inputHandlerDcap.cpp.

24  :
25  dcapIoCommon(aPath),
26  reader(inititalStat) {
27  dCapLock extraOptionLock;
28  fd = dc_open(path.c_str(), O_RDONLY);
29  if (fd == -1) {
30  if (errno == ENOENT
31  || (errno == ENOTDIR && !S_ISDIR(readInitialStat.mode))) {
33  }
34  }
35  throwcall::dcap::badval(fd, -1, "can't open ", path, " for reading");
36  blockSize = readInitialStat.blksize;
37  }

References throwcall::dcap::badval(), ioHandle::blockSize, dcapIoCommon::fd, dcapIoCommon::path, and copyRequest::vanished.

Here is the call graph for this function:

◆ ~readerDcap()

inputHandler::dcap::readerDcap::~readerDcap ( )
override

Definition at line 39 of file inputHandlerDcap.cpp.

39  {
40  if (fd != -1) {
41  dCapLock extraOptionLock;
42  if (isUnwinding()) {
43  if (dc_close(fd) != 0) {
45  path, "close during unwind ",
46  dc_strerror(dc_errno));
47  }
48  return;
49  }
50  throwcall::dcap::good0(dc_close(fd), "can't close ", path, " after reading");
51  }
52  }

References errMsg::debug, errMsg::emit(), and throwcall::dcap::good0().

Here is the call graph for this function:

Member Function Documentation

◆ checkUnchangedness()

void inputHandler::dcap::readerDcap::checkUnchangedness ( )
override

Definition at line 91 of file inputHandlerDcap.cpp.

91  {
92  struct dcapStat readFinalStatBuf;
93  dCapLock extraOptionLock;
94  throwcall::dcap::good0(dc_fstat(fd, &readFinalStatBuf), "can't stat path file ", path);
95  genericStat readFinalStat(readFinalStatBuf, std::chrono::seconds(1));
96  if (readFinalStat.size != readInitialStat.size) {
97  throw delayAdvisingError("file size has changed (" +
98  std::to_string(readInitialStat.size) +
99  " -> " +
100  std::to_string(readFinalStat.size) +
101  ") during reading on " + path);
102  }
103 
104  if (!readFinalStat.isSameMtimeAs(readInitialStat)) {
105  throw delayAdvisingError("file " + path + " was modified (" +
106  std::to_string(std::chrono::duration_cast<std::chrono::duration<double>>(readFinalStat.getMtime() - readInitialStat.getMtime()).count()) +
107  "s different mtime) during reading");
108  }
109  }

References dcapStat, genericStat::getMtime(), throwcall::dcap::good0(), genericStat::isSameMtimeAs(), and genericStat::size.

Here is the call graph for this function:

◆ readBlock()

bool inputHandler::dcap::readerDcap::readBlock ( block b)
override

Definition at line 55 of file inputHandlerDcap.cpp.

55  {
56  b.clear(totalBytesRead);
57  bool lastblock = false;
58 
59  while (b.size() + blockSize <= b.max_size()) {
61  auto bytes_read = throwcall::dcap::badval(dc_read(fd, b.bufferAt(b.size()), blockSize),
62  -1, "read failed on ", path);
63  readRateLimit.update(bytes_read);
64  if (bytes_read == 0) {
65  lastblock = true;
66  if (totalBytesRead < readInitialStat.size) {
67  throw delayAdvisingError(path + " has shrunk while reading, (" +
68  std::to_string(readInitialStat.size) +
69  " -> " +
70  std::to_string(totalBytesRead) +
71  ")");
72  }
73  break;
74  }
75  totalBytesRead += bytes_read;
76  if (totalBytesRead > readInitialStat.size) {
77  throw delayAdvisingError(path + " has grown while reading, (" +
78  std::to_string(readInitialStat.size) +
79  " -> " +
80  std::to_string(totalBytesRead) +
81  ")");
82  }
83 
84  b.bump_size(bytes_read);
85  }
86 
87  return lastblock;
88  }

References throwcall::dcap::badval(), block::bufferAt(), block::bump_size(), block::clear(), block::max_size(), readRateLimit, block::size(), throttle::watch::update(), and throttle::watch::wait().

Here is the call graph for this function:

The documentation for this class was generated from the following files:
delayAdvisingError
class for exceptions that advise for delays Exceptions of this kind are to be thrown when circumstanc...
Definition: inputHandler.h:22
throwcall::dcap::badval
T badval(T call, t badvalue, const Args &... args)
Definition: dcapCommon.h:28
block::max_size
size_t max_size() const
Definition: block.h:22
errMsg::location
class for defining the location of a error message in the source code.
Definition: errMsgQueue.h:14
dCapLock
Definition: dcapCommon.h:40
genericStat
generic stat abstraction class Used to abstract the variants of the stat structure.
Definition: genericStat.h:12
dcapStat
#define dcapStat
Definition: dcapCommon.h:7
dcapIoCommon::path
const std::string path
Definition: dcapCommon.h:76
copyRequest::stateBitType::vanished
@ vanished
block::bump_size
void bump_size(size_t additionalBytes)
Definition: block.h:33
readRateLimit
throttle::watch readRateLimit
errMsg::level::debug
@ debug
ioHandle::blockSize
size_t blockSize
in bytes, block size to be used when reading or writing
Definition: ioHandle.h:17
block::bufferAt
void * bufferAt(size_t offset)
only way to access the data in the block
Definition: block.cpp:28
dcapIoCommon::dcapIoCommon
dcapIoCommon(const std::string &aPath)
Definition: dcapCommon.cpp:181
throttle::watch::wait
void wait()
Definition: throttle.h:50
errMsg::emit
void emit(level aLogLevel, const location &loc, const std::string &aObject, const std::string &aAction, const Args &... args)
function to create and enqueue a message, this is the only way that messages should be created!
Definition: errMsgQueue.h:148
throwcall::dcap::good0
void good0(T call, const Args &... args)
Definition: dcapCommon.h:21
block::size
size_t size() const
Definition: block.h:16
block::clear
void clear(size_t aOffset)
Definition: block.h:28
dcapIoCommon::fd
int fd
Definition: dcapCommon.h:77
throttle::watch::update
void update(double units=1.0)
Definition: throttle.h:35