| 1 |
|
| #include "EXTERN.h" |
| 2 |
|
| #include "perl.h" |
| 3 |
|
| #include "XSUB.h" |
| 4 |
|
| |
| 5 |
|
| // readv/writev |
| 6 |
|
| #include <sys/uio.h> |
| 7 |
|
| |
| 8 |
|
| // errno/EINTR |
| 9 |
|
| #include <errno.h> |
| 10 |
|
| |
| 11 |
|
| // IOV_MAX |
| 12 |
|
| #include <limits.h> |
| 13 |
|
| |
| 14 |
|
| #ifndef IOV_MAX |
| 15 |
|
| # ifdef UIO_MAXIOV |
| 16 |
|
| # define IOV_MAX UIO_MAXIOV |
| 17 |
|
| # endif |
| 18 |
|
| #endif |
| 19 |
|
| |
| 20 |
|
| #ifndef IOV_MAX |
| 21 |
|
| # error "Unable to determine IOV_MAX from system headers" |
| 22 |
|
| #endif |
| 23 |
|
| |
| 24 |
|
| |
| 25 |
|
| |
| 26 |
|
| MODULE = IO::Vectored PACKAGE = IO::Vectored |
| 27 |
|
| |
| 28 |
|
| PROTOTYPES: ENABLE |
| 29 |
|
| |
| 30 |
|
| |
| 31 |
|
| unsigned long |
| 32 |
|
| _backend(fileno, is_write, ...) |
| 33 |
|
| int fileno |
| 34 |
|
| int is_write |
| 35 |
|
| CODE: |
| 36 |
|
| ssize_t rv; |
| 37 |
|
| int iovcnt; |
| 38 |
|
| |
| 39 |
13 |
▶ | if (items < 3) croak("need more arguments to %s", is_write ? "syswritev" : "sysreadv"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (items < 3) croak("need more arguments to %s", is_write ? "syswritev" : "sysreadv"); |
1 |
12 |
13 |
| if (items < 3) croak("need more arguments to %s", is_write ? "syswritev" : "sysreadv"); |
1 |
0 |
1 |
|
| 40 |
|
| |
| 41 |
12 |
| iovcnt = items - 2; |
| 42 |
12 |
▶ | if (iovcnt > IOV_MAX) croak("too many arguments to %s", is_write ? "syswritev" : "sysreadv"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (iovcnt > IOV_MAX) croak("too many arguments to %s", is_write ? "syswritev" : "sysreadv"); |
1 |
11 |
12 |
| if (iovcnt > IOV_MAX) croak("too many arguments to %s", is_write ? "syswritev" : "sysreadv"); |
1 |
0 |
1 |
|
| 43 |
|
| |
| 44 |
11 |
| { |
| 45 |
11 |
| struct iovec v[iovcnt]; // Needs C99 compiler |
| 46 |
|
| SV *item; |
| 47 |
|
| int i; |
| 48 |
|
| size_t len; |
| 49 |
|
| |
| 50 |
36 |
▶ | for(i=0; i<iovcnt; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0; i<iovcnt; i++) { |
27 |
9 |
36 |
|
| 51 |
27 |
| item = ST(2 + i); |
| 52 |
|
| |
| 53 |
27 |
▶ | if (!is_write && SvREADONLY(item)) croak("Can't modify constant item in sysreadv"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!is_write && SvREADONLY(item)) croak("Can't modify constant item in sysreadv"); |
11 |
16 |
27 |
| if (!is_write && SvREADONLY(item)) croak("Can't modify constant item in sysreadv"); |
1 |
10 |
11 |
|
| 54 |
|
| |
| 55 |
26 |
▶ | SvUPGRADE(item, SVt_PV); |
Branch: 1 branch
| Branch | True | False | Total |
| SvUPGRADE(item, SVt_PV); |
6 |
20 |
26 |
|
| 56 |
26 |
▶ | if (!SvPOK(item) && !SvIOK(item) && !SvNOK(item)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!SvPOK(item) && !SvIOK(item) && !SvNOK(item)) |
6 |
20 |
26 |
| if (!SvPOK(item) && !SvIOK(item) && !SvNOK(item)) |
3 |
3 |
6 |
| if (!SvPOK(item) && !SvIOK(item) && !SvNOK(item)) |
1 |
2 |
3 |
|
| 57 |
1 |
▶ | croak("non-string object passed to %s", is_write ? "syswritev" : "sysreadv"); |
Branch: 1 branch
| Branch | True | False | Total |
| croak("non-string object passed to %s", is_write ? "syswritev" : "sysreadv"); |
1 |
0 |
1 |
|
| 58 |
|
| SvPV_nolen(item); |
| 59 |
|
| |
| 60 |
25 |
| v[i].iov_len = len = SvCUR(item); |
| 61 |
25 |
▶ | if (is_write) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_write) { |
15 |
10 |
25 |
|
| 62 |
15 |
| v[i].iov_base = SvPV(item, len); |
| 63 |
|
| } else { |
| 64 |
10 |
| v[i].iov_base = SvPV_force(item, len); |
| 65 |
|
| } |
| 66 |
|
| } |
| 67 |
|
| |
| 68 |
9 |
| again: |
| 69 |
|
| |
| 70 |
9 |
▶ | if (is_write) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_write) { |
5 |
4 |
9 |
|
| 71 |
5 |
| rv = writev(fileno, &v[0], iovcnt); |
| 72 |
|
| } else { |
| 73 |
4 |
| rv = readv(fileno, &v[0], iovcnt); |
| 74 |
|
| } |
| 75 |
|
| |
| 76 |
9 |
▶ | if (rv < 0 && errno == EINTR) goto again; |
Branch: 2 branches
| Branch | True | False | Total |
| if (rv < 0 && errno == EINTR) goto again; |
1 |
8 |
9 |
| if (rv < 0 && errno == EINTR) goto again; |
0 |
1 |
1 |
|
| 77 |
|
| } |
| 78 |
|
| |
| 79 |
9 |
▶ | if (rv < 0) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv < 0) XSRETURN_UNDEF; |
1 |
8 |
9 |
|
| 80 |
|
| |
| 81 |
8 |
▶ | RETVAL = (unsigned long) rv; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (unsigned long) rv; |
0 |
8 |
8 |
|
| 82 |
|
| OUTPUT: |
| 83 |
|
| RETVAL |
| 84 |
|
| |
| 85 |
|
| |
| 86 |
|
| int |
| 87 |
|
| _get_iov_max() |
| 88 |
|
| CODE: |
| 89 |
1 |
▶ | RETVAL = IOV_MAX; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = IOV_MAX; |
0 |
1 |
1 |
|
| 90 |
|
| OUTPUT: |
| 91 |
|
| RETVAL |