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.249 by root, Fri Jun 23 23:50:25 2017 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);
2049 PUSHs (newmortalFH (fd[0], O_RDONLY)); 2055 PUSHs (newmortalFH (fd[0], O_RDONLY));
2050 PUSHs (newmortalFH (fd[1], O_WRONLY)); 2056 PUSHs (newmortalFH (fd[1], O_WRONLY));
2051 } 2057 }
2052} 2058}
2053 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;
2130}
2131
2054void _on_next_submit (SV *cb) 2132void _on_next_submit (SV *cb)
2055 CODE: 2133 CODE:
2056 SvREFCNT_dec (on_next_submit); 2134 SvREFCNT_dec (on_next_submit);
2057 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; 2135 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0;
2058 2136

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines