proxygen
folly::fileutil_detail Namespace Reference

Functions

template<class F , class... Args>
ssize_t wrapNoInt (F f, Args...args)
 
void incr (ssize_t)
 
void incr (ssize_t n, off_t &offset)
 
template<class F , class... Offset>
ssize_t wrapFull (F f, int fd, void *buf, size_t count, Offset...offset)
 
template<class F , class... Offset>
ssize_t wrapvFull (F f, int fd, iovec *iov, int count, Offset...offset)
 

Function Documentation

void folly::fileutil_detail::incr ( ssize_t  )
inline

Definition at line 42 of file FileUtilDetail.h.

Referenced by TEST(), wrapFull(), and wrapvFull().

42 {}
void folly::fileutil_detail::incr ( ssize_t  n,
off_t &  offset 
)
inline

Definition at line 43 of file FileUtilDetail.h.

43  {
44  offset += off_t(n);
45 }
template<class F , class... Offset>
ssize_t folly::fileutil_detail::wrapFull ( f,
int  fd,
void *  buf,
size_t  count,
Offset...  offset 
)

Definition at line 53 of file FileUtilDetail.h.

References b, f, and incr().

Referenced by folly::preadFull(), folly::pwriteFull(), folly::readFull(), folly::test::TEST_F(), and folly::writeFull().

53  {
54  char* b = static_cast<char*>(buf);
55  ssize_t totalBytes = 0;
56  ssize_t r;
57  do {
58  r = f(fd, b, count, offset...);
59  if (r == -1) {
60  if (errno == EINTR) {
61  continue;
62  }
63  return r;
64  }
65 
66  totalBytes += r;
67  b += r;
68  count -= r;
69  incr(r, offset...);
70  } while (r != 0 && count); // 0 means EOF
71 
72  return totalBytes;
73 }
auto f
char b
int * count
void incr(ssize_t n, off_t &offset)
template<class F , class... Args>
ssize_t folly::fileutil_detail::wrapNoInt ( f,
Args...  args 
)
template<class F , class... Offset>
ssize_t folly::fileutil_detail::wrapvFull ( f,
int  fd,
iovec *  iov,
int  count,
Offset...  offset 
)

Definition at line 78 of file FileUtilDetail.h.

References count, f, incr(), and folly::kIovMax.

Referenced by folly::preadvFull(), folly::pwritevFull(), folly::readvFull(), folly::test::TEST(), folly::test::TEST_F(), and folly::writevFull().

78  {
79  ssize_t totalBytes = 0;
80  ssize_t r;
81  do {
82  r = f(fd, iov, std::min<int>(count, kIovMax), offset...);
83  if (r == -1) {
84  if (errno == EINTR) {
85  continue;
86  }
87  return r;
88  }
89 
90  if (r == 0) {
91  break; // EOF
92  }
93 
94  totalBytes += r;
95  incr(r, offset...);
96  while (r != 0 && count != 0) {
97  if (r >= ssize_t(iov->iov_len)) {
98  r -= ssize_t(iov->iov_len);
99  ++iov;
100  --count;
101  } else {
102  iov->iov_base = static_cast<char*>(iov->iov_base) + r;
103  iov->iov_len -= r;
104  r = 0;
105  }
106  }
107  } while (count);
108 
109  return totalBytes;
110 }
auto f
constexpr size_t kIovMax
Definition: SysUio.h:39
int * count
void incr(ssize_t n, off_t &offset)