… | |
… | |
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> |
… | |
… | |
75 | |
77 | |
76 | #define EIO_STRUCT_STAT Stat_t |
78 | #define EIO_STRUCT_STAT Stat_t |
77 | |
79 | |
78 | /* use NV for 32 bit perls as it allows larger offsets */ |
80 | /* use NV for 32 bit perls as it allows larger offsets */ |
79 | #if IVSIZE >= 8 |
81 | #if IVSIZE >= 8 |
|
|
82 | # define VAL64 IV |
80 | # define SvVAL64 SvIV |
83 | # define SvVAL64 SvIV |
|
|
84 | # define newSVval64 newSViv |
81 | #else |
85 | #else |
|
|
86 | # define VAL64 NV |
82 | # define SvVAL64 SvNV |
87 | # define SvVAL64 SvNV |
|
|
88 | # define newSVval64 newSVnv |
83 | #endif |
89 | #endif |
84 | |
90 | |
85 | /*****************************************************************************/ |
91 | /*****************************************************************************/ |
86 | |
92 | |
87 | #if __GNUC__ >= 3 |
93 | #if __GNUC__ >= 3 |
… | |
… | |
95 | |
101 | |
96 | /*****************************************************************************/ |
102 | /*****************************************************************************/ |
97 | |
103 | |
98 | static HV *stash; |
104 | static HV *stash; |
99 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
105 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
|
|
106 | typedef int aio_rfd; /* read file desriptor */ |
|
|
107 | typedef int aio_wfd; /* write file descriptor */ |
100 | |
108 | |
101 | #define AIO_REQ_KLASS "IO::AIO::REQ" |
109 | #define AIO_REQ_KLASS "IO::AIO::REQ" |
102 | #define AIO_GRP_KLASS "IO::AIO::GRP" |
110 | #define AIO_GRP_KLASS "IO::AIO::GRP" |
103 | |
111 | |
104 | #define EIO_REQ_MEMBERS \ |
112 | #define EIO_REQ_MEMBERS \ |
… | |
… | |
109 | |
117 | |
110 | #define EIO_NO_WRAPPERS 1 |
118 | #define EIO_NO_WRAPPERS 1 |
111 | |
119 | |
112 | #include "libeio/eio.h" |
120 | #include "libeio/eio.h" |
113 | |
121 | |
|
|
122 | #ifndef POSIX_FADV_NORMAL |
|
|
123 | # define POSIX_FADV_NORMAL 0 |
|
|
124 | # define NO_FADVISE 1 |
|
|
125 | #endif |
|
|
126 | |
|
|
127 | #ifndef POSIX_FADV_SEQUENTIAL |
|
|
128 | # define POSIX_FADV_SEQUENTIAL 0 |
|
|
129 | #endif |
|
|
130 | |
|
|
131 | #ifndef POSIX_FADV_RANDOM |
|
|
132 | # define POSIX_FADV_RANDOM 0 |
|
|
133 | #endif |
|
|
134 | |
|
|
135 | #ifndef POSIX_FADV_NOREUSE |
|
|
136 | # define POSIX_FADV_NOREUSE 0 |
|
|
137 | #endif |
|
|
138 | |
|
|
139 | #ifndef POSIX_FADV_WILLNEED |
|
|
140 | # define POSIX_FADV_WILLNEED 0 |
|
|
141 | #endif |
|
|
142 | |
|
|
143 | #ifndef POSIX_FADV_DONTNEED |
|
|
144 | # define POSIX_FADV_DONTNEED 0 |
|
|
145 | #endif |
|
|
146 | |
114 | static int req_invoke (eio_req *req); |
147 | static int req_invoke (eio_req *req); |
115 | #define EIO_FINISH(req) req_invoke (req) |
148 | #define EIO_FINISH(req) req_invoke (req) |
116 | static void req_destroy (eio_req *grp); |
149 | static void req_destroy (eio_req *grp); |
117 | #define EIO_DESTROY(req) req_destroy (req) |
150 | #define EIO_DESTROY(req) req_destroy (req) |
118 | |
151 | |
… | |
… | |
127 | |
160 | |
128 | static SV *on_next_submit; |
161 | static SV *on_next_submit; |
129 | static int next_pri = EIO_PRI_DEFAULT; |
162 | static int next_pri = EIO_PRI_DEFAULT; |
130 | static int max_outstanding; |
163 | static int max_outstanding; |
131 | |
164 | |
132 | static int respipe_osf [2], respipe [2] = { -1, -1 }; |
165 | static int respipe_osf [2]; |
|
|
166 | static s_epipe respipe; |
133 | |
167 | |
134 | static void req_destroy (aio_req req); |
168 | static void req_destroy (aio_req req); |
135 | static void req_cancel (aio_req req); |
169 | static void req_cancel (aio_req req); |
136 | |
170 | |
137 | static void want_poll (void) |
171 | static void want_poll (void) |
138 | { |
172 | { |
139 | /* write a dummy byte to the pipe so fh becomes ready */ |
173 | /* write a dummy byte to the pipe so fh becomes ready */ |
140 | respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1); |
174 | s_epipe_signal (&respipe); |
141 | } |
175 | } |
142 | |
176 | |
143 | static void done_poll (void) |
177 | static void done_poll (void) |
144 | { |
178 | { |
145 | /* read any signals sent by the worker threads */ |
179 | /* read any signals sent by the worker threads */ |
146 | char buf [4]; |
180 | s_epipe_drain (&respipe); |
147 | while (respipe_read (respipe [0], buf, 4) == 4) |
|
|
148 | ; |
|
|
149 | } |
181 | } |
150 | |
182 | |
151 | /* must be called at most once */ |
183 | /* must be called at most once */ |
152 | static SV *req_sv (aio_req req, const char *klass) |
184 | static SV *req_sv (aio_req req, const char *klass) |
153 | { |
185 | { |
… | |
… | |
228 | SV *rv = &PL_sv_undef; |
260 | SV *rv = &PL_sv_undef; |
229 | |
261 | |
230 | if (req->result >= 0) |
262 | if (req->result >= 0) |
231 | { |
263 | { |
232 | int i; |
264 | int i; |
233 | char *buf = req->ptr2; |
265 | char *names = (char *)req->ptr2; |
|
|
266 | eio_dirent *ent = (eio_dirent *)req->ptr1; /* might be 0 */ |
234 | AV *av = newAV (); |
267 | AV *av = newAV (); |
235 | |
268 | |
236 | av_extend (av, req->result - 1); |
269 | av_extend (av, req->result - 1); |
237 | |
270 | |
238 | for (i = 0; i < req->result; ++i) |
271 | for (i = 0; i < req->result; ++i) |
239 | { |
272 | { |
240 | SV *sv = newSVpv (buf, 0); |
273 | if (req->int1 & EIO_READDIR_DENTS) |
|
|
274 | { |
|
|
275 | SV *namesv = newSVpvn (names + ent->nameofs, ent->namelen); |
241 | |
276 | |
|
|
277 | if (req->int1 & EIO_READDIR_CUSTOM2) |
|
|
278 | { |
|
|
279 | static SV *sv_type [EIO_DT_MAX + 1]; /* type sv cache */ |
|
|
280 | AV *avent = newAV (); |
|
|
281 | |
|
|
282 | av_extend (avent, 2); |
|
|
283 | |
|
|
284 | if (!sv_type [ent->type]) |
|
|
285 | { |
|
|
286 | sv_type [ent->type] = newSViv (ent->type); |
|
|
287 | SvREADONLY_on (sv_type [ent->type]); |
|
|
288 | } |
|
|
289 | |
|
|
290 | av_store (avent, 0, namesv); |
|
|
291 | av_store (avent, 1, SvREFCNT_inc (sv_type [ent->type])); |
|
|
292 | av_store (avent, 2, IVSIZE >= 8 ? newSVuv (ent->inode) : newSVnv (ent->inode)); |
|
|
293 | |
|
|
294 | av_store (av, i, newRV_noinc ((SV *)avent)); |
|
|
295 | } |
|
|
296 | else |
242 | av_store (av, i, sv); |
297 | av_store (av, i, namesv); |
|
|
298 | |
|
|
299 | ++ent; |
|
|
300 | } |
|
|
301 | else |
|
|
302 | { |
|
|
303 | SV *name = newSVpv (names, 0); |
|
|
304 | av_store (av, i, name); |
243 | buf += SvCUR (sv) + 1; |
305 | names += SvCUR (name) + 1; |
|
|
306 | } |
244 | } |
307 | } |
245 | |
308 | |
246 | rv = sv_2mortal (newRV_noinc ((SV *)av)); |
309 | rv = sv_2mortal (newRV_noinc ((SV *)av)); |
247 | } |
310 | } |
248 | |
311 | |
249 | PUSHs (rv); |
312 | PUSHs (rv); |
|
|
313 | |
|
|
314 | if (req->int1 & EIO_READDIR_CUSTOM1) |
|
|
315 | XPUSHs (sv_2mortal (newSViv (req->int1 & ~(EIO_READDIR_CUSTOM1 | EIO_READDIR_CUSTOM2)))); |
250 | } |
316 | } |
251 | break; |
317 | break; |
252 | |
318 | |
253 | case EIO_OPEN: |
319 | case EIO_OPEN: |
254 | { |
320 | { |
… | |
… | |
260 | GV *gv = (GV *)sv_newmortal (); |
326 | GV *gv = (GV *)sv_newmortal (); |
261 | int flags = req->int1 & (O_RDONLY | O_WRONLY | O_RDWR); |
327 | int flags = req->int1 & (O_RDONLY | O_WRONLY | O_RDWR); |
262 | char sym [64]; |
328 | char sym [64]; |
263 | int symlen; |
329 | int symlen; |
264 | |
330 | |
265 | symlen = snprintf (sym, sizeof (sym), "fd#%d", req->result); |
331 | symlen = snprintf (sym, sizeof (sym), "fd#%d", (int)req->result); |
266 | gv_init (gv, stash, sym, symlen, 0); |
332 | gv_init (gv, stash, sym, symlen, 0); |
267 | |
333 | |
268 | symlen = snprintf ( |
334 | symlen = snprintf ( |
269 | sym, |
335 | sym, |
270 | sizeof (sym), |
336 | sizeof (sym), |
271 | "%s&=%d", |
337 | "%s&=%d", |
272 | flags == O_RDONLY ? "<" : flags == O_WRONLY ? ">" : "+<", |
338 | flags == O_RDONLY ? "<" : flags == O_WRONLY ? ">" : "+<", |
273 | req->result |
339 | (int)req->result |
274 | ); |
340 | ); |
275 | |
341 | |
276 | if (do_open (gv, sym, symlen, 0, 0, 0, 0)) |
342 | if (do_open (gv, sym, symlen, 0, 0, 0, 0)) |
277 | fh = (SV *)gv; |
343 | fh = (SV *)gv; |
278 | } |
344 | } |
… | |
… | |
374 | grp->sv2 = 0; |
440 | grp->sv2 = 0; |
375 | |
441 | |
376 | eio_grp_cancel (grp); |
442 | eio_grp_cancel (grp); |
377 | } |
443 | } |
378 | |
444 | |
379 | #ifdef USE_SOCKETS_AS_HANDLES |
|
|
380 | # define TO_SOCKET(x) (win32_get_osfhandle (x)) |
|
|
381 | #else |
|
|
382 | # define TO_SOCKET(x) (x) |
|
|
383 | #endif |
|
|
384 | |
|
|
385 | static void |
445 | static void |
386 | create_respipe (void) |
446 | create_respipe (void) |
387 | { |
447 | { |
388 | int old_readfd = respipe [0]; |
|
|
389 | |
|
|
390 | if (respipe [1] >= 0) |
|
|
391 | respipe_close (TO_SOCKET (respipe [1])); |
|
|
392 | |
|
|
393 | #ifdef _WIN32 |
|
|
394 | if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe)) |
|
|
395 | #else |
|
|
396 | if (pipe (respipe)) |
448 | if (s_epipe_renew (&respipe)) |
397 | #endif |
|
|
398 | croak ("unable to initialize result pipe"); |
449 | croak ("unable to initialize result pipe"); |
399 | |
450 | |
400 | if (old_readfd >= 0) |
|
|
401 | { |
|
|
402 | if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0) |
|
|
403 | croak ("unable to initialize result pipe(2)"); |
|
|
404 | |
|
|
405 | respipe_close (respipe [0]); |
|
|
406 | respipe [0] = old_readfd; |
|
|
407 | } |
|
|
408 | |
|
|
409 | #ifdef _WIN32 |
|
|
410 | int arg = 1; |
|
|
411 | if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg) |
|
|
412 | || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg)) |
|
|
413 | #else |
|
|
414 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK) |
|
|
415 | || fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
|
|
416 | #endif |
|
|
417 | croak ("unable to initialize result pipe(3)"); |
|
|
418 | |
|
|
419 | respipe_osf [0] = TO_SOCKET (respipe [0]); |
451 | respipe_osf [0] = S_TO_SOCKET (respipe.fd [0]); |
420 | respipe_osf [1] = TO_SOCKET (respipe [1]); |
452 | respipe_osf [1] = S_TO_SOCKET (respipe.fd [1]); |
421 | } |
453 | } |
422 | |
454 | |
423 | static void poll_wait (void) |
455 | static void poll_wait (void) |
424 | { |
456 | { |
425 | fd_set rfd; |
|
|
426 | |
|
|
427 | while (eio_nreqs ()) |
457 | while (eio_nreqs ()) |
428 | { |
458 | { |
429 | int size; |
459 | int size; |
430 | |
460 | |
431 | X_LOCK (reslock); |
461 | X_LOCK (reslock); |
… | |
… | |
435 | if (size) |
465 | if (size) |
436 | return; |
466 | return; |
437 | |
467 | |
438 | etp_maybe_start_thread (); |
468 | etp_maybe_start_thread (); |
439 | |
469 | |
440 | FD_ZERO (&rfd); |
470 | s_epipe_wait (&respipe); |
441 | FD_SET (respipe [0], &rfd); |
|
|
442 | |
|
|
443 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
|
|
444 | } |
471 | } |
445 | } |
472 | } |
446 | |
473 | |
447 | static int poll_cb (void) |
474 | static int poll_cb (void) |
448 | { |
475 | { |
… | |
… | |
466 | } |
493 | } |
467 | |
494 | |
468 | static SV * |
495 | static SV * |
469 | get_cb (SV *cb_sv) |
496 | get_cb (SV *cb_sv) |
470 | { |
497 | { |
471 | HV *st; |
498 | SvGETMAGIC (cb_sv); |
472 | GV *gvp; |
499 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
473 | CV *cv; |
|
|
474 | |
|
|
475 | if (!SvOK (cb_sv)) |
|
|
476 | return 0; |
|
|
477 | |
|
|
478 | cv = sv_2cv (cb_sv, &st, &gvp, 0); |
|
|
479 | |
|
|
480 | if (!cv) |
|
|
481 | croak ("IO::AIO callback must be undef or a CODE reference"); |
|
|
482 | |
|
|
483 | return (SV *)cv; |
|
|
484 | } |
500 | } |
485 | |
501 | |
486 | #define dREQ \ |
502 | #define dREQ \ |
487 | SV *cb_cv; \ |
503 | SV *cb_cv; \ |
488 | aio_req req; \ |
504 | aio_req req; \ |
… | |
… | |
504 | SPAGAIN; \ |
520 | SPAGAIN; \ |
505 | \ |
521 | \ |
506 | if (GIMME_V != G_VOID) \ |
522 | if (GIMME_V != G_VOID) \ |
507 | XPUSHs (req_sv (req, AIO_REQ_KLASS)); |
523 | XPUSHs (req_sv (req, AIO_REQ_KLASS)); |
508 | |
524 | |
509 | static int |
|
|
510 | extract_fd (SV *fh, int wr) |
|
|
511 | { |
|
|
512 | int fd = PerlIO_fileno (wr ? IoOFP (sv_2io (fh)) : IoIFP (sv_2io (fh))); |
|
|
513 | |
|
|
514 | if (fd < 0) |
|
|
515 | croak ("illegal fh argument, either not an OS file or read/write mode mismatch"); |
|
|
516 | |
|
|
517 | return fd; |
|
|
518 | } |
|
|
519 | |
|
|
520 | MODULE = IO::AIO PACKAGE = IO::AIO |
525 | MODULE = IO::AIO PACKAGE = IO::AIO |
521 | |
526 | |
522 | PROTOTYPES: ENABLE |
527 | PROTOTYPES: ENABLE |
523 | |
528 | |
524 | BOOT: |
529 | BOOT: |
525 | { |
530 | { |
526 | stash = gv_stashpv ("IO::AIO", 1); |
531 | static const struct { |
527 | |
532 | const char *name; |
528 | newCONSTSUB (stash, "EXDEV", newSViv (EXDEV)); |
533 | IV iv; |
529 | newCONSTSUB (stash, "ENOSYS", newSViv (ENOSYS)); |
534 | } *civ, const_iv[] = { |
530 | newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY)); |
535 | # define const_iv(name, value) { # name, (IV) value }, |
531 | newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY)); |
536 | # define const_eio(name) { # name, (IV) EIO_ ## name }, |
532 | newCONSTSUB (stash, "O_CREAT", newSViv (O_CREAT)); |
537 | const_iv (EXDEV , EXDEV) |
533 | newCONSTSUB (stash, "O_TRUNC", newSViv (O_TRUNC)); |
538 | const_iv (ENOSYS , ENOSYS) |
|
|
539 | const_iv (O_RDONLY, O_RDONLY) |
|
|
540 | const_iv (O_WRONLY, O_WRONLY) |
|
|
541 | const_iv (O_CREAT , O_CREAT) |
|
|
542 | const_iv (O_TRUNC , O_TRUNC) |
534 | #ifndef _WIN32 |
543 | #ifndef _WIN32 |
535 | newCONSTSUB (stash, "S_IFIFO", newSViv (S_IFIFO)); |
544 | const_iv (S_IFIFO , S_IFIFO) |
536 | #endif |
545 | #endif |
537 | newCONSTSUB (stash, "S_IFIFO", newSViv (S_IFIFO)); |
546 | const_iv (FADV_NORMAL , POSIX_FADV_NORMAL) |
538 | newCONSTSUB (stash, "SYNC_FILE_RANGE_WAIT_BEFORE", newSViv (EIO_SYNC_FILE_RANGE_WAIT_BEFORE)); |
547 | const_iv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
539 | newCONSTSUB (stash, "SYNC_FILE_RANGE_WRITE" , newSViv (EIO_SYNC_FILE_RANGE_WRITE)); |
548 | const_iv (FADV_RANDOM , POSIX_FADV_RANDOM) |
540 | newCONSTSUB (stash, "SYNC_FILE_RANGE_WAIT_AFTER" , newSViv (EIO_SYNC_FILE_RANGE_WAIT_AFTER)); |
549 | const_iv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
|
|
550 | const_iv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
|
|
551 | const_iv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
541 | |
552 | |
|
|
553 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
|
|
554 | const_eio (SYNC_FILE_RANGE_WRITE) |
|
|
555 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
|
|
556 | |
|
|
557 | const_eio (READDIR_DENTS) |
|
|
558 | const_eio (READDIR_DIRS_FIRST) |
|
|
559 | const_eio (READDIR_STAT_ORDER) |
|
|
560 | const_eio (READDIR_FOUND_UNKNOWN) |
|
|
561 | |
|
|
562 | const_eio (DT_UNKNOWN) |
|
|
563 | const_eio (DT_FIFO) |
|
|
564 | const_eio (DT_CHR) |
|
|
565 | const_eio (DT_DIR) |
|
|
566 | const_eio (DT_BLK) |
|
|
567 | const_eio (DT_REG) |
|
|
568 | const_eio (DT_LNK) |
|
|
569 | const_eio (DT_SOCK) |
|
|
570 | const_eio (DT_WHT) |
|
|
571 | }; |
|
|
572 | |
|
|
573 | stash = gv_stashpv ("IO::AIO", 1); |
|
|
574 | |
|
|
575 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
|
|
576 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
|
|
577 | |
542 | create_respipe (); |
578 | create_respipe (); |
543 | |
579 | |
544 | if (eio_init (want_poll, done_poll) < 0) |
580 | if (eio_init (want_poll, done_poll) < 0) |
545 | croak ("IO::AIO: unable to initialise eio library"); |
581 | croak ("IO::AIO: unable to initialise eio library"); |
546 | |
582 | |
547 | /* atfork child called in fifo order, so before eio's handler */ |
583 | /* atfork child called in fifo order, so before eio's handler */ |
548 | X_THREAD_ATFORK (0, 0, atfork_child); |
584 | X_THREAD_ATFORK (0, 0, atfork_child); |
549 | } |
585 | } |
550 | |
586 | |
551 | void |
587 | void |
552 | max_poll_reqs (int nreqs) |
588 | max_poll_reqs (int nreqs) |
553 | PROTOTYPE: $ |
589 | PROTOTYPE: $ |
… | |
… | |
606 | ALIAS: |
642 | ALIAS: |
607 | aio_fsync = EIO_FSYNC |
643 | aio_fsync = EIO_FSYNC |
608 | aio_fdatasync = EIO_FDATASYNC |
644 | aio_fdatasync = EIO_FDATASYNC |
609 | PPCODE: |
645 | PPCODE: |
610 | { |
646 | { |
611 | int fd = extract_fd (fh, 0); |
647 | int fd = s_fileno_croak (fh, 0); |
612 | dREQ; |
648 | dREQ; |
613 | |
649 | |
614 | req->type = ix; |
650 | req->type = ix; |
615 | req->sv1 = newSVsv (fh); |
651 | req->sv1 = newSVsv (fh); |
616 | req->int1 = fd; |
652 | req->int1 = fd; |
617 | |
653 | |
618 | REQ_SEND (req); |
654 | REQ_SEND (req); |
619 | } |
655 | } |
620 | |
656 | |
621 | void |
657 | void |
622 | aio_sync_file_range (SV *fh, SV *offset, SV *nbytes, IV flags, SV *callback=&PL_sv_undef) |
658 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
623 | PROTOTYPE: $$$$;$ |
659 | PROTOTYPE: $$$$;$ |
624 | PPCODE: |
660 | PPCODE: |
625 | { |
661 | { |
626 | int fd = extract_fd (fh, 0); |
662 | int fd = s_fileno_croak (fh, 0); |
627 | dREQ; |
663 | dREQ; |
628 | |
664 | |
629 | req->type = EIO_SYNC_FILE_RANGE; |
665 | req->type = EIO_SYNC_FILE_RANGE; |
630 | req->sv1 = newSVsv (fh); |
666 | req->sv1 = newSVsv (fh); |
631 | req->int1 = fd; |
667 | req->int1 = fd; |
632 | req->offs = SvVAL64 (offset); |
668 | req->offs = offset; |
633 | req->size = SvVAL64 (nbytes); |
669 | req->size = nbytes; |
634 | req->int2 = flags; |
670 | req->int2 = flags; |
635 | |
671 | |
636 | REQ_SEND (req); |
672 | REQ_SEND (req); |
637 | } |
673 | } |
638 | |
674 | |
… | |
… | |
640 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
676 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
641 | PROTOTYPE: $;$ |
677 | PROTOTYPE: $;$ |
642 | PPCODE: |
678 | PPCODE: |
643 | { |
679 | { |
644 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
680 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
645 | int fd = extract_fd (fh, 0); |
681 | int fd = s_fileno_croak (fh, 0); |
646 | dREQ; |
682 | dREQ; |
647 | |
683 | |
648 | if (close_pipe < 0) |
684 | if (close_pipe < 0) |
649 | { |
685 | { |
650 | int pipefd [2]; |
686 | int pipefd [2]; |
… | |
… | |
672 | aio_write = EIO_WRITE |
708 | aio_write = EIO_WRITE |
673 | PROTOTYPE: $$$$$;$ |
709 | PROTOTYPE: $$$$$;$ |
674 | PPCODE: |
710 | PPCODE: |
675 | { |
711 | { |
676 | STRLEN svlen; |
712 | STRLEN svlen; |
677 | int fd = extract_fd (fh, ix == EIO_WRITE); |
713 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
678 | char *svptr = SvPVbyte (data, svlen); |
714 | char *svptr = SvPVbyte (data, svlen); |
679 | UV len = SvUV (length); |
715 | UV len = SvUV (length); |
680 | |
716 | |
681 | if (dataoffset < 0) |
717 | if (dataoffset < 0) |
682 | dataoffset += svlen; |
718 | dataoffset += svlen; |
… | |
… | |
733 | |
769 | |
734 | REQ_SEND; |
770 | REQ_SEND; |
735 | } |
771 | } |
736 | |
772 | |
737 | void |
773 | void |
738 | aio_sendfile (SV *out_fh, SV *in_fh, SV *in_offset, UV length, SV *callback=&PL_sv_undef) |
774 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
739 | PROTOTYPE: $$$$;$ |
775 | PROTOTYPE: $$$$;$ |
740 | PPCODE: |
776 | PPCODE: |
741 | { |
777 | { |
742 | int ifd = extract_fd (in_fh , 0); |
778 | int ifd = s_fileno_croak (in_fh , 0); |
743 | int ofd = extract_fd (out_fh, 0); |
779 | int ofd = s_fileno_croak (out_fh, 1); |
744 | dREQ; |
780 | dREQ; |
745 | |
781 | |
746 | req->type = EIO_SENDFILE; |
782 | req->type = EIO_SENDFILE; |
747 | req->sv1 = newSVsv (out_fh); |
783 | req->sv1 = newSVsv (out_fh); |
748 | req->int1 = ofd; |
784 | req->int1 = ofd; |
749 | req->sv2 = newSVsv (in_fh); |
785 | req->sv2 = newSVsv (in_fh); |
750 | req->int2 = ifd; |
786 | req->int2 = ifd; |
751 | req->offs = SvVAL64 (in_offset); |
787 | req->offs = in_offset; |
752 | req->size = length; |
788 | req->size = length; |
753 | |
789 | |
754 | REQ_SEND; |
790 | REQ_SEND; |
755 | } |
791 | } |
756 | |
792 | |
757 | void |
793 | void |
758 | aio_readahead (SV *fh, SV *offset, IV length, SV *callback=&PL_sv_undef) |
794 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
759 | PROTOTYPE: $$$;$ |
795 | PROTOTYPE: $$$;$ |
760 | PPCODE: |
796 | PPCODE: |
761 | { |
797 | { |
762 | int fd = extract_fd (fh, 0); |
798 | int fd = s_fileno_croak (fh, 0); |
763 | dREQ; |
799 | dREQ; |
764 | |
800 | |
765 | req->type = EIO_READAHEAD; |
801 | req->type = EIO_READAHEAD; |
766 | req->sv1 = newSVsv (fh); |
802 | req->sv1 = newSVsv (fh); |
767 | req->int1 = fd; |
803 | req->int1 = fd; |
768 | req->offs = SvVAL64 (offset); |
804 | req->offs = offset; |
769 | req->size = length; |
805 | req->size = length; |
770 | |
806 | |
771 | REQ_SEND; |
807 | REQ_SEND; |
772 | } |
808 | } |
773 | |
809 | |
… | |
… | |
889 | req->type = EIO_FCHOWN; |
925 | req->type = EIO_FCHOWN; |
890 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
926 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
891 | } |
927 | } |
892 | |
928 | |
893 | REQ_SEND; |
929 | REQ_SEND; |
|
|
930 | } |
|
|
931 | |
|
|
932 | void |
|
|
933 | aio_readdirx (SV8 *pathname, IV flags, SV *callback=&PL_sv_undef) |
|
|
934 | PPCODE: |
|
|
935 | { |
|
|
936 | dREQ; |
|
|
937 | |
|
|
938 | req->type = EIO_READDIR; |
|
|
939 | req->sv1 = newSVsv (pathname); |
|
|
940 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
941 | req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1; |
|
|
942 | |
|
|
943 | if (flags & EIO_READDIR_DENTS) |
|
|
944 | req->int1 |= EIO_READDIR_CUSTOM2; |
|
|
945 | |
|
|
946 | REQ_SEND; |
894 | } |
947 | } |
895 | |
948 | |
896 | void |
949 | void |
897 | aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
950 | aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
898 | ALIAS: |
951 | ALIAS: |
… | |
… | |
1026 | |
1079 | |
1027 | int |
1080 | int |
1028 | poll_fileno() |
1081 | poll_fileno() |
1029 | PROTOTYPE: |
1082 | PROTOTYPE: |
1030 | CODE: |
1083 | CODE: |
1031 | RETVAL = respipe [0]; |
1084 | RETVAL = s_epipe_fd (&respipe); |
1032 | OUTPUT: |
1085 | OUTPUT: |
1033 | RETVAL |
1086 | RETVAL |
1034 | |
1087 | |
1035 | int |
1088 | int |
1036 | poll_cb(...) |
1089 | poll_cb(...) |
… | |
… | |
1076 | CODE: |
1129 | CODE: |
1077 | RETVAL = eio_nthreads (); |
1130 | RETVAL = eio_nthreads (); |
1078 | OUTPUT: |
1131 | OUTPUT: |
1079 | RETVAL |
1132 | RETVAL |
1080 | |
1133 | |
|
|
1134 | int |
|
|
1135 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
|
|
1136 | PROTOTYPE: $$$$ |
|
|
1137 | CODE: |
|
|
1138 | #if _XOPEN_SOURCE >= 600 && !NO_FADVISE |
|
|
1139 | RETVAL = posix_fadvise (fh, offset, length, advice); |
|
|
1140 | #else |
|
|
1141 | RETVAL = errno = ENOSYS; |
|
|
1142 | #endif |
|
|
1143 | OUTPUT: |
|
|
1144 | RETVAL |
|
|
1145 | |
|
|
1146 | ssize_t |
|
|
1147 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
|
|
1148 | PROTOTYPE: $$$$ |
|
|
1149 | CODE: |
|
|
1150 | eio_sendfile_sync (ofh, ifh, offset, count); |
|
|
1151 | |
1081 | void _on_next_submit (SV *cb) |
1152 | void _on_next_submit (SV *cb) |
1082 | CODE: |
1153 | CODE: |
1083 | SvREFCNT_dec (on_next_submit); |
1154 | SvREFCNT_dec (on_next_submit); |
1084 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1155 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1085 | |
1156 | |
… | |
… | |
1099 | if (GIMME_V != G_VOID) |
1170 | if (GIMME_V != G_VOID) |
1100 | XPUSHs (req->callback ? sv_2mortal (newRV_inc (req->callback)) : &PL_sv_undef); |
1171 | XPUSHs (req->callback ? sv_2mortal (newRV_inc (req->callback)) : &PL_sv_undef); |
1101 | |
1172 | |
1102 | if (items > 1) |
1173 | if (items > 1) |
1103 | { |
1174 | { |
1104 | SV *cb_cv = get_cb (callback); |
1175 | SV *cb_cv =get_cb (callback); |
1105 | |
1176 | |
1106 | SvREFCNT_dec (req->callback); |
1177 | SvREFCNT_dec (req->callback); |
1107 | req->callback = SvREFCNT_inc (cb_cv); |
1178 | req->callback = SvREFCNT_inc (cb_cv); |
1108 | } |
1179 | } |
1109 | } |
1180 | } |
… | |
… | |
1146 | AV *av; |
1217 | AV *av; |
1147 | |
1218 | |
1148 | grp->errorno = errno; |
1219 | grp->errorno = errno; |
1149 | |
1220 | |
1150 | av = newAV (); |
1221 | av = newAV (); |
|
|
1222 | av_extend (av, items - 1); |
1151 | |
1223 | |
1152 | for (i = 1; i < items; ++i ) |
1224 | for (i = 1; i < items; ++i ) |
1153 | av_push (av, newSVsv (ST (i))); |
1225 | av_push (av, newSVsv (ST (i))); |
1154 | |
1226 | |
1155 | SvREFCNT_dec (grp->sv1); |
1227 | SvREFCNT_dec (grp->sv1); |