… | |
… | |
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> |
|
|
16 | #include <sys/statvfs.h> |
14 | #include <limits.h> |
17 | #include <limits.h> |
15 | #include <fcntl.h> |
18 | #include <fcntl.h> |
16 | #include <sched.h> |
19 | #include <sched.h> |
|
|
20 | |
|
|
21 | #if _POSIX_MEMLOCK |
|
|
22 | # include <sys/mman.h> |
|
|
23 | #endif |
17 | |
24 | |
18 | /* perl namespace pollution */ |
25 | /* perl namespace pollution */ |
19 | #undef VERSION |
26 | #undef VERSION |
20 | |
27 | |
21 | #ifdef _WIN32 |
28 | #ifdef _WIN32 |
… | |
… | |
97 | #define expect_false(expr) expect ((expr) != 0, 0) |
104 | #define expect_false(expr) expect ((expr) != 0, 0) |
98 | #define expect_true(expr) expect ((expr) != 0, 1) |
105 | #define expect_true(expr) expect ((expr) != 0, 1) |
99 | |
106 | |
100 | /*****************************************************************************/ |
107 | /*****************************************************************************/ |
101 | |
108 | |
102 | static HV *stash; |
|
|
103 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
109 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
104 | typedef int aio_rfd; /* read file desriptor */ |
110 | typedef int aio_rfd; /* read file desriptor */ |
105 | typedef int aio_wfd; /* write file descriptor */ |
111 | typedef int aio_wfd; /* write file descriptor */ |
106 | |
112 | |
107 | #define AIO_REQ_KLASS "IO::AIO::REQ" |
113 | static HV *aio_stash, *aio_req_stash, *aio_grp_stash; |
108 | #define AIO_GRP_KLASS "IO::AIO::GRP" |
|
|
109 | |
114 | |
110 | #define EIO_REQ_MEMBERS \ |
115 | #define EIO_REQ_MEMBERS \ |
111 | SV *callback; \ |
116 | SV *callback; \ |
112 | SV *sv1, *sv2; \ |
117 | SV *sv1, *sv2; \ |
113 | STRLEN stroffset; \ |
118 | STRLEN stroffset; \ |
… | |
… | |
117 | |
122 | |
118 | #include "libeio/eio.h" |
123 | #include "libeio/eio.h" |
119 | |
124 | |
120 | #ifndef POSIX_FADV_NORMAL |
125 | #ifndef POSIX_FADV_NORMAL |
121 | # define POSIX_FADV_NORMAL 0 |
126 | # define POSIX_FADV_NORMAL 0 |
|
|
127 | # define NO_FADVISE 1 |
122 | #endif |
128 | #endif |
123 | |
|
|
124 | #ifndef POSIX_FADV_SEQUENTIAL |
129 | #ifndef POSIX_FADV_SEQUENTIAL |
125 | # define POSIX_FADV_SEQUENTIAL 0 |
130 | # define POSIX_FADV_SEQUENTIAL 0 |
126 | #endif |
131 | #endif |
127 | |
|
|
128 | #ifndef POSIX_FADV_RANDOM |
132 | #ifndef POSIX_FADV_RANDOM |
129 | # define POSIX_FADV_RANDOM 0 |
133 | # define POSIX_FADV_RANDOM 0 |
130 | #endif |
134 | #endif |
131 | |
|
|
132 | #ifndef POSIX_FADV_NOREUSE |
135 | #ifndef POSIX_FADV_NOREUSE |
133 | # define POSIX_FADV_NOREUSE 0 |
136 | # define POSIX_FADV_NOREUSE 0 |
134 | #endif |
137 | #endif |
135 | |
|
|
136 | #ifndef POSIX_FADV_WILLNEED |
138 | #ifndef POSIX_FADV_WILLNEED |
137 | # define POSIX_FADV_WILLNEED 0 |
139 | # define POSIX_FADV_WILLNEED 0 |
138 | #endif |
140 | #endif |
139 | |
|
|
140 | #ifndef POSIX_FADV_DONTNEED |
141 | #ifndef POSIX_FADV_DONTNEED |
141 | # define POSIX_FADV_DONTNEED 0 |
142 | # define POSIX_FADV_DONTNEED 0 |
|
|
143 | #endif |
|
|
144 | |
|
|
145 | #ifndef ST_NODEV |
|
|
146 | # define ST_NODEV 0 |
|
|
147 | #endif |
|
|
148 | #ifndef ST_NOEXEC |
|
|
149 | # define ST_NOEXEC 0 |
|
|
150 | #endif |
|
|
151 | #ifndef ST_SYNCHRONOUS |
|
|
152 | # define ST_SYNCHRONOUS 0 |
|
|
153 | #endif |
|
|
154 | #ifndef ST_MANDLOCK |
|
|
155 | # define ST_MANDLOCK 0 |
|
|
156 | #endif |
|
|
157 | #ifndef ST_WRITE |
|
|
158 | # define ST_WRITE 0 |
|
|
159 | #endif |
|
|
160 | #ifndef ST_APPEND |
|
|
161 | # define ST_APPEND 0 |
|
|
162 | #endif |
|
|
163 | #ifndef ST_IMMUTABLE |
|
|
164 | # define ST_IMMUTABLE 0 |
|
|
165 | #endif |
|
|
166 | #ifndef ST_NOATIME |
|
|
167 | # define ST_NOATIME 0 |
|
|
168 | #endif |
|
|
169 | #ifndef ST_NODIRATIME |
|
|
170 | # define ST_NODIRATIME 0 |
|
|
171 | #endif |
|
|
172 | #ifndef ST_RELATIME |
|
|
173 | # define ST_RELATIME 0 |
|
|
174 | #endif |
|
|
175 | |
|
|
176 | #ifndef MCL_CURRENT |
|
|
177 | # define MCL_CURRENT 0 |
|
|
178 | #endif |
|
|
179 | #ifndef MCL_FUTURE |
|
|
180 | # define MCL_FUTURE 0 |
142 | #endif |
181 | #endif |
143 | |
182 | |
144 | static int req_invoke (eio_req *req); |
183 | static int req_invoke (eio_req *req); |
145 | #define EIO_FINISH(req) req_invoke (req) |
184 | #define EIO_FINISH(req) req_invoke (req) |
146 | static void req_destroy (eio_req *grp); |
185 | static void req_destroy (eio_req *grp); |
… | |
… | |
157 | |
196 | |
158 | static SV *on_next_submit; |
197 | static SV *on_next_submit; |
159 | static int next_pri = EIO_PRI_DEFAULT; |
198 | static int next_pri = EIO_PRI_DEFAULT; |
160 | static int max_outstanding; |
199 | static int max_outstanding; |
161 | |
200 | |
162 | static int respipe_osf [2], respipe [2] = { -1, -1 }; |
201 | static s_epipe respipe; |
163 | |
202 | |
164 | static void req_destroy (aio_req req); |
203 | static void req_destroy (aio_req req); |
165 | static void req_cancel (aio_req req); |
204 | static void req_cancel (aio_req req); |
166 | |
205 | |
167 | static void want_poll (void) |
206 | static void want_poll (void) |
168 | { |
207 | { |
169 | /* write a dummy byte to the pipe so fh becomes ready */ |
208 | /* write a dummy byte to the pipe so fh becomes ready */ |
170 | respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1); |
209 | s_epipe_signal (&respipe); |
171 | } |
210 | } |
172 | |
211 | |
173 | static void done_poll (void) |
212 | static void done_poll (void) |
174 | { |
213 | { |
175 | /* read any signals sent by the worker threads */ |
214 | /* read any signals sent by the worker threads */ |
176 | char buf [4]; |
215 | s_epipe_drain (&respipe); |
177 | while (respipe_read (respipe [0], buf, 4) == 4) |
|
|
178 | ; |
|
|
179 | } |
216 | } |
180 | |
217 | |
181 | /* must be called at most once */ |
218 | /* must be called at most once */ |
182 | static SV *req_sv (aio_req req, const char *klass) |
219 | static SV *req_sv (aio_req req, HV *stash) |
183 | { |
220 | { |
184 | if (!req->self) |
221 | if (!req->self) |
185 | { |
222 | { |
186 | req->self = (SV *)newHV (); |
223 | req->self = (SV *)newHV (); |
187 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
224 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
188 | } |
225 | } |
189 | |
226 | |
190 | return sv_2mortal (sv_bless (newRV_inc (req->self), gv_stashpv (klass, 1))); |
227 | return sv_2mortal (sv_bless (newRV_inc (req->self), stash)); |
191 | } |
228 | } |
192 | |
229 | |
193 | static aio_req SvAIO_REQ (SV *sv) |
230 | static aio_req SvAIO_REQ (SV *sv) |
194 | { |
231 | { |
195 | MAGIC *mg; |
232 | MAGIC *mg; |
196 | |
233 | |
197 | if (!sv_derived_from (sv, AIO_REQ_KLASS) || !SvROK (sv)) |
234 | if (!SvROK (sv) |
|
|
235 | || (SvSTASH (SvRV (sv)) != aio_grp_stash |
|
|
236 | && SvSTASH (SvRV (sv)) != aio_req_stash |
|
|
237 | && !sv_derived_from (sv, "IO::AIO::REQ"))) |
198 | croak ("object of class " AIO_REQ_KLASS " expected"); |
238 | croak ("object of class IO::AIO::REQ expected"); |
199 | |
239 | |
200 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
240 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
201 | |
241 | |
202 | return mg ? (aio_req)mg->mg_ptr : 0; |
242 | return mg ? (aio_req)mg->mg_ptr : 0; |
203 | } |
243 | } |
… | |
… | |
209 | dSP; |
249 | dSP; |
210 | |
250 | |
211 | ENTER; |
251 | ENTER; |
212 | SAVETMPS; |
252 | SAVETMPS; |
213 | PUSHMARK (SP); |
253 | PUSHMARK (SP); |
214 | XPUSHs (req_sv (grp, AIO_GRP_KLASS)); |
254 | XPUSHs (req_sv (grp, aio_grp_stash)); |
215 | PUTBACK; |
255 | PUTBACK; |
216 | call_sv (grp->sv2, G_VOID | G_EVAL | G_KEEPERR); |
256 | call_sv (grp->sv2, G_VOID | G_EVAL | G_KEEPERR); |
217 | SPAGAIN; |
257 | SPAGAIN; |
218 | FREETMPS; |
258 | FREETMPS; |
219 | LEAVE; |
259 | LEAVE; |
… | |
… | |
325 | int flags = req->int1 & (O_RDONLY | O_WRONLY | O_RDWR); |
365 | int flags = req->int1 & (O_RDONLY | O_WRONLY | O_RDWR); |
326 | char sym [64]; |
366 | char sym [64]; |
327 | int symlen; |
367 | int symlen; |
328 | |
368 | |
329 | symlen = snprintf (sym, sizeof (sym), "fd#%d", (int)req->result); |
369 | symlen = snprintf (sym, sizeof (sym), "fd#%d", (int)req->result); |
330 | gv_init (gv, stash, sym, symlen, 0); |
370 | gv_init (gv, aio_stash, sym, symlen, 0); |
331 | |
371 | |
332 | symlen = snprintf ( |
372 | symlen = snprintf ( |
333 | sym, |
373 | sym, |
334 | sizeof (sym), |
374 | sizeof (sym), |
335 | "%s&=%d", |
375 | "%s&=%d", |
… | |
… | |
341 | fh = (SV *)gv; |
381 | fh = (SV *)gv; |
342 | } |
382 | } |
343 | |
383 | |
344 | PUSHs (fh); |
384 | PUSHs (fh); |
345 | } |
385 | } |
|
|
386 | break; |
|
|
387 | |
|
|
388 | case EIO_STATVFS: |
|
|
389 | case EIO_FSTATVFS: |
|
|
390 | { |
|
|
391 | SV *rv = &PL_sv_undef; |
|
|
392 | |
|
|
393 | if (req->result >= 0) |
|
|
394 | { |
|
|
395 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
|
|
396 | HV *hv = newHV (); |
|
|
397 | |
|
|
398 | rv = sv_2mortal (newRV_noinc ((SV *)hv)); |
|
|
399 | |
|
|
400 | hv_store (hv, "bsize" , sizeof ("bsize" ) - 1, newSVval64 (f->f_bsize ), 0); |
|
|
401 | hv_store (hv, "frsize" , sizeof ("frsize" ) - 1, newSVval64 (f->f_frsize ), 0); |
|
|
402 | hv_store (hv, "blocks" , sizeof ("blocks" ) - 1, newSVval64 (f->f_blocks ), 0); |
|
|
403 | hv_store (hv, "bfree" , sizeof ("bfree" ) - 1, newSVval64 (f->f_bfree ), 0); |
|
|
404 | hv_store (hv, "bavail" , sizeof ("bavail" ) - 1, newSVval64 (f->f_bavail ), 0); |
|
|
405 | hv_store (hv, "files" , sizeof ("files" ) - 1, newSVval64 (f->f_files ), 0); |
|
|
406 | hv_store (hv, "ffree" , sizeof ("ffree" ) - 1, newSVval64 (f->f_ffree ), 0); |
|
|
407 | hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); |
|
|
408 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); |
|
|
409 | hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); |
|
|
410 | hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); |
|
|
411 | } |
|
|
412 | |
|
|
413 | PUSHs (rv); |
|
|
414 | } |
|
|
415 | |
346 | break; |
416 | break; |
347 | |
417 | |
348 | case EIO_GROUP: |
418 | case EIO_GROUP: |
349 | req->int1 = 2; /* mark group as finished */ |
419 | req->int1 = 2; /* mark group as finished */ |
350 | |
420 | |
… | |
… | |
438 | grp->sv2 = 0; |
508 | grp->sv2 = 0; |
439 | |
509 | |
440 | eio_grp_cancel (grp); |
510 | eio_grp_cancel (grp); |
441 | } |
511 | } |
442 | |
512 | |
443 | #ifdef USE_SOCKETS_AS_HANDLES |
|
|
444 | # define TO_SOCKET(x) (win32_get_osfhandle (x)) |
|
|
445 | #else |
|
|
446 | # define TO_SOCKET(x) (x) |
|
|
447 | #endif |
|
|
448 | |
|
|
449 | static void |
513 | static void |
450 | create_respipe (void) |
514 | create_respipe (void) |
451 | { |
515 | { |
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)) |
516 | if (s_epipe_renew (&respipe)) |
461 | #endif |
|
|
462 | croak ("unable to initialize result pipe"); |
517 | croak ("IO::AIO: 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 | } |
518 | } |
486 | |
519 | |
487 | static void poll_wait (void) |
520 | static void poll_wait (void) |
488 | { |
521 | { |
489 | fd_set rfd; |
|
|
490 | |
|
|
491 | while (eio_nreqs ()) |
522 | while (eio_nreqs ()) |
492 | { |
523 | { |
493 | int size; |
524 | int size; |
494 | |
525 | |
495 | X_LOCK (reslock); |
526 | X_LOCK (reslock); |
… | |
… | |
499 | if (size) |
530 | if (size) |
500 | return; |
531 | return; |
501 | |
532 | |
502 | etp_maybe_start_thread (); |
533 | etp_maybe_start_thread (); |
503 | |
534 | |
504 | FD_ZERO (&rfd); |
535 | s_epipe_wait (&respipe); |
505 | FD_SET (respipe [0], &rfd); |
|
|
506 | |
|
|
507 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
|
|
508 | } |
536 | } |
509 | } |
537 | } |
510 | |
538 | |
511 | static int poll_cb (void) |
539 | static int poll_cb (void) |
512 | { |
540 | { |
… | |
… | |
530 | } |
558 | } |
531 | |
559 | |
532 | static SV * |
560 | static SV * |
533 | get_cb (SV *cb_sv) |
561 | get_cb (SV *cb_sv) |
534 | { |
562 | { |
535 | HV *st; |
563 | SvGETMAGIC (cb_sv); |
536 | GV *gvp; |
564 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
537 | CV *cv; |
|
|
538 | |
|
|
539 | if (!SvOK (cb_sv)) |
|
|
540 | return 0; |
|
|
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 | } |
565 | } |
549 | |
566 | |
550 | #define dREQ \ |
567 | #define dREQ \ |
551 | SV *cb_cv; \ |
568 | SV *cb_cv; \ |
552 | aio_req req; \ |
569 | aio_req req; \ |
… | |
… | |
566 | PUTBACK; \ |
583 | PUTBACK; \ |
567 | req_submit (req); \ |
584 | req_submit (req); \ |
568 | SPAGAIN; \ |
585 | SPAGAIN; \ |
569 | \ |
586 | \ |
570 | if (GIMME_V != G_VOID) \ |
587 | if (GIMME_V != G_VOID) \ |
571 | XPUSHs (req_sv (req, AIO_REQ_KLASS)); |
588 | XPUSHs (req_sv (req, aio_req_stash)); |
572 | |
|
|
573 | static int |
|
|
574 | extract_fd (SV *fh, int wr) |
|
|
575 | { |
|
|
576 | int fd = PerlIO_fileno (wr ? IoOFP (sv_2io (fh)) : IoIFP (sv_2io (fh))); |
|
|
577 | |
|
|
578 | if (fd < 0) |
|
|
579 | croak ("illegal fh argument, either not an OS file or read/write mode mismatch"); |
|
|
580 | |
|
|
581 | return fd; |
|
|
582 | } |
|
|
583 | |
589 | |
584 | MODULE = IO::AIO PACKAGE = IO::AIO |
590 | MODULE = IO::AIO PACKAGE = IO::AIO |
585 | |
591 | |
586 | PROTOTYPES: ENABLE |
592 | PROTOTYPES: ENABLE |
587 | |
593 | |
… | |
… | |
607 | const_iv (FADV_RANDOM , POSIX_FADV_RANDOM) |
613 | const_iv (FADV_RANDOM , POSIX_FADV_RANDOM) |
608 | const_iv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
614 | const_iv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
609 | const_iv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
615 | const_iv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
610 | const_iv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
616 | const_iv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
611 | |
617 | |
|
|
618 | const_iv (ST_RDONLY , ST_RDONLY) |
|
|
619 | const_iv (ST_NOSUID , ST_NOSUID) |
|
|
620 | const_iv (ST_NODEV , ST_NODEV) |
|
|
621 | const_iv (ST_NOEXEC , ST_NOEXEC) |
|
|
622 | const_iv (ST_SYNCHRONOUS , ST_SYNCHRONOUS) |
|
|
623 | const_iv (ST_MANDLOCK , ST_MANDLOCK) |
|
|
624 | const_iv (ST_WRITE , ST_WRITE) |
|
|
625 | const_iv (ST_APPEND , ST_APPEND) |
|
|
626 | const_iv (ST_IMMUTABLE , ST_IMMUTABLE) |
|
|
627 | const_iv (ST_NOATIME , ST_NOATIME) |
|
|
628 | const_iv (ST_NODIRATIME , ST_NODIRATIME) |
|
|
629 | const_iv (ST_RELATIME , ST_RELATIME) |
|
|
630 | |
|
|
631 | const_iv (MCL_FUTURE , MCL_FUTURE) |
|
|
632 | const_iv (MCL_CURRENT , MCL_CURRENT) |
|
|
633 | |
|
|
634 | const_eio (MS_ASYNC) |
|
|
635 | const_eio (MS_INVALIDATE) |
|
|
636 | const_eio (MS_SYNC) |
|
|
637 | |
|
|
638 | const_eio (MT_MODIFY) |
|
|
639 | |
612 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
640 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
613 | const_eio (SYNC_FILE_RANGE_WRITE) |
641 | const_eio (SYNC_FILE_RANGE_WRITE) |
614 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
642 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
615 | |
643 | |
616 | const_eio (READDIR_DENTS) |
644 | const_eio (READDIR_DENTS) |
… | |
… | |
627 | const_eio (DT_LNK) |
655 | const_eio (DT_LNK) |
628 | const_eio (DT_SOCK) |
656 | const_eio (DT_SOCK) |
629 | const_eio (DT_WHT) |
657 | const_eio (DT_WHT) |
630 | }; |
658 | }; |
631 | |
659 | |
632 | stash = gv_stashpv ("IO::AIO", 1); |
660 | aio_stash = gv_stashpv ("IO::AIO" , 1); |
|
|
661 | aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); |
|
|
662 | aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); |
633 | |
663 | |
634 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
664 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
635 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
665 | newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv)); |
636 | |
666 | |
637 | create_respipe (); |
667 | create_respipe (); |
638 | |
668 | |
639 | if (eio_init (want_poll, done_poll) < 0) |
669 | if (eio_init (want_poll, done_poll) < 0) |
640 | croak ("IO::AIO: unable to initialise eio library"); |
670 | croak ("IO::AIO: unable to initialise eio library"); |
… | |
… | |
701 | ALIAS: |
731 | ALIAS: |
702 | aio_fsync = EIO_FSYNC |
732 | aio_fsync = EIO_FSYNC |
703 | aio_fdatasync = EIO_FDATASYNC |
733 | aio_fdatasync = EIO_FDATASYNC |
704 | PPCODE: |
734 | PPCODE: |
705 | { |
735 | { |
706 | int fd = extract_fd (fh, 0); |
736 | int fd = s_fileno_croak (fh, 0); |
707 | dREQ; |
737 | dREQ; |
708 | |
738 | |
709 | req->type = ix; |
739 | req->type = ix; |
710 | req->sv1 = newSVsv (fh); |
740 | req->sv1 = newSVsv (fh); |
711 | req->int1 = fd; |
741 | req->int1 = fd; |
… | |
… | |
716 | void |
746 | void |
717 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
747 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
718 | PROTOTYPE: $$$$;$ |
748 | PROTOTYPE: $$$$;$ |
719 | PPCODE: |
749 | PPCODE: |
720 | { |
750 | { |
721 | int fd = extract_fd (fh, 0); |
751 | int fd = s_fileno_croak (fh, 0); |
722 | dREQ; |
752 | dREQ; |
723 | |
753 | |
724 | req->type = EIO_SYNC_FILE_RANGE; |
754 | req->type = EIO_SYNC_FILE_RANGE; |
725 | req->sv1 = newSVsv (fh); |
755 | req->sv1 = newSVsv (fh); |
726 | req->int1 = fd; |
756 | req->int1 = fd; |
… | |
… | |
735 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
765 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
736 | PROTOTYPE: $;$ |
766 | PROTOTYPE: $;$ |
737 | PPCODE: |
767 | PPCODE: |
738 | { |
768 | { |
739 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
769 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
740 | int fd = extract_fd (fh, 0); |
770 | int fd = s_fileno_croak (fh, 0); |
741 | dREQ; |
771 | dREQ; |
742 | |
772 | |
743 | if (close_pipe < 0) |
773 | if (close_pipe < 0) |
744 | { |
774 | { |
745 | int pipefd [2]; |
775 | int pipefd [2]; |
… | |
… | |
767 | aio_write = EIO_WRITE |
797 | aio_write = EIO_WRITE |
768 | PROTOTYPE: $$$$$;$ |
798 | PROTOTYPE: $$$$$;$ |
769 | PPCODE: |
799 | PPCODE: |
770 | { |
800 | { |
771 | STRLEN svlen; |
801 | STRLEN svlen; |
772 | int fd = extract_fd (fh, ix == EIO_WRITE); |
802 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
773 | char *svptr = SvPVbyte (data, svlen); |
803 | char *svptr = SvPVbyte (data, svlen); |
774 | UV len = SvUV (length); |
804 | UV len = SvUV (length); |
775 | |
805 | |
776 | if (dataoffset < 0) |
806 | if (dataoffset < 0) |
777 | dataoffset += svlen; |
807 | dataoffset += svlen; |
… | |
… | |
832 | void |
862 | void |
833 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
863 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
834 | PROTOTYPE: $$$$;$ |
864 | PROTOTYPE: $$$$;$ |
835 | PPCODE: |
865 | PPCODE: |
836 | { |
866 | { |
837 | int ifd = extract_fd (in_fh , 0); |
867 | int ifd = s_fileno_croak (in_fh , 0); |
838 | int ofd = extract_fd (out_fh, 0); |
868 | int ofd = s_fileno_croak (out_fh, 1); |
839 | dREQ; |
869 | dREQ; |
840 | |
870 | |
841 | req->type = EIO_SENDFILE; |
871 | req->type = EIO_SENDFILE; |
842 | req->sv1 = newSVsv (out_fh); |
872 | req->sv1 = newSVsv (out_fh); |
843 | req->int1 = ofd; |
873 | req->int1 = ofd; |
… | |
… | |
852 | void |
882 | void |
853 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
883 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
854 | PROTOTYPE: $$$;$ |
884 | PROTOTYPE: $$$;$ |
855 | PPCODE: |
885 | PPCODE: |
856 | { |
886 | { |
857 | int fd = extract_fd (fh, 0); |
887 | int fd = s_fileno_croak (fh, 0); |
858 | dREQ; |
888 | dREQ; |
859 | |
889 | |
860 | req->type = EIO_READAHEAD; |
890 | req->type = EIO_READAHEAD; |
861 | req->sv1 = newSVsv (fh); |
891 | req->sv1 = newSVsv (fh); |
862 | req->int1 = fd; |
892 | req->int1 = fd; |
… | |
… | |
867 | } |
897 | } |
868 | |
898 | |
869 | void |
899 | void |
870 | aio_stat (SV8 *fh_or_path, SV *callback=&PL_sv_undef) |
900 | aio_stat (SV8 *fh_or_path, SV *callback=&PL_sv_undef) |
871 | ALIAS: |
901 | ALIAS: |
872 | aio_stat = EIO_STAT |
902 | aio_stat = EIO_STAT |
873 | aio_lstat = EIO_LSTAT |
903 | aio_lstat = EIO_LSTAT |
|
|
904 | aio_statvfs = EIO_STATVFS |
874 | PPCODE: |
905 | PPCODE: |
875 | { |
906 | { |
876 | dREQ; |
907 | dREQ; |
877 | |
908 | |
878 | req->sv1 = newSVsv (fh_or_path); |
909 | req->sv1 = newSVsv (fh_or_path); |
… | |
… | |
882 | req->type = ix; |
913 | req->type = ix; |
883 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
914 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
884 | } |
915 | } |
885 | else |
916 | else |
886 | { |
917 | { |
887 | req->type = EIO_FSTAT; |
918 | req->type = ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT; |
888 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
919 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
889 | } |
920 | } |
890 | |
921 | |
891 | REQ_SEND; |
922 | REQ_SEND; |
892 | } |
923 | } |
… | |
… | |
1055 | |
1086 | |
1056 | REQ_SEND; |
1087 | REQ_SEND; |
1057 | } |
1088 | } |
1058 | |
1089 | |
1059 | void |
1090 | void |
|
|
1091 | aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) |
|
|
1092 | ALIAS: |
|
|
1093 | aio_mtouch = EIO_MTOUCH |
|
|
1094 | aio_msync = EIO_MSYNC |
|
|
1095 | PROTOTYPE: $$$$;$ |
|
|
1096 | PPCODE: |
|
|
1097 | { |
|
|
1098 | STRLEN svlen; |
|
|
1099 | UV len = SvUV (length); |
|
|
1100 | char *svptr = SvPVbyte (data, svlen); |
|
|
1101 | |
|
|
1102 | if (offset < 0) |
|
|
1103 | offset += svlen; |
|
|
1104 | |
|
|
1105 | if (offset < 0 || offset > svlen) |
|
|
1106 | croak ("offset outside of scalar"); |
|
|
1107 | |
|
|
1108 | if (!SvOK (length) || len + offset > svlen) |
|
|
1109 | len = svlen - offset; |
|
|
1110 | |
|
|
1111 | { |
|
|
1112 | dREQ; |
|
|
1113 | |
|
|
1114 | req->type = ix; |
|
|
1115 | req->size = len; |
|
|
1116 | req->sv2 = SvREFCNT_inc (data); |
|
|
1117 | req->ptr2 = (char *)svptr + offset; |
|
|
1118 | req->int1 = flags; |
|
|
1119 | |
|
|
1120 | REQ_SEND; |
|
|
1121 | } |
|
|
1122 | } |
|
|
1123 | |
|
|
1124 | void |
1060 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1125 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1061 | PPCODE: |
1126 | PPCODE: |
1062 | { |
1127 | { |
1063 | dREQ; |
1128 | dREQ; |
1064 | |
1129 | |
… | |
… | |
1076 | dREQ; |
1141 | dREQ; |
1077 | |
1142 | |
1078 | req->type = EIO_GROUP; |
1143 | req->type = EIO_GROUP; |
1079 | |
1144 | |
1080 | req_submit (req); |
1145 | req_submit (req); |
1081 | XPUSHs (req_sv (req, AIO_GRP_KLASS)); |
1146 | XPUSHs (req_sv (req, aio_grp_stash)); |
1082 | } |
1147 | } |
1083 | |
1148 | |
1084 | void |
1149 | void |
1085 | aio_nop (SV *callback=&PL_sv_undef) |
1150 | aio_nop (SV *callback=&PL_sv_undef) |
1086 | ALIAS: |
1151 | ALIAS: |
… | |
… | |
1138 | |
1203 | |
1139 | int |
1204 | int |
1140 | poll_fileno() |
1205 | poll_fileno() |
1141 | PROTOTYPE: |
1206 | PROTOTYPE: |
1142 | CODE: |
1207 | CODE: |
1143 | RETVAL = respipe [0]; |
1208 | RETVAL = s_epipe_fd (&respipe); |
1144 | OUTPUT: |
1209 | OUTPUT: |
1145 | RETVAL |
1210 | RETVAL |
1146 | |
1211 | |
1147 | int |
1212 | int |
1148 | poll_cb(...) |
1213 | poll_cb(...) |
… | |
… | |
1192 | |
1257 | |
1193 | int |
1258 | int |
1194 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1259 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1195 | PROTOTYPE: $$$$ |
1260 | PROTOTYPE: $$$$ |
1196 | CODE: |
1261 | CODE: |
1197 | { |
|
|
1198 | #if _XOPEN_SOURCE >= 600 |
1262 | #if _XOPEN_SOURCE >= 600 && !NO_FADVISE |
1199 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1263 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1200 | #else |
1264 | #else |
1201 | RETVAL = errno = ENOSYS; |
1265 | RETVAL = errno = ENOSYS; |
1202 | #endif |
1266 | #endif |
1203 | } |
|
|
1204 | OUTPUT: |
1267 | OUTPUT: |
1205 | RETVAL |
1268 | RETVAL |
1206 | |
1269 | |
1207 | ssize_t |
1270 | ssize_t |
1208 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1271 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1209 | PROTOTYPE: $$$$ |
1272 | PROTOTYPE: $$$$ |
1210 | CODE: |
1273 | CODE: |
1211 | eio_sendfile_sync (ofh, ifh, offset, count); |
1274 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
|
|
1275 | OUTPUT: |
|
|
1276 | RETVAL |
|
|
1277 | |
|
|
1278 | int |
|
|
1279 | mlockall (int flags) |
|
|
1280 | PROTOTYPE: $ |
|
|
1281 | CODE: |
|
|
1282 | #if _POSIX_MEMLOCK |
|
|
1283 | #if __GLIBC__ == 2 && __GLIBC_MINOR__ <= 7 |
|
|
1284 | extern int mallopt (int, int); |
|
|
1285 | mallopt (-6, 238); /* http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473812 */ |
|
|
1286 | #endif |
|
|
1287 | mlockall (flags); |
|
|
1288 | #else |
|
|
1289 | RETVAL =-1; |
|
|
1290 | errno = ENOSYS; |
|
|
1291 | #endif |
|
|
1292 | OUTPUT: |
|
|
1293 | RETVAL |
|
|
1294 | |
|
|
1295 | int |
|
|
1296 | munlockall () |
|
|
1297 | PROTOTYPE: |
|
|
1298 | CODE: |
|
|
1299 | #if _POSIX_MEMLOCK |
|
|
1300 | munlockall (); |
|
|
1301 | #else |
|
|
1302 | RETVAL =-1; |
|
|
1303 | errno = ENOSYS; |
|
|
1304 | #endif |
|
|
1305 | OUTPUT: |
|
|
1306 | RETVAL |
1212 | |
1307 | |
1213 | void _on_next_submit (SV *cb) |
1308 | void _on_next_submit (SV *cb) |
1214 | CODE: |
1309 | CODE: |
1215 | SvREFCNT_dec (on_next_submit); |
1310 | SvREFCNT_dec (on_next_submit); |
1216 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1311 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
… | |
… | |
1231 | if (GIMME_V != G_VOID) |
1326 | if (GIMME_V != G_VOID) |
1232 | XPUSHs (req->callback ? sv_2mortal (newRV_inc (req->callback)) : &PL_sv_undef); |
1327 | XPUSHs (req->callback ? sv_2mortal (newRV_inc (req->callback)) : &PL_sv_undef); |
1233 | |
1328 | |
1234 | if (items > 1) |
1329 | if (items > 1) |
1235 | { |
1330 | { |
1236 | SV *cb_cv = get_cb (callback); |
1331 | SV *cb_cv =get_cb (callback); |
1237 | |
1332 | |
1238 | SvREFCNT_dec (req->callback); |
1333 | SvREFCNT_dec (req->callback); |
1239 | req->callback = SvREFCNT_inc (cb_cv); |
1334 | req->callback = SvREFCNT_inc (cb_cv); |
1240 | } |
1335 | } |
1241 | } |
1336 | } |