PostgreSQL Source Code  git master
pg_iovec.h File Reference
#include <limits.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.

Data Structures

struct  iovec
 

Macros

#define IOV_MAX   16
 
#define PG_IOV_MAX   Min(IOV_MAX, 32)
 

Functions

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

Macro Definition Documentation

◆ IOV_MAX

#define IOV_MAX   16

Definition at line 36 of file pg_iovec.h.

◆ PG_IOV_MAX

#define PG_IOV_MAX   Min(IOV_MAX, 32)

Definition at line 40 of file pg_iovec.h.

Function Documentation

◆ pg_preadv()

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

Definition at line 29 of file preadv.c.

30 {
31 #ifdef HAVE_READV
32  if (iovcnt == 1)
33  return pg_pread(fd, iov[0].iov_base, iov[0].iov_len, offset);
34  if (lseek(fd, offset, SEEK_SET) < 0)
35  return -1;
36  return readv(fd, iov, iovcnt);
37 #else
38  ssize_t sum = 0;
39  ssize_t part;
40 
41  for (int i = 0; i < iovcnt; ++i)
42  {
43  part = pg_pread(fd, iov[i].iov_base, iov[i].iov_len, offset);
44  if (part < 0)
45  {
46  if (i == 0)
47  return -1;
48  else
49  return sum;
50  }
51  sum += part;
52  offset += part;
53  if (part < iov[i].iov_len)
54  return sum;
55  }
56  return sum;
57 #endif
58 }
int i
Definition: isn.c:73
ssize_t pg_pread(int fd, void *buf, size_t nbyte, off_t offset)
Definition: pread.c:27
static int fd(const char *x, int i)
Definition: preproc-init.c:105

References fd(), i, and pg_pread().

◆ pg_pwritev()

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

Definition at line 29 of file pwritev.c.

30 {
31 #ifdef HAVE_WRITEV
32  if (iovcnt == 1)
33  return pg_pwrite(fd, iov[0].iov_base, iov[0].iov_len, offset);
34  if (lseek(fd, offset, SEEK_SET) < 0)
35  return -1;
36  return writev(fd, iov, iovcnt);
37 #else
38  ssize_t sum = 0;
39  ssize_t part;
40 
41  for (int i = 0; i < iovcnt; ++i)
42  {
43  part = pg_pwrite(fd, iov[i].iov_base, iov[i].iov_len, offset);
44  if (part < 0)
45  {
46  if (i == 0)
47  return -1;
48  else
49  return sum;
50  }
51  sum += part;
52  offset += part;
53  if (part < iov[i].iov_len)
54  return sum;
55  }
56  return sum;
57 #endif
58 }
ssize_t pg_pwrite(int fd, const void *buf, size_t nbyte, off_t offset)
Definition: pwrite.c:27

References fd(), i, and pg_pwrite().

Referenced by pg_pwritev_with_retry().