proxygen
SysUio.cpp File Reference
#include <folly/portability/SysUio.h>
#include <errno.h>
#include <stdio.h>
#include <folly/ScopeGuard.h>
#include <folly/portability/Sockets.h>
#include <folly/portability/SysFile.h>
#include <folly/portability/Unistd.h>

Go to the source code of this file.

Functions

template<class F , class... Args>
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)
 
ssize_t pwritev (int fd, const iovec *iov, int count, off_t offset)
 

Function Documentation

ssize_t preadv ( int  fd,
const iovec *  iov,
int  count,
off_t  offset 
)

Definition at line 52 of file SysUio.cpp.

References wrapPositional().

Referenced by folly::preadvFull().

52  {
53  return wrapPositional(readv, fd, offset, iov, count);
54 }
static int wrapPositional(F f, int fd, off_t offset, Args...args)
Definition: SysUio.cpp:28
int * count
ssize_t pwritev ( int  fd,
const iovec *  iov,
int  count,
off_t  offset 
)

Definition at line 58 of file SysUio.cpp.

References count, folly::kIovMax, fizz::detail::read(), SCOPE_EXIT, wrapPositional(), and fizz::detail::write().

Referenced by folly::pwritevFull().

58  {
59  return wrapPositional(writev, fd, offset, iov, count);
60 }
static int wrapPositional(F f, int fd, off_t offset, Args...args)
Definition: SysUio.cpp:28
int * count
template<class F , class... Args>
static int wrapPositional ( f,
int  fd,
off_t  offset,
Args...  args 
)
static

Definition at line 28 of file SysUio.cpp.

References f.

Referenced by preadv(), and pwritev().

28  {
29  off_t origLoc = lseek(fd, 0, SEEK_CUR);
30  if (origLoc == off_t(-1)) {
31  return -1;
32  }
33  if (lseek(fd, offset, SEEK_SET) == off_t(-1)) {
34  return -1;
35  }
36 
37  int res = (int)f(fd, args...);
38 
39  int curErrNo = errno;
40  if (lseek(fd, origLoc, SEEK_SET) == off_t(-1)) {
41  if (res == -1) {
42  errno = curErrNo;
43  }
44  return -1;
45  }
46  errno = curErrNo;
47 
48  return res;
49 }
auto f