… | |
… | |
3 | #include <errno.h> |
3 | #include <errno.h> |
4 | |
4 | |
5 | #include "EXTERN.h" |
5 | #include "EXTERN.h" |
6 | #include "perl.h" |
6 | #include "perl.h" |
7 | #include "XSUB.h" |
7 | #include "XSUB.h" |
|
|
8 | |
|
|
9 | #include "schmorp.h" |
8 | |
10 | |
9 | #include <stddef.h> |
11 | #include <stddef.h> |
10 | #include <stdlib.h> |
12 | #include <stdlib.h> |
11 | #include <errno.h> |
13 | #include <errno.h> |
12 | #include <sys/types.h> |
14 | #include <sys/types.h> |
13 | #include <sys/stat.h> |
15 | #include <sys/stat.h> |
14 | #include <limits.h> |
16 | #include <limits.h> |
15 | #include <fcntl.h> |
17 | #include <fcntl.h> |
16 | #include <sched.h> |
18 | #include <sched.h> |
17 | |
19 | |
|
|
20 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
|
|
21 | # include <sys/mman.h> |
|
|
22 | #endif |
|
|
23 | |
|
|
24 | #if __linux__ |
|
|
25 | # include <linux/fs.h> |
|
|
26 | # ifdef FS_IOC_FIEMAP |
|
|
27 | # include <linux/types.h> |
|
|
28 | # include <linux/fiemap.h> |
|
|
29 | # define HAVE_FIEMAP 1 |
|
|
30 | # endif |
|
|
31 | #endif |
|
|
32 | |
18 | /* perl namespace pollution */ |
33 | /* perl namespace pollution */ |
19 | #undef VERSION |
34 | #undef VERSION |
20 | |
|
|
21 | #ifdef _WIN32 |
|
|
22 | |
|
|
23 | # define EIO_STRUCT_DIRENT Direntry_t |
|
|
24 | # undef malloc |
|
|
25 | # undef free |
|
|
26 | |
|
|
27 | // perl overrides all those nice win32 functions |
|
|
28 | # undef open |
|
|
29 | # undef read |
|
|
30 | # undef write |
|
|
31 | # undef send |
|
|
32 | # undef recv |
|
|
33 | # undef stat |
|
|
34 | # undef fstat |
|
|
35 | # define lstat stat |
|
|
36 | # undef truncate |
|
|
37 | # undef ftruncate |
|
|
38 | # undef open |
|
|
39 | # undef close |
|
|
40 | # undef unlink |
|
|
41 | # undef rmdir |
|
|
42 | # undef rename |
|
|
43 | # undef lseek |
|
|
44 | |
|
|
45 | # define chown(a,b,c) (errno = ENOSYS, -1) |
|
|
46 | # define fchown(a,b,c) (errno = ENOSYS, -1) |
|
|
47 | # define fchmod(a,b) (errno = ENOSYS, -1) |
|
|
48 | # define symlink(a,b) (errno = ENOSYS, -1) |
|
|
49 | # define readlink(a,b,c) (errno = ENOSYS, -1) |
|
|
50 | # define mknod(a,b,c) (errno = ENOSYS, -1) |
|
|
51 | # define truncate(a,b) (errno = ENOSYS, -1) |
|
|
52 | # define ftruncate(fd,o) chsize ((fd), (o)) |
|
|
53 | # define fsync(fd) _commit (fd) |
|
|
54 | # define opendir(fd) (errno = ENOSYS, 0) |
|
|
55 | # define readdir(fd) (errno = ENOSYS, -1) |
|
|
56 | # define closedir(fd) (errno = ENOSYS, -1) |
|
|
57 | # define mkdir(a,b) mkdir (a) |
|
|
58 | |
|
|
59 | #else |
|
|
60 | |
|
|
61 | # include <sys/time.h> |
|
|
62 | # include <sys/select.h> |
|
|
63 | # include <unistd.h> |
|
|
64 | # include <utime.h> |
|
|
65 | # include <signal.h> |
|
|
66 | # define EIO_STRUCT_DIRENT struct dirent |
|
|
67 | |
|
|
68 | #endif |
|
|
69 | |
35 | |
70 | /* perl stupidly overrides readdir and maybe others */ |
36 | /* perl stupidly overrides readdir and maybe others */ |
71 | /* with thread-unsafe versions, imagine that :( */ |
37 | /* with thread-unsafe versions, imagine that :( */ |
72 | #undef readdir |
38 | #undef readdir |
73 | #undef opendir |
39 | #undef opendir |
74 | #undef closedir |
40 | #undef closedir |
75 | |
41 | |
|
|
42 | #ifdef _WIN32 |
|
|
43 | |
|
|
44 | // perl overrides all those nice libc functions |
|
|
45 | |
|
|
46 | #undef malloc |
|
|
47 | #undef free |
|
|
48 | #undef open |
|
|
49 | #undef read |
|
|
50 | #undef write |
|
|
51 | #undef send |
|
|
52 | #undef recv |
|
|
53 | #undef stat |
|
|
54 | #undef lstat |
|
|
55 | #undef fstat |
|
|
56 | #undef truncate |
|
|
57 | #undef ftruncate |
|
|
58 | #undef open |
|
|
59 | #undef link |
|
|
60 | #undef close |
|
|
61 | #undef unlink |
|
|
62 | #undef mkdir |
|
|
63 | #undef rmdir |
|
|
64 | #undef rename |
|
|
65 | #undef lseek |
|
|
66 | #undef opendir |
|
|
67 | #undef readdir |
|
|
68 | #undef closedir |
|
|
69 | #undef chmod |
|
|
70 | #undef fchmod |
|
|
71 | #undef dup |
|
|
72 | #undef dup2 |
|
|
73 | #undef abort |
|
|
74 | #undef pipe |
|
|
75 | |
|
|
76 | #define EIO_STRUCT_STAT struct _stati64 |
76 | #define EIO_STRUCT_STAT Stat_t |
77 | #define EIO_STRUCT_STATI64 |
77 | |
78 | |
78 | /* use NV for 32 bit perls as it allows larger offsets */ |
|
|
79 | #if IVSIZE >= 8 |
|
|
80 | # define VAL64 IV |
|
|
81 | # define SvVAL64 SvIV |
|
|
82 | # define newSVval64 newSViv |
|
|
83 | #else |
79 | #else |
84 | # define VAL64 NV |
80 | |
85 | # define SvVAL64 SvNV |
81 | #include <sys/time.h> |
86 | # define newSVval64 newSVnv |
82 | #include <sys/select.h> |
|
|
83 | #include <unistd.h> |
|
|
84 | #include <utime.h> |
|
|
85 | #include <signal.h> |
|
|
86 | |
|
|
87 | #define EIO_STRUCT_STAT Stat_t |
|
|
88 | |
87 | #endif |
89 | #endif |
88 | |
90 | |
89 | /*****************************************************************************/ |
91 | /*****************************************************************************/ |
90 | |
92 | |
91 | #if __GNUC__ >= 3 |
93 | #if __GNUC__ >= 3 |
… | |
… | |
97 | #define expect_false(expr) expect ((expr) != 0, 0) |
99 | #define expect_false(expr) expect ((expr) != 0, 0) |
98 | #define expect_true(expr) expect ((expr) != 0, 1) |
100 | #define expect_true(expr) expect ((expr) != 0, 1) |
99 | |
101 | |
100 | /*****************************************************************************/ |
102 | /*****************************************************************************/ |
101 | |
103 | |
102 | static HV *stash; |
|
|
103 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
104 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
104 | typedef int aio_rfd; /* read file desriptor */ |
105 | typedef int aio_rfd; /* read file desriptor */ |
105 | typedef int aio_wfd; /* write file descriptor */ |
106 | typedef int aio_wfd; /* write file descriptor */ |
106 | |
107 | |
107 | #define AIO_REQ_KLASS "IO::AIO::REQ" |
108 | static HV *aio_stash, *aio_req_stash, *aio_grp_stash, *aio_wd_stash; |
108 | #define AIO_GRP_KLASS "IO::AIO::GRP" |
|
|
109 | |
109 | |
110 | #define EIO_REQ_MEMBERS \ |
110 | #define EIO_REQ_MEMBERS \ |
111 | SV *callback; \ |
111 | SV *callback; \ |
112 | SV *sv1, *sv2; \ |
112 | SV *sv1, *sv2; \ |
|
|
113 | SV *sv3, *sv4; \ |
113 | STRLEN stroffset; \ |
114 | STRLEN stroffset; \ |
114 | SV *self; |
115 | SV *self; |
115 | |
116 | |
116 | #define EIO_NO_WRAPPERS 1 |
117 | #define EIO_NO_WRAPPERS 1 |
117 | |
118 | |
|
|
119 | #include "libeio/config.h" |
118 | #include "libeio/eio.h" |
120 | #include "libeio/eio.h" |
119 | |
|
|
120 | #ifndef POSIX_FADV_NORMAL |
|
|
121 | # define POSIX_FADV_NORMAL 0 |
|
|
122 | #endif |
|
|
123 | |
|
|
124 | #ifndef POSIX_FADV_SEQUENTIAL |
|
|
125 | # define POSIX_FADV_SEQUENTIAL 0 |
|
|
126 | #endif |
|
|
127 | |
|
|
128 | #ifndef POSIX_FADV_RANDOM |
|
|
129 | # define POSIX_FADV_RANDOM 0 |
|
|
130 | #endif |
|
|
131 | |
|
|
132 | #ifndef POSIX_FADV_NOREUSE |
|
|
133 | # define POSIX_FADV_NOREUSE 0 |
|
|
134 | #endif |
|
|
135 | |
|
|
136 | #ifndef POSIX_FADV_WILLNEED |
|
|
137 | # define POSIX_FADV_WILLNEED 0 |
|
|
138 | #endif |
|
|
139 | |
|
|
140 | #ifndef POSIX_FADV_DONTNEED |
|
|
141 | # define POSIX_FADV_DONTNEED 0 |
|
|
142 | #endif |
|
|
143 | |
121 | |
144 | static int req_invoke (eio_req *req); |
122 | static int req_invoke (eio_req *req); |
145 | #define EIO_FINISH(req) req_invoke (req) |
123 | #define EIO_FINISH(req) req_invoke (req) |
146 | static void req_destroy (eio_req *grp); |
124 | static void req_destroy (eio_req *grp); |
147 | #define EIO_DESTROY(req) req_destroy (req) |
125 | #define EIO_DESTROY(req) req_destroy (req) |
148 | |
126 | |
|
|
127 | #include "libeio/eio.c" |
|
|
128 | |
|
|
129 | #if !HAVE_POSIX_FADVISE |
|
|
130 | # define posix_fadvise(a,b,c,d) errno = ENOSYS /* also return ENOSYS */ |
|
|
131 | #endif |
|
|
132 | |
|
|
133 | #if !HAVE_POSIX_MADVISE |
|
|
134 | # define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */ |
|
|
135 | #endif |
|
|
136 | |
|
|
137 | #ifndef MAP_ANONYMOUS |
|
|
138 | # ifdef MAP_ANON |
|
|
139 | # define MAP_ANONYMOUS MAP_ANON |
|
|
140 | # else |
|
|
141 | # define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ |
|
|
142 | # endif |
|
|
143 | #endif |
|
|
144 | |
|
|
145 | /* defines all sorts of constants to 0 unless they are already defined */ |
|
|
146 | #include "def0.h" |
|
|
147 | |
|
|
148 | #ifndef makedev |
|
|
149 | # define makedev(maj,min) (((maj) << 8) | (min)) |
|
|
150 | #endif |
|
|
151 | #ifndef major |
|
|
152 | # define major(dev) ((dev) >> 8) |
|
|
153 | #endif |
|
|
154 | #ifndef minor |
|
|
155 | # define minor(dev) ((dev) & 0xff) |
|
|
156 | #endif |
|
|
157 | |
|
|
158 | #ifndef PAGESIZE |
|
|
159 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
|
|
160 | #endif |
|
|
161 | |
|
|
162 | /*****************************************************************************/ |
|
|
163 | |
|
|
164 | static void |
|
|
165 | fiemap (eio_req *req) |
|
|
166 | { |
|
|
167 | req->result = -1; |
|
|
168 | |
|
|
169 | #if HAVE_FIEMAP |
|
|
170 | int count = req->int3; |
|
|
171 | |
|
|
172 | /* heuristic: first try with 64 extents if we don't know how many, */ |
|
|
173 | /* as most files have (hopefully) fewer than this many extents */ |
|
|
174 | /* in fact, most should have <= 2, so maybe the 72 below is probably overkill */ |
|
|
175 | if (count < 0) |
|
|
176 | count = 72; /* for what it's worth, 72 extents fit nicely into 4kb */ |
|
|
177 | |
|
|
178 | for (;;) |
|
|
179 | { |
|
|
180 | struct fiemap *fiemap = malloc (sizeof (*fiemap) + sizeof (struct fiemap_extent) * count); |
|
|
181 | errno = ENOMEM; |
|
|
182 | if (!fiemap) |
|
|
183 | return; |
|
|
184 | |
|
|
185 | req->ptr1 = fiemap; |
|
|
186 | req->flags |= EIO_FLAG_PTR1_FREE; |
|
|
187 | |
|
|
188 | fiemap->fm_start = req->offs; |
|
|
189 | fiemap->fm_length = req->size; |
|
|
190 | fiemap->fm_flags = req->int2; |
|
|
191 | fiemap->fm_extent_count = count; |
|
|
192 | |
|
|
193 | if (ioctl (req->int1, FS_IOC_FIEMAP, fiemap)) |
|
|
194 | return; |
|
|
195 | |
|
|
196 | if (req->int3 >= 0) |
|
|
197 | break; /* when not autosizing we are done */ |
|
|
198 | |
|
|
199 | if (fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_flags & FIEMAP_EXTENT_LAST) |
|
|
200 | break; /* autosizing successful, we are done */ |
|
|
201 | |
|
|
202 | fiemap->fm_flags = req->int2; |
|
|
203 | fiemap->fm_extent_count = 0; |
|
|
204 | |
|
|
205 | if (ioctl (req->int1, FS_IOC_FIEMAP, fiemap)) |
|
|
206 | return; |
|
|
207 | |
|
|
208 | count = fiemap->fm_mapped_extents; |
|
|
209 | |
|
|
210 | free (fiemap); |
|
|
211 | } |
|
|
212 | |
|
|
213 | req->result = 0; |
|
|
214 | |
|
|
215 | #else |
|
|
216 | errno = ENOSYS; |
|
|
217 | #endif |
|
|
218 | } |
|
|
219 | |
|
|
220 | /*****************************************************************************/ |
|
|
221 | |
149 | enum { |
222 | enum { |
150 | FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ |
223 | FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ |
151 | }; |
224 | }; |
152 | |
225 | |
153 | #include "libeio/eio.c" |
|
|
154 | |
|
|
155 | typedef eio_req *aio_req; |
226 | typedef eio_req *aio_req; |
156 | typedef eio_req *aio_req_ornot; |
227 | typedef eio_req *aio_req_ornot; |
|
|
228 | typedef eio_wd aio_wd; |
157 | |
229 | |
158 | static SV *on_next_submit; |
230 | static SV *on_next_submit; |
159 | static int next_pri = EIO_PRI_DEFAULT; |
231 | static int next_pri = EIO_PRI_DEFAULT; |
160 | static int max_outstanding; |
232 | static int max_outstanding; |
161 | |
233 | |
162 | static int respipe_osf [2], respipe [2] = { -1, -1 }; |
234 | static s_epipe respipe; |
163 | |
235 | |
164 | static void req_destroy (aio_req req); |
236 | static void req_destroy (aio_req req); |
165 | static void req_cancel (aio_req req); |
237 | static void req_cancel (aio_req req); |
166 | |
238 | |
167 | static void want_poll (void) |
239 | static void |
|
|
240 | want_poll (void) |
168 | { |
241 | { |
169 | /* write a dummy byte to the pipe so fh becomes ready */ |
242 | /* write a dummy byte to the pipe so fh becomes ready */ |
170 | respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1); |
243 | s_epipe_signal (&respipe); |
171 | } |
244 | } |
172 | |
245 | |
173 | static void done_poll (void) |
246 | static void |
|
|
247 | done_poll (void) |
174 | { |
248 | { |
175 | /* read any signals sent by the worker threads */ |
249 | /* read any signals sent by the worker threads */ |
176 | char buf [4]; |
250 | s_epipe_drain (&respipe); |
177 | while (respipe_read (respipe [0], buf, 4) == 4) |
|
|
178 | ; |
|
|
179 | } |
251 | } |
180 | |
252 | |
181 | /* must be called at most once */ |
253 | /* must be called at most once */ |
182 | static SV *req_sv (aio_req req, const char *klass) |
254 | static SV * |
|
|
255 | req_sv (aio_req req, HV *stash) |
183 | { |
256 | { |
184 | if (!req->self) |
257 | if (!req->self) |
185 | { |
258 | { |
186 | req->self = (SV *)newHV (); |
259 | req->self = (SV *)newHV (); |
187 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
260 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
188 | } |
261 | } |
189 | |
262 | |
190 | return sv_2mortal (sv_bless (newRV_inc (req->self), gv_stashpv (klass, 1))); |
263 | return sv_2mortal (sv_bless (newRV_inc (req->self), stash)); |
191 | } |
264 | } |
192 | |
265 | |
193 | static aio_req SvAIO_REQ (SV *sv) |
266 | static SV * |
|
|
267 | newSVaio_wd (aio_wd wd) |
|
|
268 | { |
|
|
269 | return sv_bless (newRV_noinc (newSViv ((IV)wd)), aio_wd_stash); |
|
|
270 | } |
|
|
271 | |
|
|
272 | static aio_req |
|
|
273 | SvAIO_REQ (SV *sv) |
194 | { |
274 | { |
195 | MAGIC *mg; |
275 | MAGIC *mg; |
196 | |
276 | |
197 | if (!sv_derived_from (sv, AIO_REQ_KLASS) || !SvROK (sv)) |
277 | if (!SvROK (sv) |
|
|
278 | /* for speed reasons, we do not verify that SvROK actually has a stash ptr */ |
|
|
279 | || (SvSTASH (SvRV (sv)) != aio_grp_stash |
|
|
280 | && SvSTASH (SvRV (sv)) != aio_req_stash |
|
|
281 | && !sv_derived_from (sv, "IO::AIO::REQ"))) |
198 | croak ("object of class " AIO_REQ_KLASS " expected"); |
282 | croak ("object of class IO::AIO::REQ expected"); |
199 | |
283 | |
200 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
284 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
201 | |
285 | |
202 | return mg ? (aio_req)mg->mg_ptr : 0; |
286 | return mg ? (aio_req)mg->mg_ptr : 0; |
203 | } |
287 | } |
204 | |
288 | |
|
|
289 | static aio_wd |
|
|
290 | SvAIO_WD (SV *sv) |
|
|
291 | { |
|
|
292 | if (!SvROK (sv) |
|
|
293 | || SvTYPE (SvRV (sv)) != SVt_PVMG |
|
|
294 | || SvSTASH (SvRV (sv)) != aio_wd_stash) |
|
|
295 | croak ("IO::AIO: expected a working directory object as returned by aio_wd"); |
|
|
296 | |
|
|
297 | return (aio_wd)(long)SvIVX (SvRV (sv)); |
|
|
298 | } |
|
|
299 | |
|
|
300 | static void |
205 | static void aio_grp_feed (aio_req grp) |
301 | aio_grp_feed (aio_req grp) |
206 | { |
302 | { |
207 | if (grp->sv2 && SvOK (grp->sv2)) |
303 | if (grp->sv2 && SvOK (grp->sv2)) |
208 | { |
304 | { |
209 | dSP; |
305 | dSP; |
210 | |
306 | |
211 | ENTER; |
307 | ENTER; |
212 | SAVETMPS; |
308 | SAVETMPS; |
213 | PUSHMARK (SP); |
309 | PUSHMARK (SP); |
214 | XPUSHs (req_sv (grp, AIO_GRP_KLASS)); |
310 | XPUSHs (req_sv (grp, aio_grp_stash)); |
215 | PUTBACK; |
311 | PUTBACK; |
216 | call_sv (grp->sv2, G_VOID | G_EVAL | G_KEEPERR); |
312 | call_sv (grp->sv2, G_VOID | G_EVAL | G_KEEPERR); |
217 | SPAGAIN; |
313 | SPAGAIN; |
218 | FREETMPS; |
314 | FREETMPS; |
219 | LEAVE; |
315 | LEAVE; |
220 | } |
316 | } |
221 | } |
317 | } |
222 | |
318 | |
|
|
319 | static void |
223 | static void req_submit (eio_req *req) |
320 | req_submit (eio_req *req) |
224 | { |
321 | { |
225 | eio_submit (req); |
322 | eio_submit (req); |
226 | |
323 | |
227 | if (expect_false (on_next_submit)) |
324 | if (expect_false (on_next_submit)) |
228 | { |
325 | { |
… | |
… | |
235 | PUTBACK; |
332 | PUTBACK; |
236 | call_sv (cb, G_DISCARD | G_EVAL); |
333 | call_sv (cb, G_DISCARD | G_EVAL); |
237 | } |
334 | } |
238 | } |
335 | } |
239 | |
336 | |
|
|
337 | static int |
240 | static int req_invoke (eio_req *req) |
338 | req_invoke (eio_req *req) |
241 | { |
339 | { |
242 | dSP; |
|
|
243 | |
|
|
244 | if (req->flags & FLAG_SV2_RO_OFF) |
340 | if (req->flags & FLAG_SV2_RO_OFF) |
245 | SvREADONLY_off (req->sv2); |
341 | SvREADONLY_off (req->sv2); |
246 | |
342 | |
247 | if (!EIO_CANCELLED (req) && req->callback) |
343 | if (!EIO_CANCELLED (req) && req->callback) |
248 | { |
344 | { |
|
|
345 | dSP; |
|
|
346 | static SV *sv_result_cache; /* caches the result integer SV */ |
|
|
347 | SV *sv_result; |
|
|
348 | |
249 | ENTER; |
349 | ENTER; |
250 | SAVETMPS; |
350 | SAVETMPS; |
251 | PUSHMARK (SP); |
351 | PUSHMARK (SP); |
252 | EXTEND (SP, 1); |
352 | EXTEND (SP, 1); |
253 | |
353 | |
|
|
354 | /* do not recreate the result IV from scratch each time */ |
|
|
355 | if (expect_true (sv_result_cache)) |
|
|
356 | { |
|
|
357 | sv_result = sv_result_cache; sv_result_cache = 0; |
|
|
358 | SvIV_set (sv_result, req->result); |
|
|
359 | SvIOK_only (sv_result); |
|
|
360 | } |
|
|
361 | else |
|
|
362 | { |
|
|
363 | sv_result = newSViv (req->result); |
|
|
364 | SvREADONLY_on (sv_result); |
|
|
365 | } |
|
|
366 | |
254 | switch (req->type) |
367 | switch (req->type) |
255 | { |
368 | { |
|
|
369 | case EIO_WD_OPEN: |
|
|
370 | PUSHs (req->result ? &PL_sv_undef : sv_2mortal (newSVaio_wd (req->wd))); |
|
|
371 | break; |
|
|
372 | |
256 | case EIO_READDIR: |
373 | case EIO_READDIR: |
257 | { |
374 | { |
258 | SV *rv = &PL_sv_undef; |
375 | SV *rv = &PL_sv_undef; |
259 | |
376 | |
260 | if (req->result >= 0) |
377 | if (req->result >= 0) |
… | |
… | |
325 | int flags = req->int1 & (O_RDONLY | O_WRONLY | O_RDWR); |
442 | int flags = req->int1 & (O_RDONLY | O_WRONLY | O_RDWR); |
326 | char sym [64]; |
443 | char sym [64]; |
327 | int symlen; |
444 | int symlen; |
328 | |
445 | |
329 | symlen = snprintf (sym, sizeof (sym), "fd#%d", (int)req->result); |
446 | symlen = snprintf (sym, sizeof (sym), "fd#%d", (int)req->result); |
330 | gv_init (gv, stash, sym, symlen, 0); |
447 | gv_init (gv, aio_stash, sym, symlen, 0); |
331 | |
448 | |
332 | symlen = snprintf ( |
449 | symlen = snprintf ( |
333 | sym, |
450 | sym, |
334 | sizeof (sym), |
451 | sizeof (sym), |
335 | "%s&=%d", |
452 | "%s&=%d", |
… | |
… | |
343 | |
460 | |
344 | PUSHs (fh); |
461 | PUSHs (fh); |
345 | } |
462 | } |
346 | break; |
463 | break; |
347 | |
464 | |
|
|
465 | case EIO_STATVFS: |
|
|
466 | case EIO_FSTATVFS: |
|
|
467 | { |
|
|
468 | SV *rv = &PL_sv_undef; |
|
|
469 | |
|
|
470 | #ifndef _WIN32 |
|
|
471 | if (req->result >= 0) |
|
|
472 | { |
|
|
473 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
|
|
474 | HV *hv = newHV (); |
|
|
475 | |
|
|
476 | rv = sv_2mortal (newRV_noinc ((SV *)hv)); |
|
|
477 | |
|
|
478 | hv_store (hv, "bsize" , sizeof ("bsize" ) - 1, newSVval64 (f->f_bsize ), 0); |
|
|
479 | hv_store (hv, "frsize" , sizeof ("frsize" ) - 1, newSVval64 (f->f_frsize ), 0); |
|
|
480 | hv_store (hv, "blocks" , sizeof ("blocks" ) - 1, newSVval64 (f->f_blocks ), 0); |
|
|
481 | hv_store (hv, "bfree" , sizeof ("bfree" ) - 1, newSVval64 (f->f_bfree ), 0); |
|
|
482 | hv_store (hv, "bavail" , sizeof ("bavail" ) - 1, newSVval64 (f->f_bavail ), 0); |
|
|
483 | hv_store (hv, "files" , sizeof ("files" ) - 1, newSVval64 (f->f_files ), 0); |
|
|
484 | hv_store (hv, "ffree" , sizeof ("ffree" ) - 1, newSVval64 (f->f_ffree ), 0); |
|
|
485 | hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); |
|
|
486 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); |
|
|
487 | hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); |
|
|
488 | hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); |
|
|
489 | } |
|
|
490 | #endif |
|
|
491 | |
|
|
492 | PUSHs (rv); |
|
|
493 | } |
|
|
494 | |
|
|
495 | break; |
|
|
496 | |
348 | case EIO_GROUP: |
497 | case EIO_GROUP: |
349 | req->int1 = 2; /* mark group as finished */ |
498 | req->int1 = 2; /* mark group as finished */ |
350 | |
499 | |
351 | if (req->sv1) |
500 | if (req->sv1) |
352 | { |
501 | { |
… | |
… | |
362 | case EIO_NOP: |
511 | case EIO_NOP: |
363 | case EIO_BUSY: |
512 | case EIO_BUSY: |
364 | break; |
513 | break; |
365 | |
514 | |
366 | case EIO_READLINK: |
515 | case EIO_READLINK: |
|
|
516 | case EIO_REALPATH: |
367 | if (req->result > 0) |
517 | if (req->result > 0) |
368 | PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result))); |
518 | PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result))); |
369 | break; |
519 | break; |
370 | |
520 | |
371 | case EIO_STAT: |
521 | case EIO_STAT: |
372 | case EIO_LSTAT: |
522 | case EIO_LSTAT: |
373 | case EIO_FSTAT: |
523 | case EIO_FSTAT: |
374 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
524 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
|
|
525 | |
375 | PL_laststatval = req->result; |
526 | if (!(PL_laststatval = req->result)) |
|
|
527 | /* if compilation fails here then perl's Stat_t is not struct _stati64 */ |
376 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
528 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
377 | PUSHs (sv_2mortal (newSViv (req->result))); |
529 | |
|
|
530 | PUSHs (sv_result); |
|
|
531 | break; |
|
|
532 | |
|
|
533 | case EIO_SEEK: |
|
|
534 | PUSHs (req->result ? sv_result : sv_2mortal (newSVval64 (req->offs))); |
378 | break; |
535 | break; |
379 | |
536 | |
380 | case EIO_READ: |
537 | case EIO_READ: |
381 | { |
538 | { |
382 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
539 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
383 | *SvEND (req->sv2) = 0; |
540 | *SvEND (req->sv2) = 0; |
384 | SvPOK_only (req->sv2); |
541 | SvPOK_only (req->sv2); |
385 | SvSETMAGIC (req->sv2); |
542 | SvSETMAGIC (req->sv2); |
386 | PUSHs (sv_2mortal (newSViv (req->result))); |
543 | PUSHs (sv_result); |
387 | } |
544 | } |
388 | break; |
545 | break; |
389 | |
546 | |
390 | case EIO_DUP2: |
547 | case EIO_CUSTOM: |
|
|
548 | if (req->feed == fiemap) |
|
|
549 | { |
|
|
550 | #if HAVE_FIEMAP |
|
|
551 | if (!req->result) |
|
|
552 | { |
|
|
553 | struct fiemap *fiemap = (struct fiemap *)req->ptr1; |
|
|
554 | |
|
|
555 | if (fiemap->fm_extent_count) |
|
|
556 | { |
|
|
557 | AV *av = newAV (); |
|
|
558 | int i; |
|
|
559 | |
|
|
560 | while (fiemap->fm_mapped_extents) |
|
|
561 | { |
|
|
562 | struct fiemap_extent *extent = &fiemap->fm_extents [--fiemap->fm_mapped_extents]; |
|
|
563 | AV *ext_av = newAV (); |
|
|
564 | |
|
|
565 | av_store (ext_av, 3, newSVuv (extent->fe_flags)); |
|
|
566 | av_store (ext_av, 2, newSVval64 (extent->fe_length)); |
|
|
567 | av_store (ext_av, 1, newSVval64 (extent->fe_physical)); |
|
|
568 | av_store (ext_av, 0, newSVval64 (extent->fe_logical)); |
|
|
569 | |
|
|
570 | av_store (av, fiemap->fm_mapped_extents, newRV_noinc ((SV *)ext_av)); |
|
|
571 | } |
|
|
572 | |
|
|
573 | PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
|
|
574 | } |
|
|
575 | else |
|
|
576 | { |
|
|
577 | SvIV_set (sv_result, fiemap->fm_mapped_extents); |
|
|
578 | PUSHs (sv_result); |
|
|
579 | } |
|
|
580 | } |
|
|
581 | #endif |
|
|
582 | } |
|
|
583 | else |
|
|
584 | PUSHs (sv_result); |
|
|
585 | break; |
|
|
586 | |
|
|
587 | case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), so fudge result value */ |
391 | if (req->result > 0) |
588 | if (req->result > 0) |
392 | req->result = 0; |
589 | SvIV_set (sv_result, 0); |
393 | /* FALLTHROUGH */ |
590 | /* FALLTHROUGH */ |
394 | |
591 | |
395 | default: |
592 | default: |
396 | PUSHs (sv_2mortal (newSViv (req->result))); |
593 | PUSHs (sv_result); |
397 | break; |
594 | break; |
398 | } |
595 | } |
399 | |
596 | |
400 | errno = req->errorno; |
597 | errno = req->errorno; |
401 | |
598 | |
402 | PUTBACK; |
599 | PUTBACK; |
403 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
600 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
404 | SPAGAIN; |
601 | SPAGAIN; |
405 | |
602 | |
|
|
603 | if (expect_false (SvREFCNT (sv_result) != 1 || sv_result_cache)) |
|
|
604 | SvREFCNT_dec (sv_result); |
|
|
605 | else |
|
|
606 | sv_result_cache = sv_result; |
|
|
607 | |
406 | FREETMPS; |
608 | FREETMPS; |
407 | LEAVE; |
609 | LEAVE; |
408 | |
610 | |
409 | PUTBACK; |
611 | PUTBACK; |
410 | } |
612 | } |
411 | |
613 | |
412 | return !!SvTRUE (ERRSV); |
614 | return !!SvTRUE (ERRSV); |
413 | } |
615 | } |
414 | |
616 | |
|
|
617 | static void |
415 | static void req_destroy (aio_req req) |
618 | req_destroy (aio_req req) |
416 | { |
619 | { |
417 | if (req->self) |
620 | if (req->self) |
418 | { |
621 | { |
419 | sv_unmagic (req->self, PERL_MAGIC_ext); |
622 | sv_unmagic (req->self, PERL_MAGIC_ext); |
420 | SvREFCNT_dec (req->self); |
623 | SvREFCNT_dec (req->self); |
421 | } |
624 | } |
422 | |
625 | |
423 | SvREFCNT_dec (req->sv1); |
626 | SvREFCNT_dec (req->sv1); |
424 | SvREFCNT_dec (req->sv2); |
627 | SvREFCNT_dec (req->sv2); |
|
|
628 | SvREFCNT_dec (req->sv3); |
|
|
629 | SvREFCNT_dec (req->sv4); |
425 | SvREFCNT_dec (req->callback); |
630 | SvREFCNT_dec (req->callback); |
426 | |
631 | |
427 | Safefree (req); |
632 | free (req); |
428 | } |
633 | } |
429 | |
634 | |
|
|
635 | static void |
430 | static void req_cancel_subs (aio_req grp) |
636 | req_cancel_subs (aio_req grp) |
431 | { |
637 | { |
432 | aio_req sub; |
|
|
433 | |
|
|
434 | if (grp->type != EIO_GROUP) |
638 | if (grp->type != EIO_GROUP) |
435 | return; |
639 | return; |
436 | |
640 | |
437 | SvREFCNT_dec (grp->sv2); |
641 | SvREFCNT_dec (grp->sv2); |
438 | grp->sv2 = 0; |
642 | grp->sv2 = 0; |
439 | |
643 | |
440 | eio_grp_cancel (grp); |
644 | eio_grp_cancel (grp); |
441 | } |
645 | } |
442 | |
646 | |
443 | #ifdef USE_SOCKETS_AS_HANDLES |
647 | static void ecb_cold |
444 | # define TO_SOCKET(x) (win32_get_osfhandle (x)) |
648 | create_respipe (void) |
445 | #else |
649 | { |
446 | # define TO_SOCKET(x) (x) |
650 | if (s_epipe_renew (&respipe)) |
447 | #endif |
651 | croak ("IO::AIO: unable to initialize result pipe"); |
|
|
652 | } |
448 | |
653 | |
449 | static void |
654 | static void |
450 | create_respipe (void) |
655 | poll_wait (void) |
451 | { |
656 | { |
452 | int old_readfd = respipe [0]; |
|
|
453 | |
|
|
454 | if (respipe [1] >= 0) |
|
|
455 | respipe_close (TO_SOCKET (respipe [1])); |
|
|
456 | |
|
|
457 | #ifdef _WIN32 |
|
|
458 | if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe)) |
|
|
459 | #else |
|
|
460 | if (pipe (respipe)) |
|
|
461 | #endif |
|
|
462 | croak ("unable to initialize result pipe"); |
|
|
463 | |
|
|
464 | if (old_readfd >= 0) |
|
|
465 | { |
|
|
466 | if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0) |
|
|
467 | croak ("unable to initialize result pipe(2)"); |
|
|
468 | |
|
|
469 | respipe_close (respipe [0]); |
|
|
470 | respipe [0] = old_readfd; |
|
|
471 | } |
|
|
472 | |
|
|
473 | #ifdef _WIN32 |
|
|
474 | int arg = 1; |
|
|
475 | if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg) |
|
|
476 | || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg)) |
|
|
477 | #else |
|
|
478 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK) |
|
|
479 | || fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
|
|
480 | #endif |
|
|
481 | croak ("unable to initialize result pipe(3)"); |
|
|
482 | |
|
|
483 | respipe_osf [0] = TO_SOCKET (respipe [0]); |
|
|
484 | respipe_osf [1] = TO_SOCKET (respipe [1]); |
|
|
485 | } |
|
|
486 | |
|
|
487 | static void poll_wait (void) |
|
|
488 | { |
|
|
489 | fd_set rfd; |
|
|
490 | |
|
|
491 | while (eio_nreqs ()) |
657 | while (eio_nreqs ()) |
492 | { |
658 | { |
493 | int size; |
659 | int size; |
494 | |
660 | |
495 | X_LOCK (reslock); |
661 | X_LOCK (reslock); |
… | |
… | |
499 | if (size) |
665 | if (size) |
500 | return; |
666 | return; |
501 | |
667 | |
502 | etp_maybe_start_thread (); |
668 | etp_maybe_start_thread (); |
503 | |
669 | |
504 | FD_ZERO (&rfd); |
670 | s_epipe_wait (&respipe); |
505 | FD_SET (respipe [0], &rfd); |
|
|
506 | |
|
|
507 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
|
|
508 | } |
671 | } |
509 | } |
672 | } |
510 | |
673 | |
511 | static int poll_cb (void) |
674 | static int |
|
|
675 | poll_cb (void) |
512 | { |
676 | { |
513 | for (;;) |
677 | for (;;) |
514 | { |
678 | { |
515 | int res = eio_poll (); |
679 | int res = eio_poll (); |
516 | |
680 | |
… | |
… | |
522 | |
686 | |
523 | poll_wait (); |
687 | poll_wait (); |
524 | } |
688 | } |
525 | } |
689 | } |
526 | |
690 | |
527 | static void atfork_child (void) |
691 | static void ecb_cold |
|
|
692 | reinit (void) |
528 | { |
693 | { |
529 | create_respipe (); |
694 | create_respipe (); |
|
|
695 | |
|
|
696 | if (eio_init (want_poll, done_poll) < 0) |
|
|
697 | croak ("IO::AIO: unable to initialise eio library"); |
530 | } |
698 | } |
|
|
699 | |
|
|
700 | /*****************************************************************************/ |
|
|
701 | |
|
|
702 | #if !_POSIX_MAPPED_FILES |
|
|
703 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
|
|
704 | # define munmap(addr,length) (errno = ENOSYS, -1) |
|
|
705 | #endif |
|
|
706 | |
|
|
707 | #if !_POSIX_MEMORY_PROTECTION |
|
|
708 | # define mprotect(addr,len,prot) (errno = ENOSYS, -1) |
|
|
709 | # define PROT_NONE 0 |
|
|
710 | # define PROT_WRITE 0 |
|
|
711 | # define MAP_PRIVATE 0 |
|
|
712 | # define MAP_SHARED 0 |
|
|
713 | # define MAP_FIXED 0 |
|
|
714 | #endif |
|
|
715 | |
|
|
716 | #define MMAP_MAGIC PERL_MAGIC_ext |
|
|
717 | |
|
|
718 | static int ecb_cold |
|
|
719 | mmap_free (pTHX_ SV *sv, MAGIC *mg) |
|
|
720 | { |
|
|
721 | int old_errno = errno; |
|
|
722 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
|
|
723 | errno = old_errno; |
|
|
724 | |
|
|
725 | mg->mg_obj = 0; /* just in case */ |
|
|
726 | |
|
|
727 | SvREADONLY_off (sv); |
|
|
728 | |
|
|
729 | if (SvPVX (sv) != mg->mg_ptr) |
|
|
730 | croak ("ERROR: IO::AIO::mmap-mapped scalar changed location, detected"); |
|
|
731 | |
|
|
732 | SvCUR_set (sv, 0); |
|
|
733 | SvPVX (sv) = 0; |
|
|
734 | SvOK_off (sv); |
|
|
735 | |
|
|
736 | return 0; |
|
|
737 | } |
|
|
738 | |
|
|
739 | static MGVTBL mmap_vtbl = { |
|
|
740 | 0, 0, 0, 0, mmap_free |
|
|
741 | }; |
|
|
742 | |
|
|
743 | /*****************************************************************************/ |
531 | |
744 | |
532 | static SV * |
745 | static SV * |
533 | get_cb (SV *cb_sv) |
746 | get_cb (SV *cb_sv) |
534 | { |
747 | { |
535 | HV *st; |
748 | SvGETMAGIC (cb_sv); |
536 | GV *gvp; |
749 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
|
|
750 | } |
|
|
751 | |
|
|
752 | static aio_req ecb_noinline |
|
|
753 | dreq (SV *callback) |
|
|
754 | { |
537 | CV *cv; |
755 | SV *cb_cv; |
|
|
756 | aio_req req; |
|
|
757 | int req_pri = next_pri; |
|
|
758 | next_pri = EIO_PRI_DEFAULT; |
538 | |
759 | |
539 | if (!SvOK (cb_sv)) |
760 | cb_cv = get_cb (callback); |
|
|
761 | |
|
|
762 | req = calloc (sizeof (*req), 1); |
|
|
763 | if (!req) |
|
|
764 | croak ("out of memory during eio_req allocation"); |
|
|
765 | |
|
|
766 | req->callback = SvREFCNT_inc (cb_cv); |
|
|
767 | req->pri = req_pri; |
|
|
768 | |
540 | return 0; |
769 | return req; |
541 | |
|
|
542 | cv = sv_2cv (cb_sv, &st, &gvp, 0); |
|
|
543 | |
|
|
544 | if (!cv) |
|
|
545 | croak ("IO::AIO callback must be undef or a CODE reference"); |
|
|
546 | |
|
|
547 | return (SV *)cv; |
|
|
548 | } |
770 | } |
549 | |
771 | |
550 | #define dREQ \ |
772 | #define dREQ \ |
551 | SV *cb_cv; \ |
773 | aio_req req = dreq (callback); \ |
552 | aio_req req; \ |
|
|
553 | int req_pri = next_pri; \ |
|
|
554 | next_pri = EIO_PRI_DEFAULT; \ |
|
|
555 | \ |
|
|
556 | cb_cv = get_cb (callback); \ |
|
|
557 | \ |
|
|
558 | Newz (0, req, 1, eio_req); \ |
|
|
559 | if (!req) \ |
|
|
560 | croak ("out of memory during eio_req allocation"); \ |
|
|
561 | \ |
|
|
562 | req->callback = SvREFCNT_inc (cb_cv); \ |
|
|
563 | req->pri = req_pri |
|
|
564 | |
774 | |
565 | #define REQ_SEND \ |
775 | #define REQ_SEND \ |
566 | PUTBACK; \ |
776 | PUTBACK; \ |
567 | req_submit (req); \ |
777 | req_submit (req); \ |
568 | SPAGAIN; \ |
778 | SPAGAIN; \ |
569 | \ |
779 | \ |
570 | if (GIMME_V != G_VOID) \ |
780 | if (GIMME_V != G_VOID) \ |
571 | XPUSHs (req_sv (req, AIO_REQ_KLASS)); |
781 | XPUSHs (req_sv (req, aio_req_stash)); |
572 | |
782 | |
573 | static int |
783 | ecb_inline void |
574 | extract_fd (SV *fh, int wr) |
784 | req_set_path (aio_req req, SV *path, SV **wdsv, SV **pathsv, eio_wd *wd, void **ptr) |
575 | { |
785 | { |
576 | int fd = PerlIO_fileno (wr ? IoOFP (sv_2io (fh)) : IoIFP (sv_2io (fh))); |
786 | if (expect_false (SvROK (path))) |
|
|
787 | { |
|
|
788 | SV *rv = SvRV (path); |
|
|
789 | SV *wdob; |
577 | |
790 | |
578 | if (fd < 0) |
791 | if (SvTYPE (rv) == SVt_PVAV && AvFILLp (rv) == 1) |
579 | croak ("illegal fh argument, either not an OS file or read/write mode mismatch"); |
792 | { |
|
|
793 | path = AvARRAY (rv)[1]; |
|
|
794 | wdob = AvARRAY (rv)[0]; |
580 | |
795 | |
581 | return fd; |
796 | if (SvOK (wdob)) |
|
|
797 | { |
|
|
798 | *wd = SvAIO_WD (wdob); |
|
|
799 | *wdsv = SvREFCNT_inc_NN (SvRV (wdob)); |
|
|
800 | } |
|
|
801 | else |
|
|
802 | *wd = EIO_INVALID_WD; |
|
|
803 | } |
|
|
804 | else if (SvTYPE (rv) == SVt_PVMG && SvSTASH (rv) == aio_wd_stash) |
|
|
805 | { |
|
|
806 | *wd = (aio_wd)(long)SvIVX (rv); |
|
|
807 | *wdsv = SvREFCNT_inc_NN (rv); |
|
|
808 | *ptr = "."; |
|
|
809 | return; /* path set to "." */ |
|
|
810 | } |
|
|
811 | else |
|
|
812 | croak ("IO::AIO: pathname arguments must be specified as a string, an IO::AIO::WD object or a [IO::AIO::WD, path] pair"); |
|
|
813 | } |
|
|
814 | |
|
|
815 | *pathsv = newSVsv (path); |
|
|
816 | *ptr = SvPVbyte_nolen (*pathsv); |
582 | } |
817 | } |
|
|
818 | |
|
|
819 | static void ecb_noinline |
|
|
820 | req_set_path1 (aio_req req, SV *path) |
|
|
821 | { |
|
|
822 | req_set_path (req, path, &req->sv1, &req->sv3, &req->wd, &req->ptr1); |
|
|
823 | } |
|
|
824 | |
|
|
825 | static void ecb_noinline |
|
|
826 | req_set_fh_or_path (aio_req req, int type_path, int type_fh, SV *fh_or_path) |
|
|
827 | { |
|
|
828 | SV *rv = SvROK (fh_or_path) ? SvRV (fh_or_path) : fh_or_path; |
|
|
829 | |
|
|
830 | switch (SvTYPE (rv)) |
|
|
831 | { |
|
|
832 | case SVt_PVIO: |
|
|
833 | case SVt_PVLV: |
|
|
834 | case SVt_PVGV: |
|
|
835 | req->type = type_fh; |
|
|
836 | req->sv1 = newSVsv (fh_or_path); |
|
|
837 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
838 | break; |
|
|
839 | |
|
|
840 | default: |
|
|
841 | req->type = type_path; |
|
|
842 | req_set_path1 (req, fh_or_path); |
|
|
843 | break; |
|
|
844 | } |
|
|
845 | } |
|
|
846 | |
|
|
847 | XS(boot_IO__AIO) ecb_cold; |
583 | |
848 | |
584 | MODULE = IO::AIO PACKAGE = IO::AIO |
849 | MODULE = IO::AIO PACKAGE = IO::AIO |
585 | |
850 | |
586 | PROTOTYPES: ENABLE |
851 | PROTOTYPES: ENABLE |
587 | |
852 | |
… | |
… | |
589 | { |
854 | { |
590 | static const struct { |
855 | static const struct { |
591 | const char *name; |
856 | const char *name; |
592 | IV iv; |
857 | IV iv; |
593 | } *civ, const_iv[] = { |
858 | } *civ, const_iv[] = { |
594 | # define const_iv(name, value) { # name, (IV) value }, |
859 | # define const_niv(name, value) { # name, (IV) value }, |
|
|
860 | # define const_iv(name) { # name, (IV) name }, |
595 | # define const_eio(name) { # name, (IV) EIO_ ## name }, |
861 | # define const_eio(name) { # name, (IV) EIO_ ## name }, |
596 | const_iv (EXDEV , EXDEV) |
862 | |
|
|
863 | /* you have to re-run ./gendef0 after adding/Removing any constants here */ |
|
|
864 | |
597 | const_iv (ENOSYS , ENOSYS) |
865 | const_iv (ENOSYS) |
|
|
866 | const_iv (EXDEV) |
|
|
867 | const_iv (EBADR) |
|
|
868 | |
598 | const_iv (O_RDONLY, O_RDONLY) |
869 | const_iv (O_RDONLY) |
599 | const_iv (O_WRONLY, O_WRONLY) |
870 | const_iv (O_WRONLY) |
|
|
871 | const_iv (O_RDWR) |
600 | const_iv (O_CREAT , O_CREAT) |
872 | const_iv (O_CREAT) |
601 | const_iv (O_TRUNC , O_TRUNC) |
873 | const_iv (O_TRUNC) |
602 | #ifndef _WIN32 |
874 | const_iv (O_EXCL) |
|
|
875 | const_iv (O_APPEND) |
|
|
876 | |
|
|
877 | const_iv (O_ASYNC) |
|
|
878 | const_iv (O_DIRECT) |
|
|
879 | const_iv (O_NOATIME) |
|
|
880 | |
|
|
881 | const_iv (O_CLOEXEC) |
|
|
882 | const_iv (O_NOCTTY) |
|
|
883 | const_iv (O_NOFOLLOW) |
|
|
884 | const_iv (O_NONBLOCK) |
|
|
885 | const_iv (O_EXEC) |
|
|
886 | const_iv (O_SEARCH) |
|
|
887 | const_iv (O_DIRECTORY) |
|
|
888 | const_iv (O_DSYNC) |
|
|
889 | const_iv (O_RSYNC) |
|
|
890 | const_iv (O_SYNC) |
|
|
891 | const_iv (O_TTY_INIT) |
|
|
892 | |
603 | const_iv (S_IFIFO , S_IFIFO) |
893 | const_iv (S_IFIFO) |
604 | #endif |
894 | const_iv (S_IFCHR) |
|
|
895 | const_iv (S_IFBLK) |
|
|
896 | const_iv (S_IFLNK) |
|
|
897 | const_iv (S_IFREG) |
|
|
898 | const_iv (S_IFDIR) |
|
|
899 | const_iv (S_IFWHT) |
|
|
900 | const_iv (S_IFSOCK) |
|
|
901 | const_iv (S_IFMT) |
|
|
902 | |
605 | const_iv (FADV_NORMAL , POSIX_FADV_NORMAL) |
903 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
606 | const_iv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
904 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
607 | const_iv (FADV_RANDOM , POSIX_FADV_RANDOM) |
905 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
608 | const_iv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
906 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
609 | const_iv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
907 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
610 | const_iv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
908 | const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
|
|
909 | |
|
|
910 | const_niv (MADV_NORMAL , POSIX_MADV_NORMAL) |
|
|
911 | const_niv (MADV_SEQUENTIAL, POSIX_MADV_SEQUENTIAL) |
|
|
912 | const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) |
|
|
913 | const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) |
|
|
914 | const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) |
|
|
915 | |
|
|
916 | const_iv (ST_RDONLY) |
|
|
917 | const_iv (ST_NOSUID) |
|
|
918 | const_iv (ST_NODEV) |
|
|
919 | const_iv (ST_NOEXEC) |
|
|
920 | const_iv (ST_SYNCHRONOUS) |
|
|
921 | const_iv (ST_MANDLOCK) |
|
|
922 | const_iv (ST_WRITE) |
|
|
923 | const_iv (ST_APPEND) |
|
|
924 | const_iv (ST_IMMUTABLE) |
|
|
925 | const_iv (ST_NOATIME) |
|
|
926 | const_iv (ST_NODIRATIME) |
|
|
927 | const_iv (ST_RELATIME) |
|
|
928 | |
|
|
929 | const_iv (PROT_NONE) |
|
|
930 | const_iv (PROT_EXEC) |
|
|
931 | const_iv (PROT_READ) |
|
|
932 | const_iv (PROT_WRITE) |
|
|
933 | |
|
|
934 | /*const_iv (MAP_FIXED)*/ |
|
|
935 | const_iv (MAP_PRIVATE) |
|
|
936 | const_iv (MAP_SHARED) |
|
|
937 | const_iv (MAP_ANONYMOUS) |
|
|
938 | |
|
|
939 | /* linuxish */ |
|
|
940 | const_iv (MAP_HUGETLB) |
|
|
941 | const_iv (MAP_LOCKED) |
|
|
942 | const_iv (MAP_NORESERVE) |
|
|
943 | const_iv (MAP_POPULATE) |
|
|
944 | const_iv (MAP_NONBLOCK) |
|
|
945 | |
|
|
946 | const_iv (FIEMAP_FLAG_SYNC) |
|
|
947 | const_iv (FIEMAP_FLAG_XATTR) |
|
|
948 | const_iv (FIEMAP_FLAGS_COMPAT) |
|
|
949 | const_iv (FIEMAP_EXTENT_LAST) |
|
|
950 | const_iv (FIEMAP_EXTENT_UNKNOWN) |
|
|
951 | const_iv (FIEMAP_EXTENT_DELALLOC) |
|
|
952 | const_iv (FIEMAP_EXTENT_ENCODED) |
|
|
953 | const_iv (FIEMAP_EXTENT_DATA_ENCRYPTED) |
|
|
954 | const_iv (FIEMAP_EXTENT_NOT_ALIGNED) |
|
|
955 | const_iv (FIEMAP_EXTENT_DATA_INLINE) |
|
|
956 | const_iv (FIEMAP_EXTENT_DATA_TAIL) |
|
|
957 | const_iv (FIEMAP_EXTENT_UNWRITTEN) |
|
|
958 | const_iv (FIEMAP_EXTENT_MERGED) |
|
|
959 | const_iv (FIEMAP_EXTENT_SHARED) |
|
|
960 | |
|
|
961 | const_eio (SEEK_SET) |
|
|
962 | const_eio (SEEK_CUR) |
|
|
963 | const_eio (SEEK_END) |
|
|
964 | |
|
|
965 | const_eio (MCL_FUTURE) |
|
|
966 | const_eio (MCL_CURRENT) |
|
|
967 | |
|
|
968 | const_eio (MS_ASYNC) |
|
|
969 | const_eio (MS_INVALIDATE) |
|
|
970 | const_eio (MS_SYNC) |
|
|
971 | |
|
|
972 | const_eio (MT_MODIFY) |
611 | |
973 | |
612 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
974 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
613 | const_eio (SYNC_FILE_RANGE_WRITE) |
975 | const_eio (SYNC_FILE_RANGE_WRITE) |
614 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
976 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
|
|
977 | |
|
|
978 | const_eio (FALLOC_FL_KEEP_SIZE) |
615 | |
979 | |
616 | const_eio (READDIR_DENTS) |
980 | const_eio (READDIR_DENTS) |
617 | const_eio (READDIR_DIRS_FIRST) |
981 | const_eio (READDIR_DIRS_FIRST) |
618 | const_eio (READDIR_STAT_ORDER) |
982 | const_eio (READDIR_STAT_ORDER) |
619 | const_eio (READDIR_FOUND_UNKNOWN) |
983 | const_eio (READDIR_FOUND_UNKNOWN) |
… | |
… | |
627 | const_eio (DT_LNK) |
991 | const_eio (DT_LNK) |
628 | const_eio (DT_SOCK) |
992 | const_eio (DT_SOCK) |
629 | const_eio (DT_WHT) |
993 | const_eio (DT_WHT) |
630 | }; |
994 | }; |
631 | |
995 | |
632 | stash = gv_stashpv ("IO::AIO", 1); |
996 | aio_stash = gv_stashpv ("IO::AIO" , 1); |
|
|
997 | aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); |
|
|
998 | aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); |
|
|
999 | aio_wd_stash = gv_stashpv ("IO::AIO::WD" , 1); |
633 | |
1000 | |
634 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1001 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
635 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1002 | newCONSTSUB (aio_stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
636 | |
1003 | |
637 | create_respipe (); |
1004 | newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); |
638 | |
1005 | |
639 | if (eio_init (want_poll, done_poll) < 0) |
1006 | reinit (); |
640 | croak ("IO::AIO: unable to initialise eio library"); |
|
|
641 | |
|
|
642 | /* atfork child called in fifo order, so before eio's handler */ |
|
|
643 | X_THREAD_ATFORK (0, 0, atfork_child); |
|
|
644 | } |
1007 | } |
645 | |
1008 | |
646 | void |
1009 | void |
|
|
1010 | reinit () |
|
|
1011 | PROTOTYPE: |
|
|
1012 | |
|
|
1013 | void |
647 | max_poll_reqs (int nreqs) |
1014 | max_poll_reqs (unsigned int nreqs) |
648 | PROTOTYPE: $ |
1015 | PROTOTYPE: $ |
649 | CODE: |
1016 | CODE: |
650 | eio_set_max_poll_reqs (nreqs); |
1017 | eio_set_max_poll_reqs (nreqs); |
651 | |
1018 | |
652 | void |
1019 | void |
… | |
… | |
654 | PROTOTYPE: $ |
1021 | PROTOTYPE: $ |
655 | CODE: |
1022 | CODE: |
656 | eio_set_max_poll_time (nseconds); |
1023 | eio_set_max_poll_time (nseconds); |
657 | |
1024 | |
658 | void |
1025 | void |
659 | min_parallel (int nthreads) |
1026 | min_parallel (unsigned int nthreads) |
660 | PROTOTYPE: $ |
1027 | PROTOTYPE: $ |
661 | CODE: |
1028 | CODE: |
662 | eio_set_min_parallel (nthreads); |
1029 | eio_set_min_parallel (nthreads); |
663 | |
1030 | |
664 | void |
1031 | void |
665 | max_parallel (int nthreads) |
1032 | max_parallel (unsigned int nthreads) |
666 | PROTOTYPE: $ |
1033 | PROTOTYPE: $ |
667 | CODE: |
1034 | CODE: |
668 | eio_set_max_parallel (nthreads); |
1035 | eio_set_max_parallel (nthreads); |
669 | |
1036 | |
670 | void |
1037 | void |
671 | max_idle (int nthreads) |
1038 | max_idle (unsigned int nthreads) |
672 | PROTOTYPE: $ |
1039 | PROTOTYPE: $ |
673 | CODE: |
1040 | CODE: |
674 | eio_set_max_idle (nthreads); |
1041 | eio_set_max_idle (nthreads); |
675 | |
1042 | |
676 | void |
1043 | void |
|
|
1044 | idle_timeout (unsigned int seconds) |
|
|
1045 | PROTOTYPE: $ |
|
|
1046 | CODE: |
|
|
1047 | eio_set_idle_timeout (seconds); |
|
|
1048 | |
|
|
1049 | void |
677 | max_outstanding (int maxreqs) |
1050 | max_outstanding (unsigned int maxreqs) |
678 | PROTOTYPE: $ |
1051 | PROTOTYPE: $ |
679 | CODE: |
1052 | CODE: |
680 | max_outstanding = maxreqs; |
1053 | max_outstanding = maxreqs; |
681 | |
1054 | |
682 | void |
1055 | void |
|
|
1056 | aio_wd (SV8 *pathname, SV *callback=&PL_sv_undef) |
|
|
1057 | PPCODE: |
|
|
1058 | { |
|
|
1059 | dREQ; |
|
|
1060 | |
|
|
1061 | req->type = EIO_WD_OPEN; |
|
|
1062 | req_set_path1 (req, pathname); |
|
|
1063 | |
|
|
1064 | REQ_SEND; |
|
|
1065 | } |
|
|
1066 | |
|
|
1067 | void |
683 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
1068 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
684 | PROTOTYPE: $$$;$ |
|
|
685 | PPCODE: |
1069 | PPCODE: |
686 | { |
1070 | { |
687 | dREQ; |
1071 | dREQ; |
688 | |
1072 | |
689 | req->type = EIO_OPEN; |
1073 | req->type = EIO_OPEN; |
690 | req->sv1 = newSVsv (pathname); |
1074 | req_set_path1 (req, pathname); |
691 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
692 | req->int1 = flags; |
1075 | req->int1 = flags; |
693 | req->int2 = mode; |
1076 | req->int2 = mode; |
694 | |
1077 | |
695 | REQ_SEND; |
1078 | REQ_SEND; |
696 | } |
1079 | } |
697 | |
1080 | |
698 | void |
1081 | void |
699 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
1082 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
700 | PROTOTYPE: $;$ |
|
|
701 | ALIAS: |
1083 | ALIAS: |
702 | aio_fsync = EIO_FSYNC |
1084 | aio_fsync = EIO_FSYNC |
703 | aio_fdatasync = EIO_FDATASYNC |
1085 | aio_fdatasync = EIO_FDATASYNC |
|
|
1086 | aio_syncfs = EIO_SYNCFS |
704 | PPCODE: |
1087 | PPCODE: |
705 | { |
1088 | { |
706 | int fd = extract_fd (fh, 0); |
1089 | int fd = s_fileno_croak (fh, 0); |
707 | dREQ; |
1090 | dREQ; |
708 | |
1091 | |
709 | req->type = ix; |
1092 | req->type = ix; |
710 | req->sv1 = newSVsv (fh); |
1093 | req->sv1 = newSVsv (fh); |
711 | req->int1 = fd; |
1094 | req->int1 = fd; |
712 | |
1095 | |
713 | REQ_SEND (req); |
1096 | REQ_SEND; |
714 | } |
1097 | } |
715 | |
1098 | |
716 | void |
1099 | void |
717 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
1100 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
718 | PROTOTYPE: $$$$;$ |
|
|
719 | PPCODE: |
1101 | PPCODE: |
720 | { |
1102 | { |
721 | int fd = extract_fd (fh, 0); |
1103 | int fd = s_fileno_croak (fh, 0); |
722 | dREQ; |
1104 | dREQ; |
723 | |
1105 | |
724 | req->type = EIO_SYNC_FILE_RANGE; |
1106 | req->type = EIO_SYNC_FILE_RANGE; |
725 | req->sv1 = newSVsv (fh); |
1107 | req->sv1 = newSVsv (fh); |
726 | req->int1 = fd; |
1108 | req->int1 = fd; |
727 | req->offs = offset; |
1109 | req->offs = offset; |
728 | req->size = nbytes; |
1110 | req->size = nbytes; |
729 | req->int2 = flags; |
1111 | req->int2 = flags; |
730 | |
1112 | |
731 | REQ_SEND (req); |
1113 | REQ_SEND; |
|
|
1114 | } |
|
|
1115 | |
|
|
1116 | void |
|
|
1117 | aio_fallocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef) |
|
|
1118 | PPCODE: |
|
|
1119 | { |
|
|
1120 | int fd = s_fileno_croak (fh, 0); |
|
|
1121 | dREQ; |
|
|
1122 | |
|
|
1123 | req->type = EIO_FALLOCATE; |
|
|
1124 | req->sv1 = newSVsv (fh); |
|
|
1125 | req->int1 = fd; |
|
|
1126 | req->int2 = mode; |
|
|
1127 | req->offs = offset; |
|
|
1128 | req->size = len; |
|
|
1129 | |
|
|
1130 | REQ_SEND; |
732 | } |
1131 | } |
733 | |
1132 | |
734 | void |
1133 | void |
735 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
1134 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
736 | PROTOTYPE: $;$ |
|
|
737 | PPCODE: |
1135 | PPCODE: |
738 | { |
1136 | { |
739 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
1137 | static int close_fd = -1; /* dummy fd to close fds via dup2 */ |
740 | int fd = extract_fd (fh, 0); |
1138 | int fd = s_fileno_croak (fh, 0); |
741 | dREQ; |
1139 | dREQ; |
742 | |
1140 | |
743 | if (close_pipe < 0) |
1141 | if (expect_false (close_fd < 0)) |
744 | { |
1142 | { |
745 | int pipefd [2]; |
1143 | int pipefd [2]; |
746 | |
1144 | |
|
|
1145 | if ( |
|
|
1146 | #ifdef _WIN32 |
|
|
1147 | _pipe (pipefd, 1, _O_BINARY) < 0 |
|
|
1148 | #else |
747 | if (pipe (pipefd) < 0 |
1149 | pipe (pipefd) < 0 |
748 | || close (pipefd [1]) < 0 |
|
|
749 | || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0) |
1150 | || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0 |
|
|
1151 | #endif |
|
|
1152 | || close (pipefd [1]) < 0 |
|
|
1153 | ) |
750 | abort (); /*D*/ |
1154 | abort (); /*D*/ |
751 | |
1155 | |
752 | close_pipe = pipefd [0]; |
1156 | close_fd = pipefd [0]; |
753 | } |
1157 | } |
754 | |
1158 | |
755 | req->type = EIO_DUP2; |
1159 | req->type = EIO_DUP2; |
756 | req->int1 = close_pipe; |
1160 | req->int1 = close_fd; |
757 | req->sv2 = newSVsv (fh); |
1161 | req->sv2 = newSVsv (fh); |
758 | req->int2 = fd; |
1162 | req->int2 = fd; |
759 | |
1163 | |
760 | REQ_SEND (req); |
1164 | REQ_SEND; |
|
|
1165 | } |
|
|
1166 | |
|
|
1167 | void |
|
|
1168 | aio_seek (SV *fh, SV *offset, int whence, SV *callback=&PL_sv_undef) |
|
|
1169 | PPCODE: |
|
|
1170 | { |
|
|
1171 | int fd = s_fileno_croak (fh, 0); |
|
|
1172 | dREQ; |
|
|
1173 | |
|
|
1174 | req->type = EIO_SEEK; |
|
|
1175 | req->sv1 = newSVsv (fh); |
|
|
1176 | req->int1 = fd; |
|
|
1177 | req->offs = SvVAL64 (offset); |
|
|
1178 | req->int2 = whence; |
|
|
1179 | |
|
|
1180 | REQ_SEND; |
761 | } |
1181 | } |
762 | |
1182 | |
763 | void |
1183 | void |
764 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
1184 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
765 | ALIAS: |
1185 | ALIAS: |
766 | aio_read = EIO_READ |
1186 | aio_read = EIO_READ |
767 | aio_write = EIO_WRITE |
1187 | aio_write = EIO_WRITE |
768 | PROTOTYPE: $$$$$;$ |
|
|
769 | PPCODE: |
1188 | PPCODE: |
770 | { |
1189 | { |
771 | STRLEN svlen; |
1190 | STRLEN svlen; |
772 | int fd = extract_fd (fh, ix == EIO_WRITE); |
1191 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
773 | char *svptr = SvPVbyte (data, svlen); |
1192 | char *svptr = SvPVbyte (data, svlen); |
774 | UV len = SvUV (length); |
1193 | UV len = SvUV (length); |
775 | |
1194 | |
776 | if (dataoffset < 0) |
1195 | if (dataoffset < 0) |
777 | dataoffset += svlen; |
1196 | dataoffset += svlen; |
… | |
… | |
813 | REQ_SEND; |
1232 | REQ_SEND; |
814 | } |
1233 | } |
815 | } |
1234 | } |
816 | |
1235 | |
817 | void |
1236 | void |
818 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
1237 | aio_readlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
819 | PROTOTYPE: $$;$ |
1238 | ALIAS: |
|
|
1239 | aio_readlink = EIO_READLINK |
|
|
1240 | aio_realpath = EIO_REALPATH |
820 | PPCODE: |
1241 | PPCODE: |
821 | { |
1242 | { |
822 | SV *data; |
|
|
823 | dREQ; |
1243 | dREQ; |
824 | |
1244 | |
825 | req->type = EIO_READLINK; |
1245 | req->type = ix; |
826 | req->sv1 = newSVsv (path); |
1246 | req_set_path1 (req, pathname); |
827 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
828 | |
1247 | |
829 | REQ_SEND; |
1248 | REQ_SEND; |
830 | } |
1249 | } |
831 | |
1250 | |
832 | void |
1251 | void |
833 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
1252 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
834 | PROTOTYPE: $$$$;$ |
|
|
835 | PPCODE: |
1253 | PPCODE: |
836 | { |
1254 | { |
837 | int ifd = extract_fd (in_fh , 0); |
1255 | int ifd = s_fileno_croak (in_fh , 0); |
838 | int ofd = extract_fd (out_fh, 0); |
1256 | int ofd = s_fileno_croak (out_fh, 1); |
839 | dREQ; |
1257 | dREQ; |
840 | |
1258 | |
841 | req->type = EIO_SENDFILE; |
1259 | req->type = EIO_SENDFILE; |
842 | req->sv1 = newSVsv (out_fh); |
1260 | req->sv1 = newSVsv (out_fh); |
843 | req->int1 = ofd; |
1261 | req->int1 = ofd; |
… | |
… | |
849 | REQ_SEND; |
1267 | REQ_SEND; |
850 | } |
1268 | } |
851 | |
1269 | |
852 | void |
1270 | void |
853 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
1271 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
854 | PROTOTYPE: $$$;$ |
|
|
855 | PPCODE: |
1272 | PPCODE: |
856 | { |
1273 | { |
857 | int fd = extract_fd (fh, 0); |
1274 | int fd = s_fileno_croak (fh, 0); |
858 | dREQ; |
1275 | dREQ; |
859 | |
1276 | |
860 | req->type = EIO_READAHEAD; |
1277 | req->type = EIO_READAHEAD; |
861 | req->sv1 = newSVsv (fh); |
1278 | req->sv1 = newSVsv (fh); |
862 | req->int1 = fd; |
1279 | req->int1 = fd; |
… | |
… | |
867 | } |
1284 | } |
868 | |
1285 | |
869 | void |
1286 | void |
870 | aio_stat (SV8 *fh_or_path, SV *callback=&PL_sv_undef) |
1287 | aio_stat (SV8 *fh_or_path, SV *callback=&PL_sv_undef) |
871 | ALIAS: |
1288 | ALIAS: |
872 | aio_stat = EIO_STAT |
1289 | aio_stat = EIO_STAT |
873 | aio_lstat = EIO_LSTAT |
1290 | aio_lstat = EIO_LSTAT |
|
|
1291 | aio_statvfs = EIO_STATVFS |
874 | PPCODE: |
1292 | PPCODE: |
875 | { |
1293 | { |
876 | dREQ; |
1294 | dREQ; |
877 | |
1295 | |
878 | req->sv1 = newSVsv (fh_or_path); |
1296 | req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path); |
879 | |
|
|
880 | if (SvPOK (req->sv1)) |
|
|
881 | { |
|
|
882 | req->type = ix; |
|
|
883 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
884 | } |
|
|
885 | else |
|
|
886 | { |
|
|
887 | req->type = EIO_FSTAT; |
|
|
888 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
889 | } |
|
|
890 | |
1297 | |
891 | REQ_SEND; |
1298 | REQ_SEND; |
892 | } |
1299 | } |
|
|
1300 | |
|
|
1301 | UV |
|
|
1302 | major (UV dev) |
|
|
1303 | ALIAS: |
|
|
1304 | minor = 1 |
|
|
1305 | CODE: |
|
|
1306 | RETVAL = ix ? major (dev) : minor (dev); |
|
|
1307 | OUTPUT: |
|
|
1308 | RETVAL |
|
|
1309 | |
|
|
1310 | UV |
|
|
1311 | makedev (UV maj, UV min) |
|
|
1312 | CODE: |
|
|
1313 | RETVAL = makedev (maj, min); |
|
|
1314 | OUTPUT: |
|
|
1315 | RETVAL |
893 | |
1316 | |
894 | void |
1317 | void |
895 | aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) |
1318 | aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) |
896 | PPCODE: |
1319 | PPCODE: |
897 | { |
1320 | { |
898 | dREQ; |
1321 | dREQ; |
899 | |
1322 | |
900 | req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; |
1323 | req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; |
901 | req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; |
1324 | req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; |
902 | req->sv1 = newSVsv (fh_or_path); |
1325 | req_set_fh_or_path (req, EIO_UTIME, EIO_FUTIME, fh_or_path); |
903 | |
|
|
904 | if (SvPOK (req->sv1)) |
|
|
905 | { |
|
|
906 | req->type = EIO_UTIME; |
|
|
907 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
908 | } |
|
|
909 | else |
|
|
910 | { |
|
|
911 | req->type = EIO_FUTIME; |
|
|
912 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
913 | } |
|
|
914 | |
1326 | |
915 | REQ_SEND; |
1327 | REQ_SEND; |
916 | } |
1328 | } |
917 | |
1329 | |
918 | void |
1330 | void |
919 | aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef) |
1331 | aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef) |
920 | PPCODE: |
1332 | PPCODE: |
921 | { |
1333 | { |
922 | dREQ; |
1334 | dREQ; |
923 | |
1335 | |
924 | req->sv1 = newSVsv (fh_or_path); |
|
|
925 | req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
1336 | req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
926 | |
1337 | req_set_fh_or_path (req, EIO_TRUNCATE, EIO_FTRUNCATE, fh_or_path); |
927 | if (SvPOK (req->sv1)) |
|
|
928 | { |
|
|
929 | req->type = EIO_TRUNCATE; |
|
|
930 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
931 | } |
|
|
932 | else |
|
|
933 | { |
|
|
934 | req->type = EIO_FTRUNCATE; |
|
|
935 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
936 | } |
|
|
937 | |
1338 | |
938 | REQ_SEND; |
1339 | REQ_SEND; |
939 | } |
1340 | } |
940 | |
1341 | |
941 | void |
1342 | void |
942 | aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) |
1343 | aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) |
943 | ALIAS: |
|
|
944 | aio_chmod = EIO_CHMOD |
|
|
945 | aio_mkdir = EIO_MKDIR |
|
|
946 | PPCODE: |
1344 | PPCODE: |
947 | { |
1345 | { |
948 | dREQ; |
1346 | dREQ; |
949 | |
1347 | |
950 | req->int2 = mode; |
1348 | req->int2 = mode; |
951 | req->sv1 = newSVsv (fh_or_path); |
1349 | req_set_fh_or_path (req, EIO_CHMOD, EIO_FCHMOD, fh_or_path); |
952 | |
|
|
953 | if (SvPOK (req->sv1)) |
|
|
954 | { |
|
|
955 | req->type = ix; |
|
|
956 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
957 | } |
|
|
958 | else |
|
|
959 | { |
|
|
960 | req->type = EIO_FCHMOD; |
|
|
961 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
962 | } |
|
|
963 | |
1350 | |
964 | REQ_SEND; |
1351 | REQ_SEND; |
965 | } |
1352 | } |
966 | |
1353 | |
967 | void |
1354 | void |
… | |
… | |
970 | { |
1357 | { |
971 | dREQ; |
1358 | dREQ; |
972 | |
1359 | |
973 | req->int2 = SvOK (uid) ? SvIV (uid) : -1; |
1360 | req->int2 = SvOK (uid) ? SvIV (uid) : -1; |
974 | req->int3 = SvOK (gid) ? SvIV (gid) : -1; |
1361 | req->int3 = SvOK (gid) ? SvIV (gid) : -1; |
975 | req->sv1 = newSVsv (fh_or_path); |
1362 | req_set_fh_or_path (req, EIO_CHOWN, EIO_FCHOWN, fh_or_path); |
976 | |
|
|
977 | if (SvPOK (req->sv1)) |
|
|
978 | { |
|
|
979 | req->type = EIO_CHOWN; |
|
|
980 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
981 | } |
|
|
982 | else |
|
|
983 | { |
|
|
984 | req->type = EIO_FCHOWN; |
|
|
985 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
986 | } |
|
|
987 | |
1363 | |
988 | REQ_SEND; |
1364 | REQ_SEND; |
989 | } |
1365 | } |
990 | |
1366 | |
991 | void |
1367 | void |
… | |
… | |
993 | PPCODE: |
1369 | PPCODE: |
994 | { |
1370 | { |
995 | dREQ; |
1371 | dREQ; |
996 | |
1372 | |
997 | req->type = EIO_READDIR; |
1373 | req->type = EIO_READDIR; |
998 | req->sv1 = newSVsv (pathname); |
|
|
999 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1000 | req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1; |
1374 | req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1; |
1001 | |
1375 | |
1002 | if (flags & EIO_READDIR_DENTS) |
1376 | if (flags & EIO_READDIR_DENTS) |
1003 | req->int1 |= EIO_READDIR_CUSTOM2; |
1377 | req->int1 |= EIO_READDIR_CUSTOM2; |
1004 | |
1378 | |
|
|
1379 | req_set_path1 (req, pathname); |
|
|
1380 | |
1005 | REQ_SEND; |
1381 | REQ_SEND; |
|
|
1382 | } |
|
|
1383 | |
|
|
1384 | void |
|
|
1385 | aio_mkdir (SV8 *pathname, int mode, SV *callback=&PL_sv_undef) |
|
|
1386 | PPCODE: |
|
|
1387 | { |
|
|
1388 | dREQ; |
|
|
1389 | |
|
|
1390 | req->type = EIO_MKDIR; |
|
|
1391 | req->int2 = mode; |
|
|
1392 | req_set_path1 (req, pathname); |
|
|
1393 | |
|
|
1394 | REQ_SEND; |
1006 | } |
1395 | } |
1007 | |
1396 | |
1008 | void |
1397 | void |
1009 | aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
1398 | aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
1010 | ALIAS: |
1399 | ALIAS: |
… | |
… | |
1014 | PPCODE: |
1403 | PPCODE: |
1015 | { |
1404 | { |
1016 | dREQ; |
1405 | dREQ; |
1017 | |
1406 | |
1018 | req->type = ix; |
1407 | req->type = ix; |
1019 | req->sv1 = newSVsv (pathname); |
1408 | req_set_path1 (req, pathname); |
1020 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1021 | |
1409 | |
1022 | REQ_SEND; |
1410 | REQ_SEND; |
1023 | } |
1411 | } |
1024 | |
1412 | |
1025 | void |
1413 | void |
… | |
… | |
1028 | aio_link = EIO_LINK |
1416 | aio_link = EIO_LINK |
1029 | aio_symlink = EIO_SYMLINK |
1417 | aio_symlink = EIO_SYMLINK |
1030 | aio_rename = EIO_RENAME |
1418 | aio_rename = EIO_RENAME |
1031 | PPCODE: |
1419 | PPCODE: |
1032 | { |
1420 | { |
|
|
1421 | eio_wd wd2 = 0; |
1033 | dREQ; |
1422 | dREQ; |
1034 | |
1423 | |
1035 | req->type = ix; |
1424 | req->type = ix; |
1036 | req->sv1 = newSVsv (oldpath); |
1425 | req_set_path1 (req, oldpath); |
1037 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1426 | req_set_path (req, newpath, &req->sv2, &req->sv4, &wd2, &req->ptr2); |
1038 | req->sv2 = newSVsv (newpath); |
1427 | req->int3 = (long)wd2; |
1039 | req->ptr2 = SvPVbyte_nolen (req->sv2); |
|
|
1040 | |
1428 | |
1041 | REQ_SEND; |
1429 | REQ_SEND; |
1042 | } |
1430 | } |
1043 | |
1431 | |
1044 | void |
1432 | void |
… | |
… | |
1046 | PPCODE: |
1434 | PPCODE: |
1047 | { |
1435 | { |
1048 | dREQ; |
1436 | dREQ; |
1049 | |
1437 | |
1050 | req->type = EIO_MKNOD; |
1438 | req->type = EIO_MKNOD; |
1051 | req->sv1 = newSVsv (pathname); |
|
|
1052 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1053 | req->int2 = (mode_t)mode; |
1439 | req->int2 = (mode_t)mode; |
1054 | req->offs = dev; |
1440 | req->offs = dev; |
|
|
1441 | req_set_path1 (req, pathname); |
1055 | |
1442 | |
1056 | REQ_SEND; |
1443 | REQ_SEND; |
1057 | } |
1444 | } |
1058 | |
1445 | |
1059 | void |
1446 | void |
|
|
1447 | aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) |
|
|
1448 | ALIAS: |
|
|
1449 | aio_mtouch = EIO_MTOUCH |
|
|
1450 | aio_msync = EIO_MSYNC |
|
|
1451 | PPCODE: |
|
|
1452 | { |
|
|
1453 | STRLEN svlen; |
|
|
1454 | char *svptr = SvPVbyte (data, svlen); |
|
|
1455 | UV len = SvUV (length); |
|
|
1456 | |
|
|
1457 | if (offset < 0) |
|
|
1458 | offset += svlen; |
|
|
1459 | |
|
|
1460 | if (offset < 0 || offset > svlen) |
|
|
1461 | croak ("offset outside of scalar"); |
|
|
1462 | |
|
|
1463 | if (!SvOK (length) || len + offset > svlen) |
|
|
1464 | len = svlen - offset; |
|
|
1465 | |
|
|
1466 | { |
|
|
1467 | dREQ; |
|
|
1468 | |
|
|
1469 | req->type = ix; |
|
|
1470 | req->sv2 = SvREFCNT_inc (data); |
|
|
1471 | req->ptr2 = (char *)svptr + offset; |
|
|
1472 | req->size = len; |
|
|
1473 | req->int1 = flags; |
|
|
1474 | |
|
|
1475 | REQ_SEND; |
|
|
1476 | } |
|
|
1477 | } |
|
|
1478 | |
|
|
1479 | void |
|
|
1480 | aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback=&PL_sv_undef) |
|
|
1481 | PPCODE: |
|
|
1482 | { |
|
|
1483 | STRLEN svlen; |
|
|
1484 | char *svptr = SvPVbyte (data, svlen); |
|
|
1485 | UV len = SvUV (length); |
|
|
1486 | |
|
|
1487 | if (offset < 0) |
|
|
1488 | offset += svlen; |
|
|
1489 | |
|
|
1490 | if (offset < 0 || offset > svlen) |
|
|
1491 | croak ("offset outside of scalar"); |
|
|
1492 | |
|
|
1493 | if (!SvOK (length) || len + offset > svlen) |
|
|
1494 | len = svlen - offset; |
|
|
1495 | |
|
|
1496 | { |
|
|
1497 | dREQ; |
|
|
1498 | |
|
|
1499 | req->type = EIO_MLOCK; |
|
|
1500 | req->sv2 = SvREFCNT_inc (data); |
|
|
1501 | req->ptr2 = (char *)svptr + offset; |
|
|
1502 | req->size = len; |
|
|
1503 | |
|
|
1504 | REQ_SEND; |
|
|
1505 | } |
|
|
1506 | } |
|
|
1507 | |
|
|
1508 | void |
|
|
1509 | aio_mlockall (IV flags, SV *callback=&PL_sv_undef) |
|
|
1510 | PPCODE: |
|
|
1511 | { |
|
|
1512 | dREQ; |
|
|
1513 | |
|
|
1514 | req->type = EIO_MLOCKALL; |
|
|
1515 | req->int1 = flags; |
|
|
1516 | |
|
|
1517 | REQ_SEND; |
|
|
1518 | } |
|
|
1519 | |
|
|
1520 | void |
|
|
1521 | aio_fiemap (SV *fh, off_t start, SV *length, U32 flags, SV *count, SV *callback=&PL_sv_undef) |
|
|
1522 | PPCODE: |
|
|
1523 | { |
|
|
1524 | int fd = s_fileno_croak (fh, 0); |
|
|
1525 | dREQ; |
|
|
1526 | |
|
|
1527 | req->type = EIO_CUSTOM; |
|
|
1528 | req->sv1 = newSVsv (fh); |
|
|
1529 | req->int1 = fd; |
|
|
1530 | |
|
|
1531 | req->feed = fiemap; |
|
|
1532 | #if HAVE_FIEMAP |
|
|
1533 | /* keep our fingers crossed that the next two types are 64 bit */ |
|
|
1534 | req->offs = start; |
|
|
1535 | req->size = SvOK (length) ? SvVAL64 (length) : ~0ULL; |
|
|
1536 | req->int2 = flags; |
|
|
1537 | req->int3 = SvOK (count) ? SvIV (count) : -1; |
|
|
1538 | #endif |
|
|
1539 | |
|
|
1540 | REQ_SEND; |
|
|
1541 | } |
|
|
1542 | |
|
|
1543 | void |
1060 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1544 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1061 | PPCODE: |
1545 | PPCODE: |
1062 | { |
1546 | { |
1063 | dREQ; |
1547 | dREQ; |
1064 | |
1548 | |
… | |
… | |
1068 | REQ_SEND; |
1552 | REQ_SEND; |
1069 | } |
1553 | } |
1070 | |
1554 | |
1071 | void |
1555 | void |
1072 | aio_group (SV *callback=&PL_sv_undef) |
1556 | aio_group (SV *callback=&PL_sv_undef) |
1073 | PROTOTYPE: ;$ |
|
|
1074 | PPCODE: |
1557 | PPCODE: |
1075 | { |
1558 | { |
1076 | dREQ; |
1559 | dREQ; |
1077 | |
1560 | |
1078 | req->type = EIO_GROUP; |
1561 | req->type = EIO_GROUP; |
1079 | |
1562 | |
1080 | req_submit (req); |
1563 | req_submit (req); |
1081 | XPUSHs (req_sv (req, AIO_GRP_KLASS)); |
1564 | XPUSHs (req_sv (req, aio_grp_stash)); |
1082 | } |
1565 | } |
1083 | |
1566 | |
1084 | void |
1567 | void |
1085 | aio_nop (SV *callback=&PL_sv_undef) |
1568 | aio_nop (SV *callback=&PL_sv_undef) |
1086 | ALIAS: |
1569 | ALIAS: |
… | |
… | |
1095 | REQ_SEND; |
1578 | REQ_SEND; |
1096 | } |
1579 | } |
1097 | |
1580 | |
1098 | int |
1581 | int |
1099 | aioreq_pri (int pri = 0) |
1582 | aioreq_pri (int pri = 0) |
1100 | PROTOTYPE: ;$ |
|
|
1101 | CODE: |
1583 | CODE: |
1102 | RETVAL = next_pri; |
1584 | RETVAL = next_pri; |
1103 | if (items > 0) |
1585 | if (items > 0) |
1104 | { |
1586 | { |
1105 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
1587 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
… | |
… | |
1117 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
1599 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
1118 | next_pri = nice; |
1600 | next_pri = nice; |
1119 | |
1601 | |
1120 | void |
1602 | void |
1121 | flush () |
1603 | flush () |
1122 | PROTOTYPE: |
|
|
1123 | CODE: |
1604 | CODE: |
1124 | while (eio_nreqs ()) |
1605 | while (eio_nreqs ()) |
1125 | { |
1606 | { |
1126 | poll_wait (); |
1607 | poll_wait (); |
1127 | poll_cb (); |
1608 | poll_cb (); |
1128 | } |
1609 | } |
1129 | |
1610 | |
1130 | int |
1611 | int |
1131 | poll() |
1612 | poll () |
1132 | PROTOTYPE: |
|
|
1133 | CODE: |
1613 | CODE: |
1134 | poll_wait (); |
1614 | poll_wait (); |
1135 | RETVAL = poll_cb (); |
1615 | RETVAL = poll_cb (); |
1136 | OUTPUT: |
1616 | OUTPUT: |
1137 | RETVAL |
1617 | RETVAL |
1138 | |
1618 | |
1139 | int |
1619 | int |
1140 | poll_fileno() |
1620 | poll_fileno () |
1141 | PROTOTYPE: |
|
|
1142 | CODE: |
1621 | CODE: |
1143 | RETVAL = respipe [0]; |
1622 | RETVAL = s_epipe_fd (&respipe); |
1144 | OUTPUT: |
1623 | OUTPUT: |
1145 | RETVAL |
1624 | RETVAL |
1146 | |
1625 | |
1147 | int |
1626 | int |
1148 | poll_cb(...) |
1627 | poll_cb (...) |
1149 | PROTOTYPE: |
1628 | PROTOTYPE: |
1150 | CODE: |
1629 | CODE: |
1151 | RETVAL = poll_cb (); |
1630 | RETVAL = poll_cb (); |
1152 | OUTPUT: |
1631 | OUTPUT: |
1153 | RETVAL |
1632 | RETVAL |
1154 | |
1633 | |
1155 | void |
1634 | void |
1156 | poll_wait() |
1635 | poll_wait () |
1157 | PROTOTYPE: |
|
|
1158 | CODE: |
1636 | CODE: |
1159 | poll_wait (); |
1637 | poll_wait (); |
1160 | |
1638 | |
1161 | int |
1639 | int |
1162 | nreqs() |
1640 | nreqs () |
1163 | PROTOTYPE: |
|
|
1164 | CODE: |
1641 | CODE: |
1165 | RETVAL = eio_nreqs (); |
1642 | RETVAL = eio_nreqs (); |
1166 | OUTPUT: |
1643 | OUTPUT: |
1167 | RETVAL |
1644 | RETVAL |
1168 | |
1645 | |
1169 | int |
1646 | int |
1170 | nready() |
1647 | nready () |
1171 | PROTOTYPE: |
|
|
1172 | CODE: |
1648 | CODE: |
1173 | RETVAL = eio_nready (); |
1649 | RETVAL = eio_nready (); |
1174 | OUTPUT: |
1650 | OUTPUT: |
1175 | RETVAL |
1651 | RETVAL |
1176 | |
1652 | |
1177 | int |
1653 | int |
1178 | npending() |
1654 | npending () |
1179 | PROTOTYPE: |
|
|
1180 | CODE: |
1655 | CODE: |
1181 | RETVAL = eio_npending (); |
1656 | RETVAL = eio_npending (); |
1182 | OUTPUT: |
1657 | OUTPUT: |
1183 | RETVAL |
1658 | RETVAL |
1184 | |
1659 | |
1185 | int |
1660 | int |
1186 | nthreads() |
1661 | nthreads () |
1187 | PROTOTYPE: |
|
|
1188 | CODE: |
1662 | CODE: |
1189 | RETVAL = eio_nthreads (); |
1663 | RETVAL = eio_nthreads (); |
1190 | OUTPUT: |
1664 | OUTPUT: |
1191 | RETVAL |
1665 | RETVAL |
1192 | |
1666 | |
1193 | int |
1667 | int |
1194 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1668 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1195 | PROTOTYPE: $$$$ |
|
|
1196 | CODE: |
1669 | CODE: |
1197 | { |
|
|
1198 | #if _XOPEN_SOURCE >= 600 |
|
|
1199 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1670 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1200 | #else |
|
|
1201 | RETVAL = errno = ENOSYS; |
|
|
1202 | #endif |
|
|
1203 | } |
|
|
1204 | OUTPUT: |
1671 | OUTPUT: |
1205 | RETVAL |
1672 | RETVAL |
1206 | |
1673 | |
1207 | ssize_t |
1674 | IV |
1208 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1675 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1209 | PROTOTYPE: $$$$ |
|
|
1210 | CODE: |
1676 | CODE: |
1211 | eio_sendfile_sync (ofh, ifh, offset, count); |
1677 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
|
|
1678 | OUTPUT: |
|
|
1679 | RETVAL |
|
|
1680 | |
|
|
1681 | void |
|
|
1682 | mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) |
|
|
1683 | PPCODE: |
|
|
1684 | sv_unmagic (scalar, MMAP_MAGIC); |
|
|
1685 | { |
|
|
1686 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
|
|
1687 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
|
|
1688 | if (addr == (void *)-1) |
|
|
1689 | XSRETURN_NO; |
|
|
1690 | |
|
|
1691 | sv_force_normal (scalar); |
|
|
1692 | |
|
|
1693 | /* we store the length in mg_obj, as namlen is I32 :/ */ |
|
|
1694 | sv_magicext (scalar, 0, MMAP_MAGIC, &mmap_vtbl, (char *)addr, 0) |
|
|
1695 | ->mg_obj = (SV *)length; |
|
|
1696 | |
|
|
1697 | SvUPGRADE (scalar, SVt_PV); /* nop... */ |
|
|
1698 | |
|
|
1699 | if (!(prot & PROT_WRITE)) |
|
|
1700 | SvREADONLY_on (scalar); |
|
|
1701 | |
|
|
1702 | if (SvLEN (scalar)) |
|
|
1703 | Safefree (SvPVX (scalar)); |
|
|
1704 | |
|
|
1705 | SvPVX (scalar) = (char *)addr; |
|
|
1706 | SvCUR_set (scalar, length); |
|
|
1707 | SvLEN_set (scalar, 0); |
|
|
1708 | SvPOK_only (scalar); |
|
|
1709 | |
|
|
1710 | XSRETURN_YES; |
|
|
1711 | } |
|
|
1712 | |
|
|
1713 | void |
|
|
1714 | munmap (SV *scalar) |
|
|
1715 | CODE: |
|
|
1716 | sv_unmagic (scalar, MMAP_MAGIC); |
|
|
1717 | |
|
|
1718 | int |
|
|
1719 | madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
|
|
1720 | ALIAS: |
|
|
1721 | mprotect = 1 |
|
|
1722 | CODE: |
|
|
1723 | { |
|
|
1724 | STRLEN svlen; |
|
|
1725 | void *addr = SvPVbyte (scalar, svlen); |
|
|
1726 | size_t len = SvUV (length); |
|
|
1727 | |
|
|
1728 | if (offset < 0) |
|
|
1729 | offset += svlen; |
|
|
1730 | |
|
|
1731 | if (offset < 0 || offset > svlen) |
|
|
1732 | croak ("offset outside of scalar"); |
|
|
1733 | |
|
|
1734 | if (!SvOK (length) || len + offset > svlen) |
|
|
1735 | len = svlen - offset; |
|
|
1736 | |
|
|
1737 | addr = (void *)(((intptr_t)addr) + offset); |
|
|
1738 | eio_page_align (&addr, &len); |
|
|
1739 | |
|
|
1740 | switch (ix) |
|
|
1741 | { |
|
|
1742 | case 0: RETVAL = posix_madvise (addr, len, advice_or_prot); break; |
|
|
1743 | case 1: RETVAL = mprotect (addr, len, advice_or_prot); break; |
|
|
1744 | } |
|
|
1745 | } |
|
|
1746 | OUTPUT: |
|
|
1747 | RETVAL |
|
|
1748 | |
|
|
1749 | int |
|
|
1750 | munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef) |
|
|
1751 | CODE: |
|
|
1752 | { |
|
|
1753 | STRLEN svlen; |
|
|
1754 | void *addr = SvPVbyte (scalar, svlen); |
|
|
1755 | size_t len = SvUV (length); |
|
|
1756 | |
|
|
1757 | if (offset < 0) |
|
|
1758 | offset += svlen; |
|
|
1759 | |
|
|
1760 | if (offset < 0 || offset > svlen) |
|
|
1761 | croak ("offset outside of scalar"); |
|
|
1762 | |
|
|
1763 | if (!SvOK (length) || len + offset > svlen) |
|
|
1764 | len = svlen - offset; |
|
|
1765 | |
|
|
1766 | addr = (void *)(((intptr_t)addr) + offset); |
|
|
1767 | eio_page_align (&addr, &len); |
|
|
1768 | #if _POSIX_MEMLOCK_RANGE |
|
|
1769 | RETVAL = munlock (addr, len); |
|
|
1770 | #else |
|
|
1771 | RETVAL = ((errno = ENOSYS), -1); |
|
|
1772 | #endif |
|
|
1773 | } |
|
|
1774 | OUTPUT: |
|
|
1775 | RETVAL |
|
|
1776 | |
|
|
1777 | int |
|
|
1778 | munlockall () |
|
|
1779 | CODE: |
|
|
1780 | #if _POSIX_MEMLOCK |
|
|
1781 | munlockall (); |
|
|
1782 | #else |
|
|
1783 | RETVAL = -1; |
|
|
1784 | errno = ENOSYS; |
|
|
1785 | #endif |
|
|
1786 | OUTPUT: |
|
|
1787 | RETVAL |
1212 | |
1788 | |
1213 | void _on_next_submit (SV *cb) |
1789 | void _on_next_submit (SV *cb) |
1214 | CODE: |
1790 | CODE: |
1215 | SvREFCNT_dec (on_next_submit); |
1791 | SvREFCNT_dec (on_next_submit); |
1216 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1792 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1217 | |
1793 | |
1218 | PROTOTYPES: DISABLE |
1794 | PROTOTYPES: DISABLE |
1219 | |
1795 | |
|
|
1796 | MODULE = IO::AIO PACKAGE = IO::AIO::WD |
|
|
1797 | |
|
|
1798 | BOOT: |
|
|
1799 | { |
|
|
1800 | newCONSTSUB (aio_stash, "CWD" , newSVaio_wd (EIO_CWD )); |
|
|
1801 | newCONSTSUB (aio_stash, "INVALID_WD", newSVaio_wd (EIO_INVALID_WD)); |
|
|
1802 | } |
|
|
1803 | |
|
|
1804 | void |
|
|
1805 | DESTROY (SV *self) |
|
|
1806 | CODE: |
|
|
1807 | { |
|
|
1808 | aio_wd wd = SvAIO_WD (self); |
|
|
1809 | #if HAVE_AT |
|
|
1810 | { |
|
|
1811 | SV *callback = &PL_sv_undef; |
|
|
1812 | dREQ; /* clobbers next_pri :/ */ |
|
|
1813 | next_pri = req->pri; /* restore next_pri */ |
|
|
1814 | req->pri = EIO_PRI_MAX; /* better use max. priority to conserve fds */ |
|
|
1815 | req->type = EIO_WD_CLOSE; |
|
|
1816 | req->wd = wd; |
|
|
1817 | REQ_SEND; |
|
|
1818 | } |
|
|
1819 | #else |
|
|
1820 | eio_wd_close_sync (wd); |
|
|
1821 | #endif |
|
|
1822 | } |
|
|
1823 | |
1220 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
1824 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
1221 | |
1825 | |
1222 | void |
1826 | void |
1223 | cancel (aio_req_ornot req) |
1827 | cancel (aio_req_ornot req) |
1224 | CODE: |
1828 | CODE: |
… | |
… | |
1231 | if (GIMME_V != G_VOID) |
1835 | if (GIMME_V != G_VOID) |
1232 | XPUSHs (req->callback ? sv_2mortal (newRV_inc (req->callback)) : &PL_sv_undef); |
1836 | XPUSHs (req->callback ? sv_2mortal (newRV_inc (req->callback)) : &PL_sv_undef); |
1233 | |
1837 | |
1234 | if (items > 1) |
1838 | if (items > 1) |
1235 | { |
1839 | { |
1236 | SV *cb_cv = get_cb (callback); |
1840 | SV *cb_cv =get_cb (callback); |
1237 | |
1841 | |
1238 | SvREFCNT_dec (req->callback); |
1842 | SvREFCNT_dec (req->callback); |
1239 | req->callback = SvREFCNT_inc (cb_cv); |
1843 | req->callback = SvREFCNT_inc (cb_cv); |
1240 | } |
1844 | } |
1241 | } |
1845 | } |