ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.xs
(Generate patch)

Comparing IO-AIO/AIO.xs (file contents):
Revision 1.243 by root, Mon Jul 18 07:48:01 2016 UTC vs.
Revision 1.250 by root, Fri Sep 22 05:20:39 2017 UTC

104#define expect_false(expr) expect ((expr) != 0, 0) 104#define expect_false(expr) expect ((expr) != 0, 0)
105#define expect_true(expr) expect ((expr) != 0, 1) 105#define expect_true(expr) expect ((expr) != 0, 1)
106 106
107/*****************************************************************************/ 107/*****************************************************************************/
108 108
109#include "libeio/config.h"
110
111#if HAVE_RLIMITS
112 #include <sys/time.h>
113 #include <sys/resource.h>
114#endif
115
109typedef SV SV8; /* byte-sv, used for argument-checking */ 116typedef SV SV8; /* byte-sv, used for argument-checking */
110typedef int aio_rfd; /* read file desriptor */ 117typedef int aio_rfd; /* read file desriptor */
111typedef int aio_wfd; /* write file descriptor */ 118typedef int aio_wfd; /* write file descriptor */
112 119
113static HV *aio_stash, *aio_req_stash, *aio_grp_stash, *aio_wd_stash; 120static HV *aio_stash, *aio_req_stash, *aio_grp_stash, *aio_wd_stash;
119 STRLEN stroffset; \ 126 STRLEN stroffset; \
120 SV *self; 127 SV *self;
121 128
122#define EIO_NO_WRAPPERS 1 129#define EIO_NO_WRAPPERS 1
123 130
124#include "libeio/config.h"
125#include "libeio/eio.h" 131#include "libeio/eio.h"
126 132
127static int req_invoke (eio_req *req); 133static int req_invoke (eio_req *req);
128#define EIO_FINISH(req) req_invoke (req) 134#define EIO_FINISH(req) req_invoke (req)
129static void req_destroy (eio_req *grp); 135static void req_destroy (eio_req *grp);
924 const_niv (MADV_NORMAL , POSIX_MADV_NORMAL) 930 const_niv (MADV_NORMAL , POSIX_MADV_NORMAL)
925 const_niv (MADV_SEQUENTIAL, POSIX_MADV_SEQUENTIAL) 931 const_niv (MADV_SEQUENTIAL, POSIX_MADV_SEQUENTIAL)
926 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) 932 const_niv (MADV_RANDOM , POSIX_MADV_RANDOM)
927 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) 933 const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED)
928 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) 934 const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED)
929 const_niv (MADV_FREE , POSIX_MADV_FREE)
930 935
931 /* the second block will be 0 when missing */ 936 /* the second block will be 0 when missing */
932 const_iv (O_RDONLY) 937 const_iv (O_RDONLY)
933 const_iv (O_WRONLY) 938 const_iv (O_WRONLY)
934 const_iv (O_RDWR) 939 const_iv (O_RDWR)
995 const_iv (MAP_NONBLOCK) 1000 const_iv (MAP_NONBLOCK)
996 const_iv (MAP_GROWSDOWN) 1001 const_iv (MAP_GROWSDOWN)
997 const_iv (MAP_32BIT) 1002 const_iv (MAP_32BIT)
998 const_iv (MAP_HUGETLB) 1003 const_iv (MAP_HUGETLB)
999 const_iv (MAP_STACK) 1004 const_iv (MAP_STACK)
1005
1006 const_iv (F_DUPFD_CLOEXEC)
1007
1008 const_iv (F_OFD_GETLK)
1009 const_iv (F_OFD_SETLK)
1010 const_iv (F_OFD_GETLKW)
1000 1011
1001 const_iv (FIFREEZE) 1012 const_iv (FIFREEZE)
1002 const_iv (FITHAW) 1013 const_iv (FITHAW)
1003 const_iv (FITRIM) 1014 const_iv (FITRIM)
1004 const_iv (FICLONE) 1015 const_iv (FICLONE)
1095 1106
1096 const_eio (FALLOC_FL_KEEP_SIZE) 1107 const_eio (FALLOC_FL_KEEP_SIZE)
1097 const_eio (FALLOC_FL_PUNCH_HOLE) 1108 const_eio (FALLOC_FL_PUNCH_HOLE)
1098 const_eio (FALLOC_FL_COLLAPSE_RANGE) 1109 const_eio (FALLOC_FL_COLLAPSE_RANGE)
1099 const_eio (FALLOC_FL_ZERO_RANGE) 1110 const_eio (FALLOC_FL_ZERO_RANGE)
1111 const_eio (FALLOC_FL_INSERT_RANGE)
1112 const_eio (FALLOC_FL_UNSHARE_RANGE)
1113
1114 const_eio (RENAME_NOREPLACE)
1115 const_eio (RENAME_EXCHANGE)
1116 const_eio (RENAME_WHITEOUT)
1100 1117
1101 const_eio (READDIR_DENTS) 1118 const_eio (READDIR_DENTS)
1102 const_eio (READDIR_DIRS_FIRST) 1119 const_eio (READDIR_DIRS_FIRST)
1103 const_eio (READDIR_STAT_ORDER) 1120 const_eio (READDIR_STAT_ORDER)
1104 const_eio (READDIR_FOUND_UNKNOWN) 1121 const_eio (READDIR_FOUND_UNKNOWN)
1591 1608
1592 REQ_SEND; 1609 REQ_SEND;
1593} 1610}
1594 1611
1595void 1612void
1613aio_rename2 (SV8 *oldpath, SV8 *newpath, int flags = 0, SV *callback = &PL_sv_undef)
1614 PPCODE:
1615{
1616 eio_wd wd2 = 0;
1617 dREQ;
1618
1619 req->type = EIO_RENAME;
1620 req_set_path1 (req, oldpath);
1621 req_set_path (req, newpath, &req->sv2, &req->sv4, &wd2, &req->ptr2);
1622 req->int2 = flags;
1623 req->int3 = (long)wd2;
1624
1625 REQ_SEND;
1626}
1627
1628void
1596aio_mknod (SV8 *pathname, int mode, UV dev, SV *callback = &PL_sv_undef) 1629aio_mknod (SV8 *pathname, int mode, UV dev, SV *callback = &PL_sv_undef)
1597 PPCODE: 1630 PPCODE:
1598{ 1631{
1599 dREQ; 1632 dREQ;
1600 1633
1605 1638
1606 REQ_SEND; 1639 REQ_SEND;
1607} 1640}
1608 1641
1609void 1642void
1610aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback = &PL_sv_undef) 1643aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = -1, SV *callback = &PL_sv_undef)
1611 ALIAS: 1644 ALIAS:
1612 aio_mtouch = EIO_MTOUCH 1645 aio_mtouch = EIO_MTOUCH
1613 aio_msync = EIO_MSYNC 1646 aio_msync = EIO_MSYNC
1614 PPCODE: 1647 PPCODE:
1615{ 1648{
1616 STRLEN svlen; 1649 STRLEN svlen;
1617 char *svptr = SvPVbyte (data, svlen); 1650 char *svptr = SvPVbyte (data, svlen);
1618 UV len = SvUV (length); 1651 UV len = SvUV (length);
1652
1653 if (flags < 0)
1654 flags = ix == EIO_MSYNC ? EIO_MS_SYNC : 0;
1619 1655
1620 if (offset < 0) 1656 if (offset < 0)
1621 offset += svlen; 1657 offset += svlen;
1622 1658
1623 if (offset < 0 || offset > svlen) 1659 if (offset < 0 || offset > svlen)
2017 { 2053 {
2018 EXTEND (SP, 2); 2054 EXTEND (SP, 2);
2019 PUSHs (newmortalFH (fd[0], O_RDONLY)); 2055 PUSHs (newmortalFH (fd[0], O_RDONLY));
2020 PUSHs (newmortalFH (fd[1], O_WRONLY)); 2056 PUSHs (newmortalFH (fd[1], O_WRONLY));
2021 } 2057 }
2058}
2059
2060UV
2061get_fdlimit ()
2062 CODE:
2063#if HAVE_RLIMITS
2064 struct rlimit rl;
2065 if (0 == getrlimit (RLIMIT_NOFILE, &rl))
2066 XSRETURN_UV (rl.rlim_cur == RLIM_INFINITY ? (UV)-1 : rl.rlim_cur);
2067#endif
2068 XSRETURN_UNDEF;
2069 OUTPUT:
2070 RETVAL
2071
2072void
2073min_fdlimit (UV limit = 0x7fffffffU)
2074 CODE:
2075{
2076#if HAVE_RLIMITS
2077 struct rlimit rl;
2078 rlim_t orig_rlim_max;
2079 UV bit;
2080
2081 if (0 != getrlimit (RLIMIT_NOFILE, &rl))
2082 goto fail;
2083
2084 if (rl.rlim_cur == RLIM_INFINITY)
2085 XSRETURN_YES;
2086
2087 orig_rlim_max = rl.rlim_max == RLIM_INFINITY ? ((rlim_t)0)-1 : rl.rlim_max;
2088
2089 if (rl.rlim_cur < limit)
2090 {
2091 rl.rlim_cur = limit;
2092
2093 if (rl.rlim_max < rl.rlim_cur && rl.rlim_max != RLIM_INFINITY)
2094 rl.rlim_max = rl.rlim_cur;
2095 }
2096
2097 if (0 == setrlimit (RLIMIT_NOFILE, &rl))
2098 XSRETURN_YES;
2099
2100 if (errno == EPERM)
2101 {
2102 /* setlimit failed with EPERM - maybe we can't raise the hardlimit, or maybe */
2103 /* our limit overflows a system-wide limit */
2104 /* try an adaptive algorithm, but do not lower the hardlimit */
2105 rl.rlim_max = 0;
2106 for (bit = 0x40000000U; bit; bit >>= 1)
2107 {
2108 rl.rlim_max |= bit;
2109 rl.rlim_cur = rl.rlim_max;
2110
2111 /* nevr decrease the hard limit */
2112 if (rl.rlim_max < orig_rlim_max)
2113 break;
2114
2115 if (0 != setrlimit (RLIMIT_NOFILE, &rl))
2116 rl.rlim_max &= ~bit; /* too high, remove bit again */
2117 }
2118
2119 /* now, raise the soft limit to the max permitted */
2120 if (0 == getrlimit (RLIMIT_NOFILE, &rl))
2121 {
2122 rl.rlim_cur = rl.rlim_max;
2123 if (0 == setrlimit (RLIMIT_NOFILE, &rl))
2124 errno = EPERM;
2125 }
2126 }
2127#endif
2128 fail:
2129 XSRETURN_UNDEF;
2022} 2130}
2023 2131
2024void _on_next_submit (SV *cb) 2132void _on_next_submit (SV *cb)
2025 CODE: 2133 CODE:
2026 SvREFCNT_dec (on_next_submit); 2134 SvREFCNT_dec (on_next_submit);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines