27 template <
class F,
class...
Args>
29 off_t origLoc = lseek(fd, 0, SEEK_CUR);
30 if (origLoc == off_t(-1)) {
33 if (lseek(fd, offset, SEEK_SET) == off_t(-1)) {
37 int res = (int)
f(fd, args...);
40 if (lseek(fd, origLoc, SEEK_SET) == off_t(-1)) {
51 #if !FOLLY_HAVE_PREADV 52 extern "C" ssize_t
preadv(
int fd,
const iovec* iov,
int count, off_t offset) {
57 #if !FOLLY_HAVE_PWRITEV 58 extern "C" ssize_t
pwritev(
int fd,
const iovec* iov,
int count, off_t offset) {
64 template <
bool isRead>
65 static ssize_t doVecOperation(
int fd,
const iovec* iov,
int count) {
78 bool shouldLock = !folly::portability::sockets::is_fh_socket(fd);
79 if (shouldLock && lockf(fd, F_LOCK, 0) == -1) {
84 lockf(fd, F_ULOCK, 0);
88 ssize_t bytesProcessed = 0;
90 void* curBase = iov[0].iov_base;
91 size_t curLen = iov[0].iov_len;
92 while (curIov < count) {
95 res =
read(fd, curBase, (
unsigned int)curLen);
96 if (res == 0 && curLen != 0) {
100 res =
write(fd, curBase, (
unsigned int)curLen);
108 if (
size_t(res) == curLen) {
110 if (curIov < count) {
111 curBase = iov[curIov].iov_base;
112 curLen = iov[curIov].iov_len;
115 curBase = (
void*)((
char*)curBase + res);
119 if (bytesProcessed + res < 0) {
124 bytesProcessed += res;
127 return bytesProcessed;
130 extern "C" ssize_t readv(
int fd,
const iovec* iov,
int count) {
131 return doVecOperation<true>(fd, iov,
count);
134 extern "C" ssize_t writev(
int fd,
const iovec* iov,
int count) {
135 return doVecOperation<false>(fd, iov,
count);
void write(const T &in, folly::io::Appender &appender)
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
ssize_t pwritev(int fd, const iovec *iov, int count, off_t offset)
size_t read(T &out, folly::io::Cursor &cursor)
static int wrapPositional(F f, int fd, off_t offset, Args...args)
ssize_t preadv(int fd, const iovec *iov, int count, off_t offset)