Skip to content

Commit

Permalink
[davix] Avoid code repetition in private TDavix file member functions
Browse files Browse the repository at this point in the history
  • Loading branch information
guitargeek committed Feb 5, 2025
1 parent b470726 commit d032ff8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 27 deletions.
3 changes: 1 addition & 2 deletions net/davix/inc/TDavixFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ class TDavixFile : public TFile {
TDavixFileInternal* d_ptr;

void Init(Bool_t init);
Long64_t DavixReadBuffer(Davix_fd *fd, char *buf, Int_t len);
Long64_t DavixPReadBuffer(Davix_fd *fd, char *buf, Long64_t pos, Int_t len);
Long64_t DavixReadBuffer(Davix_fd *fd, char *buf, Long64_t pos, Int_t len);
Long64_t DavixReadBuffers(Davix_fd *fd, char *buf, Long64_t *pos, Int_t *len, Int_t nbuf);
Long64_t DavixWriteBuffer(Davix_fd *fd, const char *buf, Int_t len);
Int_t DavixStat(struct stat *st) const;
Expand Down
31 changes: 6 additions & 25 deletions net/davix/src/TDavixFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,8 @@ Bool_t TDavixFile::ReadBuffer(char *buf, Int_t len)
Davix_fd *fd;
if ((fd = d_ptr->getDavixFileInstance()) == NULL)
return kTRUE;
Long64_t ret = DavixReadBuffer(fd, buf, len);
Long64_t ret = DavixReadBuffer(fd, buf, fOffset, len);
fOffset += std::max((Long64_t)0, ret); // only shift offset on successful read
if (ret < 0)
return kTRUE;

Expand All @@ -760,7 +761,7 @@ Bool_t TDavixFile::ReadBuffer(char *buf, Long64_t pos, Int_t len)
if ((fd = d_ptr->getDavixFileInstance()) == NULL)
return kTRUE;

Long64_t ret = DavixPReadBuffer(fd, buf, pos, len);
Long64_t ret = DavixReadBuffer(fd, buf, pos, len);
if (ret < 0)
return kTRUE;

Expand Down Expand Up @@ -906,21 +907,21 @@ void TDavixFile::eventStop(Double_t t_start, Long64_t len, bool read)

////////////////////////////////////////////////////////////////////////////////

Long64_t TDavixFile::DavixReadBuffer(Davix_fd *fd, char *buf, Int_t len)
Long64_t TDavixFile::DavixReadBuffer(Davix_fd *fd, char *buf, Long64_t pos, Int_t len)
{
DavixError *davixErr = NULL;
Double_t start_time = eventStart();

Long64_t ret = d_ptr->davixPosix->pread(fd, buf, len, fOffset, &davixErr);
Long64_t ret = d_ptr->davixPosix->pread(fd, buf, len, pos, &davixErr);
if (ret < 0) {
Error("DavixReadBuffer", "can not read data with davix: %s (%d)",
davixErr->getErrMsg().c_str(), davixErr->getStatus());
DavixError::clearError(&davixErr);
} else {
fOffset += ret;
eventStop(start_time, ret);
}


return ret;
}

Expand All @@ -946,26 +947,6 @@ Long64_t TDavixFile::DavixWriteBuffer(Davix_fd *fd, const char *buf, Int_t len)

////////////////////////////////////////////////////////////////////////////////

Long64_t TDavixFile::DavixPReadBuffer(Davix_fd *fd, char *buf, Long64_t pos, Int_t len)
{
DavixError *davixErr = NULL;
Double_t start_time = eventStart();

Long64_t ret = d_ptr->davixPosix->pread(fd, buf, len, pos, &davixErr);
if (ret < 0) {
Error("DavixPReadBuffer", "can not read data with davix: %s (%d)",
davixErr->getErrMsg().c_str(), davixErr->getStatus());
DavixError::clearError(&davixErr);
} else {
eventStop(start_time, ret);
}


return ret;
}

////////////////////////////////////////////////////////////////////////////////

Long64_t TDavixFile::DavixReadBuffers(Davix_fd *fd, char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)
{
DavixError *davixErr = NULL;
Expand Down

0 comments on commit d032ff8

Please sign in to comment.