PostgreSQL Source Code  git master
pg_iovec.h File Reference
#include <limits.h>
#include <sys/uio.h>
#include <unistd.h>
Include dependency graph for pg_iovec.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PG_IOV_MAX   Min(IOV_MAX, 32)
 

Functions

static ssize_t pg_preadv (int fd, const struct iovec *iov, int iovcnt, off_t offset)
 
static ssize_t pg_pwritev (int fd, const struct iovec *iov, int iovcnt, off_t offset)
 

Macro Definition Documentation

◆ PG_IOV_MAX

#define PG_IOV_MAX   Min(IOV_MAX, 32)

Definition at line 37 of file pg_iovec.h.

Function Documentation

◆ pg_preadv()

static ssize_t pg_preadv ( int  fd,
const struct iovec *  iov,
int  iovcnt,
off_t  offset 
)
inlinestatic

Definition at line 44 of file pg_iovec.h.

45 {
46 #if HAVE_DECL_PREADV
47  /*
48  * Avoid a small amount of argument copying overhead in the kernel if
49  * there is only one iovec.
50  */
51  if (iovcnt == 1)
52  return pread(fd, iov[0].iov_base, iov[0].iov_len, offset);
53  else
54  return preadv(fd, iov, iovcnt, offset);
55 #else
56  ssize_t sum = 0;
57  ssize_t part;
58 
59  for (int i = 0; i < iovcnt; ++i)
60  {
61  part = pg_pread(fd, iov[i].iov_base, iov[i].iov_len, offset);
62  if (part < 0)
63  {
64  if (i == 0)
65  return -1;
66  else
67  return sum;
68  }
69  sum += part;
70  offset += part;
71  if (part < iov[i].iov_len)
72  return sum;
73  }
74  return sum;
75 #endif
76 }
int i
Definition: isn.c:73
#define pg_pread
Definition: port.h:225
static int fd(const char *x, int i)
Definition: preproc-init.c:105

References fd(), i, and pg_pread.

Referenced by FileReadV().

◆ pg_pwritev()

static ssize_t pg_pwritev ( int  fd,
const struct iovec *  iov,
int  iovcnt,
off_t  offset 
)
inlinestatic

Definition at line 83 of file pg_iovec.h.

84 {
85 #if HAVE_DECL_PWRITEV
86  /*
87  * Avoid a small amount of argument copying overhead in the kernel if
88  * there is only one iovec.
89  */
90  if (iovcnt == 1)
91  return pwrite(fd, iov[0].iov_base, iov[0].iov_len, offset);
92  else
93  return pwritev(fd, iov, iovcnt, offset);
94 #else
95  ssize_t sum = 0;
96  ssize_t part;
97 
98  for (int i = 0; i < iovcnt; ++i)
99  {
100  part = pg_pwrite(fd, iov[i].iov_base, iov[i].iov_len, offset);
101  if (part < 0)
102  {
103  if (i == 0)
104  return -1;
105  else
106  return sum;
107  }
108  sum += part;
109  offset += part;
110  if (part < iov[i].iov_len)
111  return sum;
112  }
113  return sum;
114 #endif
115 }
#define pg_pwrite
Definition: port.h:226

References fd(), i, and pg_pwrite.

Referenced by FileWriteV(), and pg_pwritev_with_retry().