… | |
… | |
11 | #include <stddef.h> |
11 | #include <stddef.h> |
12 | #include <stdlib.h> |
12 | #include <stdlib.h> |
13 | #include <errno.h> |
13 | #include <errno.h> |
14 | #include <sys/types.h> |
14 | #include <sys/types.h> |
15 | #include <sys/stat.h> |
15 | #include <sys/stat.h> |
16 | #include <sys/statvfs.h> |
|
|
17 | #include <limits.h> |
16 | #include <limits.h> |
18 | #include <fcntl.h> |
17 | #include <fcntl.h> |
19 | #include <sched.h> |
18 | #include <sched.h> |
20 | |
19 | |
21 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
20 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
22 | # include <sys/mman.h> |
21 | # include <sys/mman.h> |
23 | #endif |
22 | #endif |
24 | |
23 | |
25 | /* perl namespace pollution */ |
24 | /* perl namespace pollution */ |
26 | #undef VERSION |
25 | #undef VERSION |
27 | |
|
|
28 | #ifdef _WIN32 |
|
|
29 | |
|
|
30 | # define EIO_STRUCT_DIRENT Direntry_t |
|
|
31 | # undef malloc |
|
|
32 | # undef free |
|
|
33 | |
|
|
34 | // perl overrides all those nice win32 functions |
|
|
35 | # undef open |
|
|
36 | # undef read |
|
|
37 | # undef write |
|
|
38 | # undef send |
|
|
39 | # undef recv |
|
|
40 | # undef stat |
|
|
41 | # undef fstat |
|
|
42 | # define lstat stat |
|
|
43 | # undef truncate |
|
|
44 | # undef ftruncate |
|
|
45 | # undef open |
|
|
46 | # undef close |
|
|
47 | # undef unlink |
|
|
48 | # undef rmdir |
|
|
49 | # undef rename |
|
|
50 | # undef lseek |
|
|
51 | |
|
|
52 | # define chown(a,b,c) (errno = ENOSYS, -1) |
|
|
53 | # define fchown(a,b,c) (errno = ENOSYS, -1) |
|
|
54 | # define fchmod(a,b) (errno = ENOSYS, -1) |
|
|
55 | # define symlink(a,b) (errno = ENOSYS, -1) |
|
|
56 | # define readlink(a,b,c) (errno = ENOSYS, -1) |
|
|
57 | # define mknod(a,b,c) (errno = ENOSYS, -1) |
|
|
58 | # define truncate(a,b) (errno = ENOSYS, -1) |
|
|
59 | # define ftruncate(fd,o) chsize ((fd), (o)) |
|
|
60 | # define fsync(fd) _commit (fd) |
|
|
61 | # define opendir(fd) (errno = ENOSYS, 0) |
|
|
62 | # define readdir(fd) (errno = ENOSYS, -1) |
|
|
63 | # define closedir(fd) (errno = ENOSYS, -1) |
|
|
64 | # define mkdir(a,b) mkdir (a) |
|
|
65 | |
|
|
66 | #else |
|
|
67 | |
|
|
68 | # include <sys/time.h> |
|
|
69 | # include <sys/select.h> |
|
|
70 | # include <unistd.h> |
|
|
71 | # include <utime.h> |
|
|
72 | # include <signal.h> |
|
|
73 | # define EIO_STRUCT_DIRENT struct dirent |
|
|
74 | |
|
|
75 | #endif |
|
|
76 | |
26 | |
77 | /* perl stupidly overrides readdir and maybe others */ |
27 | /* perl stupidly overrides readdir and maybe others */ |
78 | /* with thread-unsafe versions, imagine that :( */ |
28 | /* with thread-unsafe versions, imagine that :( */ |
79 | #undef readdir |
29 | #undef readdir |
80 | #undef opendir |
30 | #undef opendir |
81 | #undef closedir |
31 | #undef closedir |
82 | |
32 | |
|
|
33 | #ifdef _WIN32 |
|
|
34 | |
|
|
35 | // perl overrides all those nice libc functions |
|
|
36 | |
|
|
37 | #undef malloc |
|
|
38 | #undef free |
|
|
39 | #undef open |
|
|
40 | #undef read |
|
|
41 | #undef write |
|
|
42 | #undef send |
|
|
43 | #undef recv |
|
|
44 | #undef stat |
|
|
45 | #undef lstat |
|
|
46 | #undef fstat |
|
|
47 | #undef truncate |
|
|
48 | #undef ftruncate |
|
|
49 | #undef open |
|
|
50 | #undef link |
|
|
51 | #undef close |
|
|
52 | #undef unlink |
|
|
53 | #undef mkdir |
|
|
54 | #undef rmdir |
|
|
55 | #undef rename |
|
|
56 | #undef lseek |
|
|
57 | #undef opendir |
|
|
58 | #undef readdir |
|
|
59 | #undef closedir |
|
|
60 | #undef chmod |
|
|
61 | #undef fchmod |
|
|
62 | #undef dup |
|
|
63 | #undef dup2 |
|
|
64 | #undef abort |
|
|
65 | #undef pipe |
|
|
66 | |
|
|
67 | #define EIO_STRUCT_STAT struct _stati64 |
|
|
68 | #define EIO_STRUCT_STATI64 |
|
|
69 | |
|
|
70 | #else |
|
|
71 | |
|
|
72 | #include <sys/time.h> |
|
|
73 | #include <sys/select.h> |
|
|
74 | #include <unistd.h> |
|
|
75 | #include <utime.h> |
|
|
76 | #include <signal.h> |
|
|
77 | |
83 | #define EIO_STRUCT_STAT Stat_t |
78 | #define EIO_STRUCT_STAT Stat_t |
|
|
79 | |
|
|
80 | #endif |
84 | |
81 | |
85 | /* use NV for 32 bit perls as it allows larger offsets */ |
82 | /* use NV for 32 bit perls as it allows larger offsets */ |
86 | #if IVSIZE >= 8 |
83 | #if IVSIZE >= 8 |
87 | # define VAL64 IV |
84 | # define VAL64 IV |
88 | # define SvVAL64 SvIV |
85 | # define SvVAL64 SvIV |
… | |
… | |
108 | |
105 | |
109 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
106 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
110 | typedef int aio_rfd; /* read file desriptor */ |
107 | typedef int aio_rfd; /* read file desriptor */ |
111 | typedef int aio_wfd; /* write file descriptor */ |
108 | typedef int aio_wfd; /* write file descriptor */ |
112 | |
109 | |
113 | static HV *aio_stash, *aio_req_stash, *aio_grp_stash; |
110 | static HV *aio_stash, *aio_req_stash, *aio_grp_stash, *aio_wd_stash; |
114 | |
111 | |
115 | #define EIO_REQ_MEMBERS \ |
112 | #define EIO_REQ_MEMBERS \ |
116 | SV *callback; \ |
113 | SV *callback; \ |
117 | SV *sv1, *sv2; \ |
114 | SV *sv1, *sv2; \ |
|
|
115 | SV *sv3, *sv4; \ |
118 | STRLEN stroffset; \ |
116 | STRLEN stroffset; \ |
119 | SV *self; |
117 | SV *self; |
120 | |
118 | |
121 | #define EIO_NO_WRAPPERS 1 |
119 | #define EIO_NO_WRAPPERS 1 |
122 | |
120 | |
123 | #include "libeio/config.h" |
121 | #include "libeio/config.h" |
124 | #include "libeio/eio.h" |
122 | #include "libeio/eio.h" |
125 | |
123 | |
|
|
124 | static int req_invoke (eio_req *req); |
|
|
125 | #define EIO_FINISH(req) req_invoke (req) |
|
|
126 | static void req_destroy (eio_req *grp); |
|
|
127 | #define EIO_DESTROY(req) req_destroy (req) |
|
|
128 | |
|
|
129 | #include "libeio/eio.c" |
|
|
130 | |
|
|
131 | /* Linux/others */ |
|
|
132 | #ifndef O_ASYNC |
|
|
133 | # define O_ASYNC 0 |
|
|
134 | #endif |
|
|
135 | #ifndef O_DIRECT |
|
|
136 | # define O_DIRECT 0 |
|
|
137 | #endif |
|
|
138 | #ifndef O_NOATIME |
|
|
139 | # define O_NOATIME 0 |
|
|
140 | #endif |
|
|
141 | |
|
|
142 | /* POSIX */ |
|
|
143 | #ifndef O_CLOEXEC |
|
|
144 | # define O_CLOEXEC 0 |
|
|
145 | #endif |
|
|
146 | #ifndef O_NOFOLLOW |
|
|
147 | # define O_NOFOLLOW 0 |
|
|
148 | #endif |
|
|
149 | #ifndef O_NOCTTY |
|
|
150 | # define O_NOCTTY 0 |
|
|
151 | #endif |
|
|
152 | #ifndef O_NONBLOCK |
|
|
153 | # define O_NONBLOCK 0 |
|
|
154 | #endif |
|
|
155 | #ifndef O_EXEC |
|
|
156 | # define O_EXEC 0 |
|
|
157 | #endif |
|
|
158 | #ifndef O_SEARCH |
|
|
159 | # define O_SEARCH 0 |
|
|
160 | #endif |
|
|
161 | #ifndef O_DIRECTORY |
|
|
162 | # define O_DIRECTORY 0 |
|
|
163 | #endif |
|
|
164 | #ifndef O_DSYNC |
|
|
165 | # define O_DSYNC 0 |
|
|
166 | #endif |
|
|
167 | #ifndef O_RSYNC |
|
|
168 | # define O_RSYNC 0 |
|
|
169 | #endif |
|
|
170 | #ifndef O_SYNC |
|
|
171 | # define O_SYNC 0 |
|
|
172 | #endif |
|
|
173 | #ifndef O_TTY_INIT |
|
|
174 | # define O_TTY_INIT 0 |
|
|
175 | #endif |
|
|
176 | |
126 | #ifndef POSIX_FADV_NORMAL |
177 | #ifndef POSIX_FADV_NORMAL |
127 | # define POSIX_FADV_NORMAL 0 |
178 | # define POSIX_FADV_NORMAL 0 |
128 | #endif |
179 | #endif |
129 | #ifndef POSIX_FADV_SEQUENTIAL |
180 | #ifndef POSIX_FADV_SEQUENTIAL |
130 | # define POSIX_FADV_SEQUENTIAL 0 |
181 | # define POSIX_FADV_SEQUENTIAL 0 |
… | |
… | |
177 | #endif |
228 | #endif |
178 | #ifndef PROT_EXEC |
229 | #ifndef PROT_EXEC |
179 | # define PROT_EXEC 0 |
230 | # define PROT_EXEC 0 |
180 | #endif |
231 | #endif |
181 | |
232 | |
|
|
233 | #ifndef ST_RDONLY |
|
|
234 | # define ST_RDONLY 0 |
|
|
235 | #endif |
|
|
236 | #ifndef ST_NOSUID |
|
|
237 | # define ST_NOSUID 0 |
|
|
238 | #endif |
182 | #ifndef ST_NODEV |
239 | #ifndef ST_NODEV |
183 | # define ST_NODEV 0 |
240 | # define ST_NODEV 0 |
184 | #endif |
241 | #endif |
185 | #ifndef ST_NOEXEC |
242 | #ifndef ST_NOEXEC |
186 | # define ST_NOEXEC 0 |
243 | # define ST_NOEXEC 0 |
… | |
… | |
270 | |
327 | |
271 | #ifndef PAGESIZE |
328 | #ifndef PAGESIZE |
272 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
329 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
273 | #endif |
330 | #endif |
274 | |
331 | |
275 | static int req_invoke (eio_req *req); |
|
|
276 | #define EIO_FINISH(req) req_invoke (req) |
|
|
277 | static void req_destroy (eio_req *grp); |
|
|
278 | #define EIO_DESTROY(req) req_destroy (req) |
|
|
279 | |
|
|
280 | enum { |
332 | enum { |
281 | FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ |
333 | FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ |
282 | }; |
334 | }; |
283 | |
335 | |
284 | #include "libeio/eio.c" |
|
|
285 | |
|
|
286 | typedef eio_req *aio_req; |
336 | typedef eio_req *aio_req; |
287 | typedef eio_req *aio_req_ornot; |
337 | typedef eio_req *aio_req_ornot; |
|
|
338 | typedef eio_wd aio_wd; |
288 | |
339 | |
289 | static SV *on_next_submit; |
340 | static SV *on_next_submit; |
290 | static int next_pri = EIO_PRI_DEFAULT; |
341 | static int next_pri = EIO_PRI_DEFAULT; |
291 | static int max_outstanding; |
342 | static int max_outstanding; |
292 | |
343 | |
293 | static s_epipe respipe; |
344 | static s_epipe respipe; |
294 | |
345 | |
295 | static void req_destroy (aio_req req); |
346 | static void req_destroy (aio_req req); |
296 | static void req_cancel (aio_req req); |
347 | static void req_cancel (aio_req req); |
297 | |
348 | |
298 | static void want_poll (void) |
349 | static void |
|
|
350 | want_poll (void) |
299 | { |
351 | { |
300 | /* write a dummy byte to the pipe so fh becomes ready */ |
352 | /* write a dummy byte to the pipe so fh becomes ready */ |
301 | s_epipe_signal (&respipe); |
353 | s_epipe_signal (&respipe); |
302 | } |
354 | } |
303 | |
355 | |
304 | static void done_poll (void) |
356 | static void |
|
|
357 | done_poll (void) |
305 | { |
358 | { |
306 | /* read any signals sent by the worker threads */ |
359 | /* read any signals sent by the worker threads */ |
307 | s_epipe_drain (&respipe); |
360 | s_epipe_drain (&respipe); |
308 | } |
361 | } |
309 | |
362 | |
310 | /* must be called at most once */ |
363 | /* must be called at most once */ |
|
|
364 | static SV * |
311 | static SV *req_sv (aio_req req, HV *stash) |
365 | req_sv (aio_req req, HV *stash) |
312 | { |
366 | { |
313 | if (!req->self) |
367 | if (!req->self) |
314 | { |
368 | { |
315 | req->self = (SV *)newHV (); |
369 | req->self = (SV *)newHV (); |
316 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
370 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
317 | } |
371 | } |
318 | |
372 | |
319 | return sv_2mortal (sv_bless (newRV_inc (req->self), stash)); |
373 | return sv_2mortal (sv_bless (newRV_inc (req->self), stash)); |
320 | } |
374 | } |
321 | |
375 | |
322 | static aio_req SvAIO_REQ (SV *sv) |
376 | static SV * |
|
|
377 | newSVaio_wd (aio_wd wd) |
|
|
378 | { |
|
|
379 | return sv_bless (newRV_noinc (newSViv ((IV)wd)), aio_wd_stash); |
|
|
380 | } |
|
|
381 | |
|
|
382 | static aio_req |
|
|
383 | SvAIO_REQ (SV *sv) |
323 | { |
384 | { |
324 | MAGIC *mg; |
385 | MAGIC *mg; |
325 | |
386 | |
326 | if (!SvROK (sv) |
387 | if (!SvROK (sv) |
|
|
388 | /* for speed reasons, we do not verify that SvROK actually has a stash ptr */ |
327 | || (SvSTASH (SvRV (sv)) != aio_grp_stash |
389 | || (SvSTASH (SvRV (sv)) != aio_grp_stash |
328 | && SvSTASH (SvRV (sv)) != aio_req_stash |
390 | && SvSTASH (SvRV (sv)) != aio_req_stash |
329 | && !sv_derived_from (sv, "IO::AIO::REQ"))) |
391 | && !sv_derived_from (sv, "IO::AIO::REQ"))) |
330 | croak ("object of class IO::AIO::REQ expected"); |
392 | croak ("object of class IO::AIO::REQ expected"); |
331 | |
393 | |
332 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
394 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
333 | |
395 | |
334 | return mg ? (aio_req)mg->mg_ptr : 0; |
396 | return mg ? (aio_req)mg->mg_ptr : 0; |
335 | } |
397 | } |
336 | |
398 | |
|
|
399 | static aio_wd |
|
|
400 | SvAIO_WD (SV *sv) |
|
|
401 | { |
|
|
402 | if (!SvROK (sv) |
|
|
403 | || SvTYPE (SvRV (sv)) != SVt_PVMG |
|
|
404 | || SvSTASH (SvRV (sv)) != aio_wd_stash) |
|
|
405 | croak ("IO::AIO: expected a working directory object as returned by aio_wd"); |
|
|
406 | |
|
|
407 | return (aio_wd)(long)SvIVX (SvRV (sv)); |
|
|
408 | } |
|
|
409 | |
|
|
410 | static void |
337 | static void aio_grp_feed (aio_req grp) |
411 | aio_grp_feed (aio_req grp) |
338 | { |
412 | { |
339 | if (grp->sv2 && SvOK (grp->sv2)) |
413 | if (grp->sv2 && SvOK (grp->sv2)) |
340 | { |
414 | { |
341 | dSP; |
415 | dSP; |
342 | |
416 | |
… | |
… | |
350 | FREETMPS; |
424 | FREETMPS; |
351 | LEAVE; |
425 | LEAVE; |
352 | } |
426 | } |
353 | } |
427 | } |
354 | |
428 | |
|
|
429 | static void |
355 | static void req_submit (eio_req *req) |
430 | req_submit (eio_req *req) |
356 | { |
431 | { |
357 | eio_submit (req); |
432 | eio_submit (req); |
358 | |
433 | |
359 | if (expect_false (on_next_submit)) |
434 | if (expect_false (on_next_submit)) |
360 | { |
435 | { |
… | |
… | |
367 | PUTBACK; |
442 | PUTBACK; |
368 | call_sv (cb, G_DISCARD | G_EVAL); |
443 | call_sv (cb, G_DISCARD | G_EVAL); |
369 | } |
444 | } |
370 | } |
445 | } |
371 | |
446 | |
|
|
447 | static int |
372 | static int req_invoke (eio_req *req) |
448 | req_invoke (eio_req *req) |
373 | { |
449 | { |
374 | if (req->flags & FLAG_SV2_RO_OFF) |
450 | if (req->flags & FLAG_SV2_RO_OFF) |
375 | SvREADONLY_off (req->sv2); |
451 | SvREADONLY_off (req->sv2); |
376 | |
452 | |
377 | if (!EIO_CANCELLED (req) && req->callback) |
453 | if (!EIO_CANCELLED (req) && req->callback) |
… | |
… | |
398 | SvREADONLY_on (sv_result); |
474 | SvREADONLY_on (sv_result); |
399 | } |
475 | } |
400 | |
476 | |
401 | switch (req->type) |
477 | switch (req->type) |
402 | { |
478 | { |
|
|
479 | case EIO_WD_OPEN: |
|
|
480 | PUSHs (req->result ? &PL_sv_undef : sv_2mortal (newSVaio_wd (req->wd))); |
|
|
481 | break; |
|
|
482 | |
403 | case EIO_READDIR: |
483 | case EIO_READDIR: |
404 | { |
484 | { |
405 | SV *rv = &PL_sv_undef; |
485 | SV *rv = &PL_sv_undef; |
406 | |
486 | |
407 | if (req->result >= 0) |
487 | if (req->result >= 0) |
… | |
… | |
495 | case EIO_STATVFS: |
575 | case EIO_STATVFS: |
496 | case EIO_FSTATVFS: |
576 | case EIO_FSTATVFS: |
497 | { |
577 | { |
498 | SV *rv = &PL_sv_undef; |
578 | SV *rv = &PL_sv_undef; |
499 | |
579 | |
|
|
580 | #ifndef _WIN32 |
500 | if (req->result >= 0) |
581 | if (req->result >= 0) |
501 | { |
582 | { |
502 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
583 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
503 | HV *hv = newHV (); |
584 | HV *hv = newHV (); |
504 | |
585 | |
… | |
… | |
514 | hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); |
595 | hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); |
515 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); |
596 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); |
516 | hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); |
597 | hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); |
517 | hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); |
598 | hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); |
518 | } |
599 | } |
|
|
600 | #endif |
519 | |
601 | |
520 | PUSHs (rv); |
602 | PUSHs (rv); |
521 | } |
603 | } |
522 | |
604 | |
523 | break; |
605 | break; |
… | |
… | |
539 | case EIO_NOP: |
621 | case EIO_NOP: |
540 | case EIO_BUSY: |
622 | case EIO_BUSY: |
541 | break; |
623 | break; |
542 | |
624 | |
543 | case EIO_READLINK: |
625 | case EIO_READLINK: |
|
|
626 | case EIO_REALPATH: |
544 | if (req->result > 0) |
627 | if (req->result > 0) |
545 | PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result))); |
628 | PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result))); |
546 | break; |
629 | break; |
547 | |
630 | |
548 | case EIO_STAT: |
631 | case EIO_STAT: |
549 | case EIO_LSTAT: |
632 | case EIO_LSTAT: |
550 | case EIO_FSTAT: |
633 | case EIO_FSTAT: |
551 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
634 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
|
|
635 | |
552 | PL_laststatval = req->result; |
636 | if (!(PL_laststatval = req->result)) |
|
|
637 | /* if compilation fails here then perl's Stat_t is not struct _stati64 */ |
553 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
638 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
|
|
639 | |
554 | PUSHs (sv_result); |
640 | PUSHs (sv_result); |
555 | break; |
641 | break; |
556 | |
642 | |
557 | case EIO_READ: |
643 | case EIO_READ: |
558 | { |
644 | { |
… | |
… | |
592 | } |
678 | } |
593 | |
679 | |
594 | return !!SvTRUE (ERRSV); |
680 | return !!SvTRUE (ERRSV); |
595 | } |
681 | } |
596 | |
682 | |
|
|
683 | static void |
597 | static void req_destroy (aio_req req) |
684 | req_destroy (aio_req req) |
598 | { |
685 | { |
599 | if (req->self) |
686 | if (req->self) |
600 | { |
687 | { |
601 | sv_unmagic (req->self, PERL_MAGIC_ext); |
688 | sv_unmagic (req->self, PERL_MAGIC_ext); |
602 | SvREFCNT_dec (req->self); |
689 | SvREFCNT_dec (req->self); |
603 | } |
690 | } |
604 | |
691 | |
605 | SvREFCNT_dec (req->sv1); |
692 | SvREFCNT_dec (req->sv1); |
606 | SvREFCNT_dec (req->sv2); |
693 | SvREFCNT_dec (req->sv2); |
|
|
694 | SvREFCNT_dec (req->sv3); |
|
|
695 | SvREFCNT_dec (req->sv4); |
607 | SvREFCNT_dec (req->callback); |
696 | SvREFCNT_dec (req->callback); |
608 | |
697 | |
609 | Safefree (req); |
698 | free (req); |
610 | } |
699 | } |
611 | |
700 | |
|
|
701 | static void |
612 | static void req_cancel_subs (aio_req grp) |
702 | req_cancel_subs (aio_req grp) |
613 | { |
703 | { |
614 | aio_req sub; |
|
|
615 | |
|
|
616 | if (grp->type != EIO_GROUP) |
704 | if (grp->type != EIO_GROUP) |
617 | return; |
705 | return; |
618 | |
706 | |
619 | SvREFCNT_dec (grp->sv2); |
707 | SvREFCNT_dec (grp->sv2); |
620 | grp->sv2 = 0; |
708 | grp->sv2 = 0; |
621 | |
709 | |
622 | eio_grp_cancel (grp); |
710 | eio_grp_cancel (grp); |
623 | } |
711 | } |
624 | |
712 | |
625 | static void |
713 | static void ecb_cold |
626 | create_respipe (void) |
714 | create_respipe (void) |
627 | { |
715 | { |
628 | if (s_epipe_renew (&respipe)) |
716 | if (s_epipe_renew (&respipe)) |
629 | croak ("IO::AIO: unable to initialize result pipe"); |
717 | croak ("IO::AIO: unable to initialize result pipe"); |
630 | } |
718 | } |
631 | |
719 | |
632 | static void poll_wait (void) |
720 | static void |
|
|
721 | poll_wait (void) |
633 | { |
722 | { |
634 | while (eio_nreqs ()) |
723 | while (eio_nreqs ()) |
635 | { |
724 | { |
636 | int size; |
725 | int size; |
637 | |
726 | |
… | |
… | |
646 | |
735 | |
647 | s_epipe_wait (&respipe); |
736 | s_epipe_wait (&respipe); |
648 | } |
737 | } |
649 | } |
738 | } |
650 | |
739 | |
651 | static int poll_cb (void) |
740 | static int |
|
|
741 | poll_cb (void) |
652 | { |
742 | { |
653 | for (;;) |
743 | for (;;) |
654 | { |
744 | { |
655 | int res = eio_poll (); |
745 | int res = eio_poll (); |
656 | |
746 | |
… | |
… | |
662 | |
752 | |
663 | poll_wait (); |
753 | poll_wait (); |
664 | } |
754 | } |
665 | } |
755 | } |
666 | |
756 | |
667 | static void atfork_child (void) |
757 | static void ecb_cold |
|
|
758 | reinit (void) |
668 | { |
759 | { |
669 | create_respipe (); |
760 | create_respipe (); |
|
|
761 | |
|
|
762 | if (eio_init (want_poll, done_poll) < 0) |
|
|
763 | croak ("IO::AIO: unable to initialise eio library"); |
670 | } |
764 | } |
671 | |
765 | |
672 | /*****************************************************************************/ |
766 | /*****************************************************************************/ |
673 | |
767 | |
674 | #if !_POSIX_MAPPED_FILES |
768 | #if !_POSIX_MAPPED_FILES |
… | |
… | |
685 | # define MAP_FIXED 0 |
779 | # define MAP_FIXED 0 |
686 | #endif |
780 | #endif |
687 | |
781 | |
688 | #define MMAP_MAGIC PERL_MAGIC_ext |
782 | #define MMAP_MAGIC PERL_MAGIC_ext |
689 | |
783 | |
690 | static int |
784 | static int ecb_cold |
691 | mmap_free (pTHX_ SV *sv, MAGIC *mg) |
785 | mmap_free (pTHX_ SV *sv, MAGIC *mg) |
692 | { |
786 | { |
693 | int old_errno = errno; |
787 | int old_errno = errno; |
694 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
788 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
695 | errno = old_errno; |
789 | errno = old_errno; |
… | |
… | |
719 | { |
813 | { |
720 | SvGETMAGIC (cb_sv); |
814 | SvGETMAGIC (cb_sv); |
721 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
815 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
722 | } |
816 | } |
723 | |
817 | |
|
|
818 | static aio_req ecb_noinline |
|
|
819 | dreq (SV *callback) |
|
|
820 | { |
|
|
821 | SV *cb_cv; |
|
|
822 | aio_req req; |
|
|
823 | int req_pri = next_pri; |
|
|
824 | next_pri = EIO_PRI_DEFAULT; |
|
|
825 | |
|
|
826 | cb_cv = get_cb (callback); |
|
|
827 | |
|
|
828 | req = calloc (sizeof (*req), 1); |
|
|
829 | if (!req) |
|
|
830 | croak ("out of memory during eio_req allocation"); |
|
|
831 | |
|
|
832 | req->callback = SvREFCNT_inc (cb_cv); |
|
|
833 | req->pri = req_pri; |
|
|
834 | |
|
|
835 | return req; |
|
|
836 | } |
|
|
837 | |
724 | #define dREQ \ |
838 | #define dREQ \ |
725 | SV *cb_cv; \ |
839 | aio_req req = dreq (callback); \ |
726 | aio_req req; \ |
|
|
727 | int req_pri = next_pri; \ |
|
|
728 | next_pri = EIO_PRI_DEFAULT; \ |
|
|
729 | \ |
|
|
730 | cb_cv = get_cb (callback); \ |
|
|
731 | \ |
|
|
732 | Newz (0, req, 1, eio_req); \ |
|
|
733 | if (!req) \ |
|
|
734 | croak ("out of memory during eio_req allocation"); \ |
|
|
735 | \ |
|
|
736 | req->callback = SvREFCNT_inc (cb_cv); \ |
|
|
737 | req->pri = req_pri |
|
|
738 | |
840 | |
739 | #define REQ_SEND \ |
841 | #define REQ_SEND \ |
740 | PUTBACK; \ |
842 | PUTBACK; \ |
741 | req_submit (req); \ |
843 | req_submit (req); \ |
742 | SPAGAIN; \ |
844 | SPAGAIN; \ |
743 | \ |
845 | \ |
744 | if (GIMME_V != G_VOID) \ |
846 | if (GIMME_V != G_VOID) \ |
745 | XPUSHs (req_sv (req, aio_req_stash)); |
847 | XPUSHs (req_sv (req, aio_req_stash)); |
|
|
848 | |
|
|
849 | ecb_inline void |
|
|
850 | req_set_path (aio_req req, SV *path, SV **wdsv, SV **pathsv, eio_wd *wd, void **ptr) |
|
|
851 | { |
|
|
852 | if (expect_false (SvROK (path))) |
|
|
853 | { |
|
|
854 | SV *rv = SvRV (path); |
|
|
855 | SV *wdob; |
|
|
856 | |
|
|
857 | if (SvTYPE (rv) == SVt_PVAV && AvFILLp (rv) == 1) |
|
|
858 | { |
|
|
859 | path = AvARRAY (rv)[1]; |
|
|
860 | wdob = AvARRAY (rv)[0]; |
|
|
861 | |
|
|
862 | if (SvOK (wdob)) |
|
|
863 | { |
|
|
864 | *wd = SvAIO_WD (wdob); |
|
|
865 | *wdsv = SvREFCNT_inc_NN (SvRV (wdob)); |
|
|
866 | } |
|
|
867 | else |
|
|
868 | *wd = EIO_INVALID_WD; |
|
|
869 | } |
|
|
870 | else if (SvTYPE (rv) == SVt_PVMG && SvSTASH (rv) == aio_wd_stash) |
|
|
871 | { |
|
|
872 | *wd = (aio_wd)(long)SvIVX (rv); |
|
|
873 | *wdsv = SvREFCNT_inc_NN (rv); |
|
|
874 | *ptr = "."; |
|
|
875 | return; /* path set to "." */ |
|
|
876 | } |
|
|
877 | else |
|
|
878 | croak ("IO::AIO: pathname arguments must be specified as a string, an IO::AIO::WD object or a [IO::AIO::WD, path] pair"); |
|
|
879 | } |
|
|
880 | |
|
|
881 | *pathsv = newSVsv (path); |
|
|
882 | *ptr = SvPVbyte_nolen (*pathsv); |
|
|
883 | } |
|
|
884 | |
|
|
885 | static void ecb_noinline |
|
|
886 | req_set_path1 (aio_req req, SV *path) |
|
|
887 | { |
|
|
888 | req_set_path (req, path, &req->sv1, &req->sv3, &req->wd, &req->ptr1); |
|
|
889 | } |
|
|
890 | |
|
|
891 | static void ecb_noinline |
|
|
892 | req_set_fh_or_path (aio_req req, int type_path, int type_fh, SV *fh_or_path) |
|
|
893 | { |
|
|
894 | SV *rv = SvROK (fh_or_path) ? SvRV (fh_or_path) : fh_or_path; |
|
|
895 | |
|
|
896 | switch (SvTYPE (rv)) |
|
|
897 | { |
|
|
898 | case SVt_PVIO: |
|
|
899 | case SVt_PVLV: |
|
|
900 | case SVt_PVGV: |
|
|
901 | req->type = type_fh; |
|
|
902 | req->sv1 = newSVsv (fh_or_path); |
|
|
903 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
904 | break; |
|
|
905 | |
|
|
906 | default: |
|
|
907 | req->type = type_path; |
|
|
908 | req_set_path1 (req, fh_or_path); |
|
|
909 | break; |
|
|
910 | } |
|
|
911 | } |
|
|
912 | |
|
|
913 | XS(boot_IO__AIO) ecb_cold; |
746 | |
914 | |
747 | MODULE = IO::AIO PACKAGE = IO::AIO |
915 | MODULE = IO::AIO PACKAGE = IO::AIO |
748 | |
916 | |
749 | PROTOTYPES: ENABLE |
917 | PROTOTYPES: ENABLE |
750 | |
918 | |
… | |
… | |
765 | const_iv (O_CREAT) |
933 | const_iv (O_CREAT) |
766 | const_iv (O_TRUNC) |
934 | const_iv (O_TRUNC) |
767 | const_iv (O_EXCL) |
935 | const_iv (O_EXCL) |
768 | const_iv (O_APPEND) |
936 | const_iv (O_APPEND) |
769 | |
937 | |
|
|
938 | const_iv (O_ASYNC) |
|
|
939 | const_iv (O_DIRECT) |
|
|
940 | const_iv (O_NOATIME) |
|
|
941 | |
|
|
942 | const_iv (O_CLOEXEC) |
|
|
943 | const_iv (O_NOCTTY) |
|
|
944 | const_iv (O_NOFOLLOW) |
|
|
945 | const_iv (O_NONBLOCK) |
|
|
946 | const_iv (O_EXEC) |
|
|
947 | const_iv (O_SEARCH) |
|
|
948 | const_iv (O_DIRECTORY) |
|
|
949 | const_iv (O_DSYNC) |
|
|
950 | const_iv (O_RSYNC) |
|
|
951 | const_iv (O_SYNC) |
|
|
952 | const_iv (O_TTY_INIT) |
|
|
953 | |
770 | const_iv (S_IFIFO) |
954 | const_iv (S_IFIFO) |
771 | const_iv (S_IFCHR) |
955 | const_iv (S_IFCHR) |
772 | const_iv (S_IFBLK) |
956 | const_iv (S_IFBLK) |
773 | const_iv (S_IFLNK) |
957 | const_iv (S_IFLNK) |
774 | const_iv (S_IFREG) |
958 | const_iv (S_IFREG) |
… | |
… | |
831 | |
1015 | |
832 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
1016 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
833 | const_eio (SYNC_FILE_RANGE_WRITE) |
1017 | const_eio (SYNC_FILE_RANGE_WRITE) |
834 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
1018 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
835 | |
1019 | |
|
|
1020 | const_eio (FALLOC_FL_KEEP_SIZE) |
|
|
1021 | |
836 | const_eio (READDIR_DENTS) |
1022 | const_eio (READDIR_DENTS) |
837 | const_eio (READDIR_DIRS_FIRST) |
1023 | const_eio (READDIR_DIRS_FIRST) |
838 | const_eio (READDIR_STAT_ORDER) |
1024 | const_eio (READDIR_STAT_ORDER) |
839 | const_eio (READDIR_FOUND_UNKNOWN) |
1025 | const_eio (READDIR_FOUND_UNKNOWN) |
840 | |
1026 | |
… | |
… | |
850 | }; |
1036 | }; |
851 | |
1037 | |
852 | aio_stash = gv_stashpv ("IO::AIO" , 1); |
1038 | aio_stash = gv_stashpv ("IO::AIO" , 1); |
853 | aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); |
1039 | aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); |
854 | aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); |
1040 | aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); |
|
|
1041 | aio_wd_stash = gv_stashpv ("IO::AIO::WD" , 1); |
855 | |
1042 | |
856 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1043 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
857 | newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv)); |
1044 | newCONSTSUB (aio_stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
858 | |
1045 | |
859 | newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); |
1046 | newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); |
860 | |
1047 | |
861 | create_respipe (); |
1048 | reinit (); |
862 | |
|
|
863 | if (eio_init (want_poll, done_poll) < 0) |
|
|
864 | croak ("IO::AIO: unable to initialise eio library"); |
|
|
865 | |
|
|
866 | /* atfork child called in fifo order, so before eio's handler */ |
|
|
867 | X_THREAD_ATFORK (0, 0, atfork_child); |
|
|
868 | } |
1049 | } |
|
|
1050 | |
|
|
1051 | void |
|
|
1052 | reinit () |
|
|
1053 | PROTOTYPE: |
869 | |
1054 | |
870 | void |
1055 | void |
871 | max_poll_reqs (unsigned int nreqs) |
1056 | max_poll_reqs (unsigned int nreqs) |
872 | PROTOTYPE: $ |
1057 | PROTOTYPE: $ |
873 | CODE: |
1058 | CODE: |
… | |
… | |
908 | PROTOTYPE: $ |
1093 | PROTOTYPE: $ |
909 | CODE: |
1094 | CODE: |
910 | max_outstanding = maxreqs; |
1095 | max_outstanding = maxreqs; |
911 | |
1096 | |
912 | void |
1097 | void |
|
|
1098 | aio_wd (SV8 *pathname, SV *callback=&PL_sv_undef) |
|
|
1099 | PPCODE: |
|
|
1100 | { |
|
|
1101 | dREQ; |
|
|
1102 | |
|
|
1103 | req->type = EIO_WD_OPEN; |
|
|
1104 | req_set_path1 (req, pathname); |
|
|
1105 | |
|
|
1106 | REQ_SEND; |
|
|
1107 | } |
|
|
1108 | |
|
|
1109 | void |
913 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
1110 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
914 | PPCODE: |
1111 | PPCODE: |
915 | { |
1112 | { |
916 | dREQ; |
1113 | dREQ; |
917 | |
1114 | |
918 | req->type = EIO_OPEN; |
1115 | req->type = EIO_OPEN; |
919 | req->sv1 = newSVsv (pathname); |
1116 | req_set_path1 (req, pathname); |
920 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
921 | req->int1 = flags; |
1117 | req->int1 = flags; |
922 | req->int2 = mode; |
1118 | req->int2 = mode; |
923 | |
1119 | |
924 | REQ_SEND; |
1120 | REQ_SEND; |
925 | } |
1121 | } |
… | |
… | |
927 | void |
1123 | void |
928 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
1124 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
929 | ALIAS: |
1125 | ALIAS: |
930 | aio_fsync = EIO_FSYNC |
1126 | aio_fsync = EIO_FSYNC |
931 | aio_fdatasync = EIO_FDATASYNC |
1127 | aio_fdatasync = EIO_FDATASYNC |
|
|
1128 | aio_syncfs = EIO_SYNCFS |
932 | PPCODE: |
1129 | PPCODE: |
933 | { |
1130 | { |
934 | int fd = s_fileno_croak (fh, 0); |
1131 | int fd = s_fileno_croak (fh, 0); |
935 | dREQ; |
1132 | dREQ; |
936 | |
1133 | |
… | |
… | |
957 | |
1154 | |
958 | REQ_SEND (req); |
1155 | REQ_SEND (req); |
959 | } |
1156 | } |
960 | |
1157 | |
961 | void |
1158 | void |
|
|
1159 | aio_fallocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef) |
|
|
1160 | PPCODE: |
|
|
1161 | { |
|
|
1162 | int fd = s_fileno_croak (fh, 0); |
|
|
1163 | dREQ; |
|
|
1164 | |
|
|
1165 | req->type = EIO_FALLOCATE; |
|
|
1166 | req->sv1 = newSVsv (fh); |
|
|
1167 | req->int1 = fd; |
|
|
1168 | req->int2 = mode; |
|
|
1169 | req->offs = offset; |
|
|
1170 | req->size = len; |
|
|
1171 | |
|
|
1172 | REQ_SEND (req); |
|
|
1173 | } |
|
|
1174 | |
|
|
1175 | void |
962 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
1176 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
963 | PPCODE: |
1177 | PPCODE: |
964 | { |
1178 | { |
965 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
1179 | static int close_fd = -1; /* dummy fd to close fds via dup2 */ |
966 | int fd = s_fileno_croak (fh, 0); |
1180 | int fd = s_fileno_croak (fh, 0); |
967 | dREQ; |
1181 | dREQ; |
968 | |
1182 | |
969 | if (close_pipe < 0) |
1183 | if (expect_false (close_fd < 0)) |
970 | { |
1184 | { |
971 | int pipefd [2]; |
1185 | int pipefd [2]; |
972 | |
1186 | |
|
|
1187 | if ( |
|
|
1188 | #ifdef _WIN32 |
|
|
1189 | _pipe (pipefd, 1, _O_BINARY) < 0 |
|
|
1190 | #else |
973 | if (pipe (pipefd) < 0 |
1191 | pipe (pipefd) < 0 |
974 | || close (pipefd [1]) < 0 |
|
|
975 | || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0) |
1192 | || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0 |
|
|
1193 | #endif |
|
|
1194 | || close (pipefd [1]) < 0 |
|
|
1195 | ) |
976 | abort (); /*D*/ |
1196 | abort (); /*D*/ |
977 | |
1197 | |
978 | close_pipe = pipefd [0]; |
1198 | close_fd = pipefd [0]; |
979 | } |
1199 | } |
980 | |
1200 | |
981 | req->type = EIO_DUP2; |
1201 | req->type = EIO_DUP2; |
982 | req->int1 = close_pipe; |
1202 | req->int1 = close_fd; |
983 | req->sv2 = newSVsv (fh); |
1203 | req->sv2 = newSVsv (fh); |
984 | req->int2 = fd; |
1204 | req->int2 = fd; |
985 | |
1205 | |
986 | REQ_SEND (req); |
1206 | REQ_SEND (req); |
987 | } |
1207 | } |
… | |
… | |
1038 | REQ_SEND; |
1258 | REQ_SEND; |
1039 | } |
1259 | } |
1040 | } |
1260 | } |
1041 | |
1261 | |
1042 | void |
1262 | void |
1043 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
1263 | aio_readlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
|
|
1264 | ALIAS: |
|
|
1265 | aio_readlink = EIO_READLINK |
|
|
1266 | aio_realpath = EIO_REALPATH |
1044 | PPCODE: |
1267 | PPCODE: |
1045 | { |
1268 | { |
1046 | SV *data; |
|
|
1047 | dREQ; |
1269 | dREQ; |
1048 | |
1270 | |
1049 | req->type = EIO_READLINK; |
1271 | req->type = ix; |
1050 | req->sv1 = newSVsv (path); |
1272 | req_set_path1 (req, pathname); |
1051 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1052 | |
1273 | |
1053 | REQ_SEND; |
1274 | REQ_SEND; |
1054 | } |
1275 | } |
1055 | |
1276 | |
1056 | void |
1277 | void |
… | |
… | |
1096 | aio_statvfs = EIO_STATVFS |
1317 | aio_statvfs = EIO_STATVFS |
1097 | PPCODE: |
1318 | PPCODE: |
1098 | { |
1319 | { |
1099 | dREQ; |
1320 | dREQ; |
1100 | |
1321 | |
1101 | req->sv1 = newSVsv (fh_or_path); |
1322 | req_set_fh_or_path (req, ix, ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT, fh_or_path); |
1102 | |
|
|
1103 | if (SvPOK (req->sv1)) |
|
|
1104 | { |
|
|
1105 | req->type = ix; |
|
|
1106 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1107 | } |
|
|
1108 | else |
|
|
1109 | { |
|
|
1110 | req->type = ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT; |
|
|
1111 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1112 | } |
|
|
1113 | |
1323 | |
1114 | REQ_SEND; |
1324 | REQ_SEND; |
1115 | } |
1325 | } |
1116 | |
1326 | |
1117 | UV |
1327 | UV |
… | |
… | |
1136 | { |
1346 | { |
1137 | dREQ; |
1347 | dREQ; |
1138 | |
1348 | |
1139 | req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; |
1349 | req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; |
1140 | req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; |
1350 | req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; |
1141 | req->sv1 = newSVsv (fh_or_path); |
1351 | req_set_fh_or_path (req, EIO_UTIME, EIO_FUTIME, fh_or_path); |
1142 | |
|
|
1143 | if (SvPOK (req->sv1)) |
|
|
1144 | { |
|
|
1145 | req->type = EIO_UTIME; |
|
|
1146 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1147 | } |
|
|
1148 | else |
|
|
1149 | { |
|
|
1150 | req->type = EIO_FUTIME; |
|
|
1151 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1152 | } |
|
|
1153 | |
1352 | |
1154 | REQ_SEND; |
1353 | REQ_SEND; |
1155 | } |
1354 | } |
1156 | |
1355 | |
1157 | void |
1356 | void |
1158 | aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef) |
1357 | aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef) |
1159 | PPCODE: |
1358 | PPCODE: |
1160 | { |
1359 | { |
1161 | dREQ; |
1360 | dREQ; |
1162 | |
1361 | |
1163 | req->sv1 = newSVsv (fh_or_path); |
|
|
1164 | req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
1362 | req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
1165 | |
1363 | req_set_fh_or_path (req, EIO_TRUNCATE, EIO_FTRUNCATE, fh_or_path); |
1166 | if (SvPOK (req->sv1)) |
|
|
1167 | { |
|
|
1168 | req->type = EIO_TRUNCATE; |
|
|
1169 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1170 | } |
|
|
1171 | else |
|
|
1172 | { |
|
|
1173 | req->type = EIO_FTRUNCATE; |
|
|
1174 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1175 | } |
|
|
1176 | |
1364 | |
1177 | REQ_SEND; |
1365 | REQ_SEND; |
1178 | } |
1366 | } |
1179 | |
1367 | |
1180 | void |
1368 | void |
1181 | aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) |
1369 | aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) |
1182 | ALIAS: |
|
|
1183 | aio_chmod = EIO_CHMOD |
|
|
1184 | aio_mkdir = EIO_MKDIR |
|
|
1185 | PPCODE: |
1370 | PPCODE: |
1186 | { |
1371 | { |
1187 | dREQ; |
1372 | dREQ; |
1188 | |
1373 | |
1189 | req->int2 = mode; |
1374 | req->int2 = mode; |
1190 | req->sv1 = newSVsv (fh_or_path); |
1375 | req_set_fh_or_path (req, EIO_CHMOD, EIO_FCHMOD, fh_or_path); |
1191 | |
|
|
1192 | if (SvPOK (req->sv1)) |
|
|
1193 | { |
|
|
1194 | req->type = ix; |
|
|
1195 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1196 | } |
|
|
1197 | else |
|
|
1198 | { |
|
|
1199 | req->type = EIO_FCHMOD; |
|
|
1200 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1201 | } |
|
|
1202 | |
1376 | |
1203 | REQ_SEND; |
1377 | REQ_SEND; |
1204 | } |
1378 | } |
1205 | |
1379 | |
1206 | void |
1380 | void |
… | |
… | |
1209 | { |
1383 | { |
1210 | dREQ; |
1384 | dREQ; |
1211 | |
1385 | |
1212 | req->int2 = SvOK (uid) ? SvIV (uid) : -1; |
1386 | req->int2 = SvOK (uid) ? SvIV (uid) : -1; |
1213 | req->int3 = SvOK (gid) ? SvIV (gid) : -1; |
1387 | req->int3 = SvOK (gid) ? SvIV (gid) : -1; |
1214 | req->sv1 = newSVsv (fh_or_path); |
1388 | req_set_fh_or_path (req, EIO_CHOWN, EIO_FCHOWN, fh_or_path); |
1215 | |
|
|
1216 | if (SvPOK (req->sv1)) |
|
|
1217 | { |
|
|
1218 | req->type = EIO_CHOWN; |
|
|
1219 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1220 | } |
|
|
1221 | else |
|
|
1222 | { |
|
|
1223 | req->type = EIO_FCHOWN; |
|
|
1224 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
1225 | } |
|
|
1226 | |
1389 | |
1227 | REQ_SEND; |
1390 | REQ_SEND; |
1228 | } |
1391 | } |
1229 | |
1392 | |
1230 | void |
1393 | void |
… | |
… | |
1232 | PPCODE: |
1395 | PPCODE: |
1233 | { |
1396 | { |
1234 | dREQ; |
1397 | dREQ; |
1235 | |
1398 | |
1236 | req->type = EIO_READDIR; |
1399 | req->type = EIO_READDIR; |
1237 | req->sv1 = newSVsv (pathname); |
|
|
1238 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1239 | req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1; |
1400 | req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1; |
1240 | |
1401 | |
1241 | if (flags & EIO_READDIR_DENTS) |
1402 | if (flags & EIO_READDIR_DENTS) |
1242 | req->int1 |= EIO_READDIR_CUSTOM2; |
1403 | req->int1 |= EIO_READDIR_CUSTOM2; |
1243 | |
1404 | |
|
|
1405 | req_set_path1 (req, pathname); |
|
|
1406 | |
1244 | REQ_SEND; |
1407 | REQ_SEND; |
|
|
1408 | } |
|
|
1409 | |
|
|
1410 | void |
|
|
1411 | aio_mkdir (SV8 *pathname, int mode, SV *callback=&PL_sv_undef) |
|
|
1412 | PPCODE: |
|
|
1413 | { |
|
|
1414 | dREQ; |
|
|
1415 | |
|
|
1416 | req->type = EIO_MKDIR; |
|
|
1417 | req->int2 = mode; |
|
|
1418 | req_set_path1 (req, pathname); |
|
|
1419 | |
|
|
1420 | REQ_SEND; |
1245 | } |
1421 | } |
1246 | |
1422 | |
1247 | void |
1423 | void |
1248 | aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
1424 | aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
1249 | ALIAS: |
1425 | ALIAS: |
… | |
… | |
1253 | PPCODE: |
1429 | PPCODE: |
1254 | { |
1430 | { |
1255 | dREQ; |
1431 | dREQ; |
1256 | |
1432 | |
1257 | req->type = ix; |
1433 | req->type = ix; |
1258 | req->sv1 = newSVsv (pathname); |
1434 | req_set_path1 (req, pathname); |
1259 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1260 | |
1435 | |
1261 | REQ_SEND; |
1436 | REQ_SEND; |
1262 | } |
1437 | } |
1263 | |
1438 | |
1264 | void |
1439 | void |
… | |
… | |
1267 | aio_link = EIO_LINK |
1442 | aio_link = EIO_LINK |
1268 | aio_symlink = EIO_SYMLINK |
1443 | aio_symlink = EIO_SYMLINK |
1269 | aio_rename = EIO_RENAME |
1444 | aio_rename = EIO_RENAME |
1270 | PPCODE: |
1445 | PPCODE: |
1271 | { |
1446 | { |
|
|
1447 | eio_wd wd2 = 0; |
1272 | dREQ; |
1448 | dREQ; |
1273 | |
1449 | |
1274 | req->type = ix; |
1450 | req->type = ix; |
1275 | req->sv1 = newSVsv (oldpath); |
1451 | req_set_path1 (req, oldpath); |
1276 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1452 | req_set_path (req, newpath, &req->sv2, &req->sv4, &wd2, &req->ptr2); |
1277 | req->sv2 = newSVsv (newpath); |
1453 | req->int3 = (long)wd2; |
1278 | req->ptr2 = SvPVbyte_nolen (req->sv2); |
|
|
1279 | |
1454 | |
1280 | REQ_SEND; |
1455 | REQ_SEND; |
1281 | } |
1456 | } |
1282 | |
1457 | |
1283 | void |
1458 | void |
… | |
… | |
1285 | PPCODE: |
1460 | PPCODE: |
1286 | { |
1461 | { |
1287 | dREQ; |
1462 | dREQ; |
1288 | |
1463 | |
1289 | req->type = EIO_MKNOD; |
1464 | req->type = EIO_MKNOD; |
1290 | req->sv1 = newSVsv (pathname); |
|
|
1291 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1292 | req->int2 = (mode_t)mode; |
1465 | req->int2 = (mode_t)mode; |
1293 | req->offs = dev; |
1466 | req->offs = dev; |
|
|
1467 | req_set_path1 (req, pathname); |
1294 | |
1468 | |
1295 | REQ_SEND; |
1469 | REQ_SEND; |
1296 | } |
1470 | } |
1297 | |
1471 | |
1298 | void |
1472 | void |
… | |
… | |
1498 | CODE: |
1672 | CODE: |
1499 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1673 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1500 | OUTPUT: |
1674 | OUTPUT: |
1501 | RETVAL |
1675 | RETVAL |
1502 | |
1676 | |
1503 | ssize_t |
1677 | IV |
1504 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1678 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1505 | CODE: |
1679 | CODE: |
1506 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1680 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1507 | OUTPUT: |
1681 | OUTPUT: |
1508 | RETVAL |
1682 | RETVAL |
… | |
… | |
1620 | SvREFCNT_dec (on_next_submit); |
1794 | SvREFCNT_dec (on_next_submit); |
1621 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1795 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1622 | |
1796 | |
1623 | PROTOTYPES: DISABLE |
1797 | PROTOTYPES: DISABLE |
1624 | |
1798 | |
|
|
1799 | MODULE = IO::AIO PACKAGE = IO::AIO::WD |
|
|
1800 | |
|
|
1801 | BOOT: |
|
|
1802 | { |
|
|
1803 | newCONSTSUB (aio_stash, "CWD" , newSVaio_wd (EIO_CWD )); |
|
|
1804 | newCONSTSUB (aio_stash, "INVALID_WD", newSVaio_wd (EIO_INVALID_WD)); |
|
|
1805 | } |
|
|
1806 | |
|
|
1807 | void |
|
|
1808 | DESTROY (SV *self) |
|
|
1809 | CODE: |
|
|
1810 | { |
|
|
1811 | aio_wd wd = SvAIO_WD (self); |
|
|
1812 | #if HAVE_AT |
|
|
1813 | { |
|
|
1814 | SV *callback = &PL_sv_undef; |
|
|
1815 | dREQ; /* clobbers next_pri :/ */ |
|
|
1816 | next_pri = req->pri; /* restore next_pri */ |
|
|
1817 | req->pri = EIO_PRI_MAX; /* better use max. priority to conserve fds */ |
|
|
1818 | req->type = EIO_WD_CLOSE; |
|
|
1819 | req->wd = wd; |
|
|
1820 | REQ_SEND; |
|
|
1821 | } |
|
|
1822 | #else |
|
|
1823 | eio_wd_close_sync (wd); |
|
|
1824 | #endif |
|
|
1825 | } |
|
|
1826 | |
1625 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
1827 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
1626 | |
1828 | |
1627 | void |
1829 | void |
1628 | cancel (aio_req_ornot req) |
1830 | cancel (aio_req_ornot req) |
1629 | CODE: |
1831 | CODE: |