… | |
… | |
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> |
16 | #include <limits.h> |
17 | #include <limits.h> |
17 | #include <fcntl.h> |
18 | #include <fcntl.h> |
18 | #include <sched.h> |
19 | #include <sched.h> |
|
|
20 | |
|
|
21 | #if _POSIX_MEMLOCK || _POSIX_MAPPED_FILES |
|
|
22 | # include <sys/mman.h> |
|
|
23 | #endif |
19 | |
24 | |
20 | /* perl namespace pollution */ |
25 | /* perl namespace pollution */ |
21 | #undef VERSION |
26 | #undef VERSION |
22 | |
27 | |
23 | #ifdef _WIN32 |
28 | #ifdef _WIN32 |
… | |
… | |
99 | #define expect_false(expr) expect ((expr) != 0, 0) |
104 | #define expect_false(expr) expect ((expr) != 0, 0) |
100 | #define expect_true(expr) expect ((expr) != 0, 1) |
105 | #define expect_true(expr) expect ((expr) != 0, 1) |
101 | |
106 | |
102 | /*****************************************************************************/ |
107 | /*****************************************************************************/ |
103 | |
108 | |
104 | static HV *stash; |
|
|
105 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
109 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
106 | typedef int aio_rfd; /* read file desriptor */ |
110 | typedef int aio_rfd; /* read file desriptor */ |
107 | typedef int aio_wfd; /* write file descriptor */ |
111 | typedef int aio_wfd; /* write file descriptor */ |
108 | |
112 | |
109 | #define AIO_REQ_KLASS "IO::AIO::REQ" |
113 | static HV *aio_stash, *aio_req_stash, *aio_grp_stash; |
110 | #define AIO_GRP_KLASS "IO::AIO::GRP" |
|
|
111 | |
114 | |
112 | #define EIO_REQ_MEMBERS \ |
115 | #define EIO_REQ_MEMBERS \ |
113 | SV *callback; \ |
116 | SV *callback; \ |
114 | SV *sv1, *sv2; \ |
117 | SV *sv1, *sv2; \ |
115 | STRLEN stroffset; \ |
118 | STRLEN stroffset; \ |
… | |
… | |
121 | |
124 | |
122 | #ifndef POSIX_FADV_NORMAL |
125 | #ifndef POSIX_FADV_NORMAL |
123 | # define POSIX_FADV_NORMAL 0 |
126 | # define POSIX_FADV_NORMAL 0 |
124 | # define NO_FADVISE 1 |
127 | # define NO_FADVISE 1 |
125 | #endif |
128 | #endif |
126 | |
|
|
127 | #ifndef POSIX_FADV_SEQUENTIAL |
129 | #ifndef POSIX_FADV_SEQUENTIAL |
128 | # define POSIX_FADV_SEQUENTIAL 0 |
130 | # define POSIX_FADV_SEQUENTIAL 0 |
129 | #endif |
131 | #endif |
130 | |
|
|
131 | #ifndef POSIX_FADV_RANDOM |
132 | #ifndef POSIX_FADV_RANDOM |
132 | # define POSIX_FADV_RANDOM 0 |
133 | # define POSIX_FADV_RANDOM 0 |
133 | #endif |
134 | #endif |
134 | |
|
|
135 | #ifndef POSIX_FADV_NOREUSE |
135 | #ifndef POSIX_FADV_NOREUSE |
136 | # define POSIX_FADV_NOREUSE 0 |
136 | # define POSIX_FADV_NOREUSE 0 |
137 | #endif |
137 | #endif |
138 | |
|
|
139 | #ifndef POSIX_FADV_WILLNEED |
138 | #ifndef POSIX_FADV_WILLNEED |
140 | # define POSIX_FADV_WILLNEED 0 |
139 | # define POSIX_FADV_WILLNEED 0 |
141 | #endif |
140 | #endif |
142 | |
|
|
143 | #ifndef POSIX_FADV_DONTNEED |
141 | #ifndef POSIX_FADV_DONTNEED |
144 | # define POSIX_FADV_DONTNEED 0 |
142 | # define POSIX_FADV_DONTNEED 0 |
|
|
143 | #endif |
|
|
144 | |
|
|
145 | #if _XOPEN_SOURCE < 600 || NO_FADVISE |
|
|
146 | # define posix_fadvise(a,b,c,d) errno = ENOSYS /* also return ENOSYS */ |
|
|
147 | #endif |
|
|
148 | |
|
|
149 | #ifndef POSIX_MADV_NORMAL |
|
|
150 | # define POSIX_MADV_NORMAL 0 |
|
|
151 | # define NO_MADVISE 1 |
|
|
152 | #endif |
|
|
153 | #ifndef POSIX_MADV_SEQUENTIAL |
|
|
154 | # define POSIX_MADV_SEQUENTIAL 0 |
|
|
155 | #endif |
|
|
156 | #ifndef POSIX_MADV_RANDOM |
|
|
157 | # define POSIX_MADV_RANDOM 0 |
|
|
158 | #endif |
|
|
159 | #ifndef POSIX_MADV_WILLNEED |
|
|
160 | # define POSIX_MADV_WILLNEED 0 |
|
|
161 | #endif |
|
|
162 | #ifndef POSIX_MADV_DONTNEED |
|
|
163 | # define POSIX_MADV_DONTNEED 0 |
|
|
164 | #endif |
|
|
165 | |
|
|
166 | #if _XOPEN_SOURCE < 600 || NO_MADVISE |
|
|
167 | # define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */ |
|
|
168 | #endif |
|
|
169 | |
|
|
170 | #ifndef PROT_NONE |
|
|
171 | # define PROT_NONE 0 |
|
|
172 | #endif |
|
|
173 | #ifndef PROT_READ |
|
|
174 | # define PROT_READ 0 |
|
|
175 | #endif |
|
|
176 | #ifndef PROT_WRITE |
|
|
177 | # define PROT_READ 0 |
|
|
178 | #endif |
|
|
179 | #ifndef PROT_EXEC |
|
|
180 | # define PROT_EXEC 0 |
|
|
181 | #endif |
|
|
182 | |
|
|
183 | #ifndef ST_NODEV |
|
|
184 | # define ST_NODEV 0 |
|
|
185 | #endif |
|
|
186 | #ifndef ST_NOEXEC |
|
|
187 | # define ST_NOEXEC 0 |
|
|
188 | #endif |
|
|
189 | #ifndef ST_SYNCHRONOUS |
|
|
190 | # define ST_SYNCHRONOUS 0 |
|
|
191 | #endif |
|
|
192 | #ifndef ST_MANDLOCK |
|
|
193 | # define ST_MANDLOCK 0 |
|
|
194 | #endif |
|
|
195 | #ifndef ST_WRITE |
|
|
196 | # define ST_WRITE 0 |
|
|
197 | #endif |
|
|
198 | #ifndef ST_APPEND |
|
|
199 | # define ST_APPEND 0 |
|
|
200 | #endif |
|
|
201 | #ifndef ST_IMMUTABLE |
|
|
202 | # define ST_IMMUTABLE 0 |
|
|
203 | #endif |
|
|
204 | #ifndef ST_NOATIME |
|
|
205 | # define ST_NOATIME 0 |
|
|
206 | #endif |
|
|
207 | #ifndef ST_NODIRATIME |
|
|
208 | # define ST_NODIRATIME 0 |
|
|
209 | #endif |
|
|
210 | #ifndef ST_RELATIME |
|
|
211 | # define ST_RELATIME 0 |
|
|
212 | #endif |
|
|
213 | |
|
|
214 | #ifndef MAP_ANONYMOUS |
|
|
215 | # ifdef MAP_ANON |
|
|
216 | # define MAP_ANONYMOUS MAP_ANON |
|
|
217 | # else |
|
|
218 | # define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ |
|
|
219 | # endif |
|
|
220 | #endif |
|
|
221 | #ifndef MAP_HUGETLB |
|
|
222 | # define MAP_HUGETLB 0 |
|
|
223 | #endif |
|
|
224 | #ifndef MAP_LOCKED |
|
|
225 | # define MAP_LOCKED 0 |
|
|
226 | #endif |
|
|
227 | #ifndef MAP_NORESERVE |
|
|
228 | # define MAP_NORESERVE 0 |
|
|
229 | #endif |
|
|
230 | #ifndef MAP_POPULATE |
|
|
231 | # define MAP_POPULATE 0 |
|
|
232 | #endif |
|
|
233 | #ifndef MAP_NONBLOCK |
|
|
234 | # define MAP_NONBLOCK 0 |
|
|
235 | #endif |
|
|
236 | |
|
|
237 | #ifndef PAGESIZE |
|
|
238 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
145 | #endif |
239 | #endif |
146 | |
240 | |
147 | static int req_invoke (eio_req *req); |
241 | static int req_invoke (eio_req *req); |
148 | #define EIO_FINISH(req) req_invoke (req) |
242 | #define EIO_FINISH(req) req_invoke (req) |
149 | static void req_destroy (eio_req *grp); |
243 | static void req_destroy (eio_req *grp); |
… | |
… | |
178 | /* read any signals sent by the worker threads */ |
272 | /* read any signals sent by the worker threads */ |
179 | s_epipe_drain (&respipe); |
273 | s_epipe_drain (&respipe); |
180 | } |
274 | } |
181 | |
275 | |
182 | /* must be called at most once */ |
276 | /* must be called at most once */ |
183 | static SV *req_sv (aio_req req, const char *klass) |
277 | static SV *req_sv (aio_req req, HV *stash) |
184 | { |
278 | { |
185 | if (!req->self) |
279 | if (!req->self) |
186 | { |
280 | { |
187 | req->self = (SV *)newHV (); |
281 | req->self = (SV *)newHV (); |
188 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
282 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
189 | } |
283 | } |
190 | |
284 | |
191 | return sv_2mortal (sv_bless (newRV_inc (req->self), gv_stashpv (klass, 1))); |
285 | return sv_2mortal (sv_bless (newRV_inc (req->self), stash)); |
192 | } |
286 | } |
193 | |
287 | |
194 | static aio_req SvAIO_REQ (SV *sv) |
288 | static aio_req SvAIO_REQ (SV *sv) |
195 | { |
289 | { |
196 | MAGIC *mg; |
290 | MAGIC *mg; |
197 | |
291 | |
198 | if (!sv_derived_from (sv, AIO_REQ_KLASS) || !SvROK (sv)) |
292 | if (!SvROK (sv) |
|
|
293 | || (SvSTASH (SvRV (sv)) != aio_grp_stash |
|
|
294 | && SvSTASH (SvRV (sv)) != aio_req_stash |
|
|
295 | && !sv_derived_from (sv, "IO::AIO::REQ"))) |
199 | croak ("object of class " AIO_REQ_KLASS " expected"); |
296 | croak ("object of class IO::AIO::REQ expected"); |
200 | |
297 | |
201 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
298 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
202 | |
299 | |
203 | return mg ? (aio_req)mg->mg_ptr : 0; |
300 | return mg ? (aio_req)mg->mg_ptr : 0; |
204 | } |
301 | } |
… | |
… | |
210 | dSP; |
307 | dSP; |
211 | |
308 | |
212 | ENTER; |
309 | ENTER; |
213 | SAVETMPS; |
310 | SAVETMPS; |
214 | PUSHMARK (SP); |
311 | PUSHMARK (SP); |
215 | XPUSHs (req_sv (grp, AIO_GRP_KLASS)); |
312 | XPUSHs (req_sv (grp, aio_grp_stash)); |
216 | PUTBACK; |
313 | PUTBACK; |
217 | call_sv (grp->sv2, G_VOID | G_EVAL | G_KEEPERR); |
314 | call_sv (grp->sv2, G_VOID | G_EVAL | G_KEEPERR); |
218 | SPAGAIN; |
315 | SPAGAIN; |
219 | FREETMPS; |
316 | FREETMPS; |
220 | LEAVE; |
317 | LEAVE; |
… | |
… | |
238 | } |
335 | } |
239 | } |
336 | } |
240 | |
337 | |
241 | static int req_invoke (eio_req *req) |
338 | static int req_invoke (eio_req *req) |
242 | { |
339 | { |
243 | dSP; |
|
|
244 | |
|
|
245 | if (req->flags & FLAG_SV2_RO_OFF) |
340 | if (req->flags & FLAG_SV2_RO_OFF) |
246 | SvREADONLY_off (req->sv2); |
341 | SvREADONLY_off (req->sv2); |
247 | |
342 | |
248 | if (!EIO_CANCELLED (req) && req->callback) |
343 | if (!EIO_CANCELLED (req) && req->callback) |
249 | { |
344 | { |
|
|
345 | dSP; |
|
|
346 | static SV *sv_result_cache; /* caches the result integer SV */ |
|
|
347 | SV *sv_result; |
|
|
348 | |
250 | ENTER; |
349 | ENTER; |
251 | SAVETMPS; |
350 | SAVETMPS; |
252 | PUSHMARK (SP); |
351 | PUSHMARK (SP); |
253 | EXTEND (SP, 1); |
352 | EXTEND (SP, 1); |
|
|
353 | |
|
|
354 | /* do not recreate the result IV from scratch each time */ |
|
|
355 | if (expect_true (sv_result_cache)) |
|
|
356 | { |
|
|
357 | sv_result = sv_result_cache; sv_result_cache = 0; |
|
|
358 | SvIV_set (sv_result, req->result); |
|
|
359 | } |
|
|
360 | else |
|
|
361 | { |
|
|
362 | sv_result = newSViv (req->result); |
|
|
363 | SvREADONLY_on (sv_result); |
|
|
364 | } |
254 | |
365 | |
255 | switch (req->type) |
366 | switch (req->type) |
256 | { |
367 | { |
257 | case EIO_READDIR: |
368 | case EIO_READDIR: |
258 | { |
369 | { |
… | |
… | |
326 | int flags = req->int1 & (O_RDONLY | O_WRONLY | O_RDWR); |
437 | int flags = req->int1 & (O_RDONLY | O_WRONLY | O_RDWR); |
327 | char sym [64]; |
438 | char sym [64]; |
328 | int symlen; |
439 | int symlen; |
329 | |
440 | |
330 | symlen = snprintf (sym, sizeof (sym), "fd#%d", (int)req->result); |
441 | symlen = snprintf (sym, sizeof (sym), "fd#%d", (int)req->result); |
331 | gv_init (gv, stash, sym, symlen, 0); |
442 | gv_init (gv, aio_stash, sym, symlen, 0); |
332 | |
443 | |
333 | symlen = snprintf ( |
444 | symlen = snprintf ( |
334 | sym, |
445 | sym, |
335 | sizeof (sym), |
446 | sizeof (sym), |
336 | "%s&=%d", |
447 | "%s&=%d", |
… | |
… | |
344 | |
455 | |
345 | PUSHs (fh); |
456 | PUSHs (fh); |
346 | } |
457 | } |
347 | break; |
458 | break; |
348 | |
459 | |
|
|
460 | case EIO_STATVFS: |
|
|
461 | case EIO_FSTATVFS: |
|
|
462 | { |
|
|
463 | SV *rv = &PL_sv_undef; |
|
|
464 | |
|
|
465 | if (req->result >= 0) |
|
|
466 | { |
|
|
467 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
|
|
468 | HV *hv = newHV (); |
|
|
469 | |
|
|
470 | rv = sv_2mortal (newRV_noinc ((SV *)hv)); |
|
|
471 | |
|
|
472 | hv_store (hv, "bsize" , sizeof ("bsize" ) - 1, newSVval64 (f->f_bsize ), 0); |
|
|
473 | hv_store (hv, "frsize" , sizeof ("frsize" ) - 1, newSVval64 (f->f_frsize ), 0); |
|
|
474 | hv_store (hv, "blocks" , sizeof ("blocks" ) - 1, newSVval64 (f->f_blocks ), 0); |
|
|
475 | hv_store (hv, "bfree" , sizeof ("bfree" ) - 1, newSVval64 (f->f_bfree ), 0); |
|
|
476 | hv_store (hv, "bavail" , sizeof ("bavail" ) - 1, newSVval64 (f->f_bavail ), 0); |
|
|
477 | hv_store (hv, "files" , sizeof ("files" ) - 1, newSVval64 (f->f_files ), 0); |
|
|
478 | hv_store (hv, "ffree" , sizeof ("ffree" ) - 1, newSVval64 (f->f_ffree ), 0); |
|
|
479 | hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); |
|
|
480 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); |
|
|
481 | hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); |
|
|
482 | hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); |
|
|
483 | } |
|
|
484 | |
|
|
485 | PUSHs (rv); |
|
|
486 | } |
|
|
487 | |
|
|
488 | break; |
|
|
489 | |
349 | case EIO_GROUP: |
490 | case EIO_GROUP: |
350 | req->int1 = 2; /* mark group as finished */ |
491 | req->int1 = 2; /* mark group as finished */ |
351 | |
492 | |
352 | if (req->sv1) |
493 | if (req->sv1) |
353 | { |
494 | { |
… | |
… | |
373 | case EIO_LSTAT: |
514 | case EIO_LSTAT: |
374 | case EIO_FSTAT: |
515 | case EIO_FSTAT: |
375 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
516 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
376 | PL_laststatval = req->result; |
517 | PL_laststatval = req->result; |
377 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
518 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
378 | PUSHs (sv_2mortal (newSViv (req->result))); |
519 | PUSHs (sv_result); |
379 | break; |
520 | break; |
380 | |
521 | |
381 | case EIO_READ: |
522 | case EIO_READ: |
382 | { |
523 | { |
383 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
524 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
384 | *SvEND (req->sv2) = 0; |
525 | *SvEND (req->sv2) = 0; |
385 | SvPOK_only (req->sv2); |
526 | SvPOK_only (req->sv2); |
386 | SvSETMAGIC (req->sv2); |
527 | SvSETMAGIC (req->sv2); |
387 | PUSHs (sv_2mortal (newSViv (req->result))); |
528 | PUSHs (sv_result); |
388 | } |
529 | } |
389 | break; |
530 | break; |
390 | |
531 | |
391 | case EIO_DUP2: |
532 | case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), su fudge result value */ |
392 | if (req->result > 0) |
533 | if (req->result > 0) |
393 | req->result = 0; |
534 | SvIV_set (sv_result, 0); |
394 | /* FALLTHROUGH */ |
535 | /* FALLTHROUGH */ |
395 | |
536 | |
396 | default: |
537 | default: |
397 | PUSHs (sv_2mortal (newSViv (req->result))); |
538 | PUSHs (sv_result); |
398 | break; |
539 | break; |
399 | } |
540 | } |
400 | |
541 | |
401 | errno = req->errorno; |
542 | errno = req->errorno; |
402 | |
543 | |
403 | PUTBACK; |
544 | PUTBACK; |
404 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
545 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
405 | SPAGAIN; |
546 | SPAGAIN; |
|
|
547 | |
|
|
548 | if (expect_false (SvREFCNT (sv_result) != 1 || sv_result_cache)) |
|
|
549 | SvREFCNT_dec (sv_result); |
|
|
550 | else |
|
|
551 | sv_result_cache = sv_result; |
406 | |
552 | |
407 | FREETMPS; |
553 | FREETMPS; |
408 | LEAVE; |
554 | LEAVE; |
409 | |
555 | |
410 | PUTBACK; |
556 | PUTBACK; |
… | |
… | |
485 | |
631 | |
486 | static void atfork_child (void) |
632 | static void atfork_child (void) |
487 | { |
633 | { |
488 | create_respipe (); |
634 | create_respipe (); |
489 | } |
635 | } |
|
|
636 | |
|
|
637 | /*****************************************************************************/ |
|
|
638 | |
|
|
639 | #if !_POSIX_MAPPED_FILES |
|
|
640 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
|
|
641 | # define munmap(addr,length) (errno = ENOSYS, -1) |
|
|
642 | # define mprotect(addr,len,prot) (errno = ENOSYS, -1) |
|
|
643 | #endif |
|
|
644 | |
|
|
645 | #define MMAP_MAGIC PERL_MAGIC_ext |
|
|
646 | |
|
|
647 | static int |
|
|
648 | mmap_free (pTHX_ SV *sv, MAGIC *mg) |
|
|
649 | { |
|
|
650 | int old_errno = errno; |
|
|
651 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
|
|
652 | errno = old_errno; |
|
|
653 | |
|
|
654 | mg->mg_obj = 0; /* just in case */ |
|
|
655 | |
|
|
656 | SvREADONLY_off (sv); |
|
|
657 | |
|
|
658 | if (SvPVX (sv) != mg->mg_ptr) |
|
|
659 | croak ("ERROR: IO::AIO::mmap-mapped scalar changed location, detected"); |
|
|
660 | |
|
|
661 | SvCUR_set (sv, 0); |
|
|
662 | SvPVX (sv) = 0; |
|
|
663 | SvOK_off (sv); |
|
|
664 | |
|
|
665 | return 0; |
|
|
666 | } |
|
|
667 | |
|
|
668 | static MGVTBL mmap_vtbl = { |
|
|
669 | 0, 0, 0, 0, mmap_free |
|
|
670 | }; |
|
|
671 | |
|
|
672 | /*****************************************************************************/ |
490 | |
673 | |
491 | static SV * |
674 | static SV * |
492 | get_cb (SV *cb_sv) |
675 | get_cb (SV *cb_sv) |
493 | { |
676 | { |
494 | SvGETMAGIC (cb_sv); |
677 | SvGETMAGIC (cb_sv); |
… | |
… | |
514 | PUTBACK; \ |
697 | PUTBACK; \ |
515 | req_submit (req); \ |
698 | req_submit (req); \ |
516 | SPAGAIN; \ |
699 | SPAGAIN; \ |
517 | \ |
700 | \ |
518 | if (GIMME_V != G_VOID) \ |
701 | if (GIMME_V != G_VOID) \ |
519 | XPUSHs (req_sv (req, AIO_REQ_KLASS)); |
702 | XPUSHs (req_sv (req, aio_req_stash)); |
520 | |
703 | |
521 | MODULE = IO::AIO PACKAGE = IO::AIO |
704 | MODULE = IO::AIO PACKAGE = IO::AIO |
522 | |
705 | |
523 | PROTOTYPES: ENABLE |
706 | PROTOTYPES: ENABLE |
524 | |
707 | |
… | |
… | |
526 | { |
709 | { |
527 | static const struct { |
710 | static const struct { |
528 | const char *name; |
711 | const char *name; |
529 | IV iv; |
712 | IV iv; |
530 | } *civ, const_iv[] = { |
713 | } *civ, const_iv[] = { |
531 | # define const_iv(name, value) { # name, (IV) value }, |
714 | # define const_niv(name, value) { # name, (IV) value }, |
|
|
715 | # define const_iv(name) { # name, (IV) name }, |
532 | # define const_eio(name) { # name, (IV) EIO_ ## name }, |
716 | # define const_eio(name) { # name, (IV) EIO_ ## name }, |
533 | const_iv (EXDEV , EXDEV) |
717 | const_iv (EXDEV) |
534 | const_iv (ENOSYS , ENOSYS) |
718 | const_iv (ENOSYS) |
535 | const_iv (O_RDONLY, O_RDONLY) |
719 | const_iv (O_RDONLY) |
536 | const_iv (O_WRONLY, O_WRONLY) |
720 | const_iv (O_WRONLY) |
|
|
721 | const_iv (O_RDWR) |
537 | const_iv (O_CREAT , O_CREAT) |
722 | const_iv (O_CREAT) |
538 | const_iv (O_TRUNC , O_TRUNC) |
723 | const_iv (O_TRUNC) |
|
|
724 | const_iv (O_EXCL) |
|
|
725 | const_iv (O_APPEND) |
539 | #ifndef _WIN32 |
726 | #ifndef _WIN32 |
540 | const_iv (S_IFIFO , S_IFIFO) |
727 | const_iv (S_IFIFO) |
541 | #endif |
728 | #endif |
542 | const_iv (FADV_NORMAL , POSIX_FADV_NORMAL) |
729 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
543 | const_iv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
730 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
544 | const_iv (FADV_RANDOM , POSIX_FADV_RANDOM) |
731 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
545 | const_iv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
732 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
546 | const_iv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
733 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
547 | const_iv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
734 | const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
|
|
735 | |
|
|
736 | const_niv (MADV_NORMAL , POSIX_MADV_NORMAL) |
|
|
737 | const_niv (MADV_SEQUENTIAL, POSIX_MADV_SEQUENTIAL) |
|
|
738 | const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) |
|
|
739 | const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) |
|
|
740 | const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) |
|
|
741 | |
|
|
742 | const_iv (ST_RDONLY) |
|
|
743 | const_iv (ST_NOSUID) |
|
|
744 | const_iv (ST_NODEV) |
|
|
745 | const_iv (ST_NOEXEC) |
|
|
746 | const_iv (ST_SYNCHRONOUS) |
|
|
747 | const_iv (ST_MANDLOCK) |
|
|
748 | const_iv (ST_WRITE) |
|
|
749 | const_iv (ST_APPEND) |
|
|
750 | const_iv (ST_IMMUTABLE) |
|
|
751 | const_iv (ST_NOATIME) |
|
|
752 | const_iv (ST_NODIRATIME) |
|
|
753 | const_iv (ST_RELATIME) |
|
|
754 | |
|
|
755 | const_iv (PROT_NONE) |
|
|
756 | const_iv (PROT_EXEC) |
|
|
757 | const_iv (PROT_READ) |
|
|
758 | const_iv (PROT_WRITE) |
|
|
759 | |
|
|
760 | /*const_iv (MAP_FIXED)*/ |
|
|
761 | const_iv (MAP_PRIVATE) |
|
|
762 | const_iv (MAP_SHARED) |
|
|
763 | const_iv (MAP_ANONYMOUS) |
|
|
764 | |
|
|
765 | /* linuxish */ |
|
|
766 | const_iv (MAP_HUGETLB) |
|
|
767 | const_iv (MAP_LOCKED) |
|
|
768 | const_iv (MAP_NORESERVE) |
|
|
769 | const_iv (MAP_POPULATE) |
|
|
770 | const_iv (MAP_NONBLOCK) |
|
|
771 | |
|
|
772 | const_eio (MCL_FUTURE) |
|
|
773 | const_eio (MCL_CURRENT) |
|
|
774 | |
|
|
775 | const_eio (MS_ASYNC) |
|
|
776 | const_eio (MS_INVALIDATE) |
|
|
777 | const_eio (MS_SYNC) |
|
|
778 | |
|
|
779 | const_eio (MT_MODIFY) |
548 | |
780 | |
549 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
781 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
550 | const_eio (SYNC_FILE_RANGE_WRITE) |
782 | const_eio (SYNC_FILE_RANGE_WRITE) |
551 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
783 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
552 | |
784 | |
… | |
… | |
564 | const_eio (DT_LNK) |
796 | const_eio (DT_LNK) |
565 | const_eio (DT_SOCK) |
797 | const_eio (DT_SOCK) |
566 | const_eio (DT_WHT) |
798 | const_eio (DT_WHT) |
567 | }; |
799 | }; |
568 | |
800 | |
569 | stash = gv_stashpv ("IO::AIO", 1); |
801 | aio_stash = gv_stashpv ("IO::AIO" , 1); |
|
|
802 | aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); |
|
|
803 | aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); |
570 | |
804 | |
571 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
805 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
572 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
806 | newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv)); |
|
|
807 | |
|
|
808 | newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); |
573 | |
809 | |
574 | create_respipe (); |
810 | create_respipe (); |
575 | |
811 | |
576 | if (eio_init (want_poll, done_poll) < 0) |
812 | if (eio_init (want_poll, done_poll) < 0) |
577 | croak ("IO::AIO: unable to initialise eio library"); |
813 | croak ("IO::AIO: unable to initialise eio library"); |
… | |
… | |
616 | CODE: |
852 | CODE: |
617 | max_outstanding = maxreqs; |
853 | max_outstanding = maxreqs; |
618 | |
854 | |
619 | void |
855 | void |
620 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
856 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
621 | PROTOTYPE: $$$;$ |
|
|
622 | PPCODE: |
857 | PPCODE: |
623 | { |
858 | { |
624 | dREQ; |
859 | dREQ; |
625 | |
860 | |
626 | req->type = EIO_OPEN; |
861 | req->type = EIO_OPEN; |
… | |
… | |
632 | REQ_SEND; |
867 | REQ_SEND; |
633 | } |
868 | } |
634 | |
869 | |
635 | void |
870 | void |
636 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
871 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
637 | PROTOTYPE: $;$ |
|
|
638 | ALIAS: |
872 | ALIAS: |
639 | aio_fsync = EIO_FSYNC |
873 | aio_fsync = EIO_FSYNC |
640 | aio_fdatasync = EIO_FDATASYNC |
874 | aio_fdatasync = EIO_FDATASYNC |
641 | PPCODE: |
875 | PPCODE: |
642 | { |
876 | { |
… | |
… | |
650 | REQ_SEND (req); |
884 | REQ_SEND (req); |
651 | } |
885 | } |
652 | |
886 | |
653 | void |
887 | void |
654 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
888 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
655 | PROTOTYPE: $$$$;$ |
|
|
656 | PPCODE: |
889 | PPCODE: |
657 | { |
890 | { |
658 | int fd = s_fileno_croak (fh, 0); |
891 | int fd = s_fileno_croak (fh, 0); |
659 | dREQ; |
892 | dREQ; |
660 | |
893 | |
… | |
… | |
668 | REQ_SEND (req); |
901 | REQ_SEND (req); |
669 | } |
902 | } |
670 | |
903 | |
671 | void |
904 | void |
672 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
905 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
673 | PROTOTYPE: $;$ |
|
|
674 | PPCODE: |
906 | PPCODE: |
675 | { |
907 | { |
676 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
908 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
677 | int fd = s_fileno_croak (fh, 0); |
909 | int fd = s_fileno_croak (fh, 0); |
678 | dREQ; |
910 | dREQ; |
… | |
… | |
700 | void |
932 | void |
701 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
933 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
702 | ALIAS: |
934 | ALIAS: |
703 | aio_read = EIO_READ |
935 | aio_read = EIO_READ |
704 | aio_write = EIO_WRITE |
936 | aio_write = EIO_WRITE |
705 | PROTOTYPE: $$$$$;$ |
|
|
706 | PPCODE: |
937 | PPCODE: |
707 | { |
938 | { |
708 | STRLEN svlen; |
939 | STRLEN svlen; |
709 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
940 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
710 | char *svptr = SvPVbyte (data, svlen); |
941 | char *svptr = SvPVbyte (data, svlen); |
… | |
… | |
751 | } |
982 | } |
752 | } |
983 | } |
753 | |
984 | |
754 | void |
985 | void |
755 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
986 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
756 | PROTOTYPE: $$;$ |
|
|
757 | PPCODE: |
987 | PPCODE: |
758 | { |
988 | { |
759 | SV *data; |
989 | SV *data; |
760 | dREQ; |
990 | dREQ; |
761 | |
991 | |
… | |
… | |
766 | REQ_SEND; |
996 | REQ_SEND; |
767 | } |
997 | } |
768 | |
998 | |
769 | void |
999 | void |
770 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
1000 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
771 | PROTOTYPE: $$$$;$ |
|
|
772 | PPCODE: |
1001 | PPCODE: |
773 | { |
1002 | { |
774 | int ifd = s_fileno_croak (in_fh , 0); |
1003 | int ifd = s_fileno_croak (in_fh , 0); |
775 | int ofd = s_fileno_croak (out_fh, 1); |
1004 | int ofd = s_fileno_croak (out_fh, 1); |
776 | dREQ; |
1005 | dREQ; |
… | |
… | |
786 | REQ_SEND; |
1015 | REQ_SEND; |
787 | } |
1016 | } |
788 | |
1017 | |
789 | void |
1018 | void |
790 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
1019 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
791 | PROTOTYPE: $$$;$ |
|
|
792 | PPCODE: |
1020 | PPCODE: |
793 | { |
1021 | { |
794 | int fd = s_fileno_croak (fh, 0); |
1022 | int fd = s_fileno_croak (fh, 0); |
795 | dREQ; |
1023 | dREQ; |
796 | |
1024 | |
… | |
… | |
804 | } |
1032 | } |
805 | |
1033 | |
806 | void |
1034 | void |
807 | aio_stat (SV8 *fh_or_path, SV *callback=&PL_sv_undef) |
1035 | aio_stat (SV8 *fh_or_path, SV *callback=&PL_sv_undef) |
808 | ALIAS: |
1036 | ALIAS: |
809 | aio_stat = EIO_STAT |
1037 | aio_stat = EIO_STAT |
810 | aio_lstat = EIO_LSTAT |
1038 | aio_lstat = EIO_LSTAT |
|
|
1039 | aio_statvfs = EIO_STATVFS |
811 | PPCODE: |
1040 | PPCODE: |
812 | { |
1041 | { |
813 | dREQ; |
1042 | dREQ; |
814 | |
1043 | |
815 | req->sv1 = newSVsv (fh_or_path); |
1044 | req->sv1 = newSVsv (fh_or_path); |
… | |
… | |
819 | req->type = ix; |
1048 | req->type = ix; |
820 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1049 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
821 | } |
1050 | } |
822 | else |
1051 | else |
823 | { |
1052 | { |
824 | req->type = EIO_FSTAT; |
1053 | req->type = ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT; |
825 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
1054 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
826 | } |
1055 | } |
827 | |
1056 | |
828 | REQ_SEND; |
1057 | REQ_SEND; |
829 | } |
1058 | } |
… | |
… | |
992 | |
1221 | |
993 | REQ_SEND; |
1222 | REQ_SEND; |
994 | } |
1223 | } |
995 | |
1224 | |
996 | void |
1225 | void |
|
|
1226 | aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) |
|
|
1227 | ALIAS: |
|
|
1228 | aio_mtouch = EIO_MTOUCH |
|
|
1229 | aio_msync = EIO_MSYNC |
|
|
1230 | PPCODE: |
|
|
1231 | { |
|
|
1232 | STRLEN svlen; |
|
|
1233 | char *svptr = SvPVbyte (data, svlen); |
|
|
1234 | UV len = SvUV (length); |
|
|
1235 | |
|
|
1236 | if (offset < 0) |
|
|
1237 | offset += svlen; |
|
|
1238 | |
|
|
1239 | if (offset < 0 || offset > svlen) |
|
|
1240 | croak ("offset outside of scalar"); |
|
|
1241 | |
|
|
1242 | if (!SvOK (length) || len + offset > svlen) |
|
|
1243 | len = svlen - offset; |
|
|
1244 | |
|
|
1245 | { |
|
|
1246 | dREQ; |
|
|
1247 | |
|
|
1248 | req->type = ix; |
|
|
1249 | req->sv2 = SvREFCNT_inc (data); |
|
|
1250 | req->ptr2 = (char *)svptr + offset; |
|
|
1251 | req->size = len; |
|
|
1252 | req->int1 = flags; |
|
|
1253 | |
|
|
1254 | REQ_SEND; |
|
|
1255 | } |
|
|
1256 | } |
|
|
1257 | |
|
|
1258 | void |
|
|
1259 | aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback=&PL_sv_undef) |
|
|
1260 | PPCODE: |
|
|
1261 | { |
|
|
1262 | STRLEN svlen; |
|
|
1263 | char *svptr = SvPVbyte (data, svlen); |
|
|
1264 | UV len = SvUV (length); |
|
|
1265 | |
|
|
1266 | if (offset < 0) |
|
|
1267 | offset += svlen; |
|
|
1268 | |
|
|
1269 | if (offset < 0 || offset > svlen) |
|
|
1270 | croak ("offset outside of scalar"); |
|
|
1271 | |
|
|
1272 | if (!SvOK (length) || len + offset > svlen) |
|
|
1273 | len = svlen - offset; |
|
|
1274 | |
|
|
1275 | { |
|
|
1276 | dREQ; |
|
|
1277 | |
|
|
1278 | req->type = EIO_MLOCK; |
|
|
1279 | req->sv2 = SvREFCNT_inc (data); |
|
|
1280 | req->ptr2 = (char *)svptr + offset; |
|
|
1281 | req->size = len; |
|
|
1282 | |
|
|
1283 | REQ_SEND; |
|
|
1284 | } |
|
|
1285 | } |
|
|
1286 | |
|
|
1287 | void |
|
|
1288 | aio_mlockall (IV flags, SV *callback=&PL_sv_undef) |
|
|
1289 | PPCODE: |
|
|
1290 | { |
|
|
1291 | dREQ; |
|
|
1292 | |
|
|
1293 | req->type = EIO_MLOCKALL; |
|
|
1294 | req->int1 = flags; |
|
|
1295 | |
|
|
1296 | REQ_SEND; |
|
|
1297 | } |
|
|
1298 | |
|
|
1299 | void |
997 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1300 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
998 | PPCODE: |
1301 | PPCODE: |
999 | { |
1302 | { |
1000 | dREQ; |
1303 | dREQ; |
1001 | |
1304 | |
… | |
… | |
1005 | REQ_SEND; |
1308 | REQ_SEND; |
1006 | } |
1309 | } |
1007 | |
1310 | |
1008 | void |
1311 | void |
1009 | aio_group (SV *callback=&PL_sv_undef) |
1312 | aio_group (SV *callback=&PL_sv_undef) |
1010 | PROTOTYPE: ;$ |
|
|
1011 | PPCODE: |
1313 | PPCODE: |
1012 | { |
1314 | { |
1013 | dREQ; |
1315 | dREQ; |
1014 | |
1316 | |
1015 | req->type = EIO_GROUP; |
1317 | req->type = EIO_GROUP; |
1016 | |
1318 | |
1017 | req_submit (req); |
1319 | req_submit (req); |
1018 | XPUSHs (req_sv (req, AIO_GRP_KLASS)); |
1320 | XPUSHs (req_sv (req, aio_grp_stash)); |
1019 | } |
1321 | } |
1020 | |
1322 | |
1021 | void |
1323 | void |
1022 | aio_nop (SV *callback=&PL_sv_undef) |
1324 | aio_nop (SV *callback=&PL_sv_undef) |
1023 | ALIAS: |
1325 | ALIAS: |
… | |
… | |
1032 | REQ_SEND; |
1334 | REQ_SEND; |
1033 | } |
1335 | } |
1034 | |
1336 | |
1035 | int |
1337 | int |
1036 | aioreq_pri (int pri = 0) |
1338 | aioreq_pri (int pri = 0) |
1037 | PROTOTYPE: ;$ |
|
|
1038 | CODE: |
1339 | CODE: |
1039 | RETVAL = next_pri; |
1340 | RETVAL = next_pri; |
1040 | if (items > 0) |
1341 | if (items > 0) |
1041 | { |
1342 | { |
1042 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
1343 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
… | |
… | |
1054 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
1355 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
1055 | next_pri = nice; |
1356 | next_pri = nice; |
1056 | |
1357 | |
1057 | void |
1358 | void |
1058 | flush () |
1359 | flush () |
1059 | PROTOTYPE: |
|
|
1060 | CODE: |
1360 | CODE: |
1061 | while (eio_nreqs ()) |
1361 | while (eio_nreqs ()) |
1062 | { |
1362 | { |
1063 | poll_wait (); |
1363 | poll_wait (); |
1064 | poll_cb (); |
1364 | poll_cb (); |
1065 | } |
1365 | } |
1066 | |
1366 | |
1067 | int |
1367 | int |
1068 | poll() |
1368 | poll () |
1069 | PROTOTYPE: |
|
|
1070 | CODE: |
1369 | CODE: |
1071 | poll_wait (); |
1370 | poll_wait (); |
1072 | RETVAL = poll_cb (); |
1371 | RETVAL = poll_cb (); |
1073 | OUTPUT: |
1372 | OUTPUT: |
1074 | RETVAL |
1373 | RETVAL |
1075 | |
1374 | |
1076 | int |
1375 | int |
1077 | poll_fileno() |
1376 | poll_fileno () |
1078 | PROTOTYPE: |
|
|
1079 | CODE: |
1377 | CODE: |
1080 | RETVAL = s_epipe_fd (&respipe); |
1378 | RETVAL = s_epipe_fd (&respipe); |
1081 | OUTPUT: |
1379 | OUTPUT: |
1082 | RETVAL |
1380 | RETVAL |
1083 | |
1381 | |
1084 | int |
1382 | int |
1085 | poll_cb(...) |
1383 | poll_cb (...) |
1086 | PROTOTYPE: |
1384 | PROTOTYPE: |
1087 | CODE: |
1385 | CODE: |
1088 | RETVAL = poll_cb (); |
1386 | RETVAL = poll_cb (); |
1089 | OUTPUT: |
1387 | OUTPUT: |
1090 | RETVAL |
1388 | RETVAL |
1091 | |
1389 | |
1092 | void |
1390 | void |
1093 | poll_wait() |
1391 | poll_wait () |
1094 | PROTOTYPE: |
|
|
1095 | CODE: |
1392 | CODE: |
1096 | poll_wait (); |
1393 | poll_wait (); |
1097 | |
1394 | |
1098 | int |
1395 | int |
1099 | nreqs() |
1396 | nreqs () |
1100 | PROTOTYPE: |
|
|
1101 | CODE: |
1397 | CODE: |
1102 | RETVAL = eio_nreqs (); |
1398 | RETVAL = eio_nreqs (); |
1103 | OUTPUT: |
1399 | OUTPUT: |
1104 | RETVAL |
1400 | RETVAL |
1105 | |
1401 | |
1106 | int |
1402 | int |
1107 | nready() |
1403 | nready () |
1108 | PROTOTYPE: |
|
|
1109 | CODE: |
1404 | CODE: |
1110 | RETVAL = eio_nready (); |
1405 | RETVAL = eio_nready (); |
1111 | OUTPUT: |
1406 | OUTPUT: |
1112 | RETVAL |
1407 | RETVAL |
1113 | |
1408 | |
1114 | int |
1409 | int |
1115 | npending() |
1410 | npending () |
1116 | PROTOTYPE: |
|
|
1117 | CODE: |
1411 | CODE: |
1118 | RETVAL = eio_npending (); |
1412 | RETVAL = eio_npending (); |
1119 | OUTPUT: |
1413 | OUTPUT: |
1120 | RETVAL |
1414 | RETVAL |
1121 | |
1415 | |
1122 | int |
1416 | int |
1123 | nthreads() |
1417 | nthreads () |
1124 | PROTOTYPE: |
|
|
1125 | CODE: |
1418 | CODE: |
1126 | RETVAL = eio_nthreads (); |
1419 | RETVAL = eio_nthreads (); |
1127 | OUTPUT: |
1420 | OUTPUT: |
1128 | RETVAL |
1421 | RETVAL |
1129 | |
1422 | |
1130 | int |
1423 | int |
1131 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1424 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
1132 | PROTOTYPE: $$$$ |
|
|
1133 | CODE: |
1425 | CODE: |
1134 | #if _XOPEN_SOURCE >= 600 && !NO_FADVISE |
|
|
1135 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1426 | RETVAL = posix_fadvise (fh, offset, length, advice); |
1136 | #else |
|
|
1137 | RETVAL = errno = ENOSYS; |
|
|
1138 | #endif |
|
|
1139 | OUTPUT: |
1427 | OUTPUT: |
1140 | RETVAL |
1428 | RETVAL |
1141 | |
1429 | |
1142 | ssize_t |
1430 | ssize_t |
1143 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1431 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
1144 | PROTOTYPE: $$$$ |
|
|
1145 | CODE: |
1432 | CODE: |
1146 | eio_sendfile_sync (ofh, ifh, offset, count); |
1433 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
|
|
1434 | OUTPUT: |
|
|
1435 | RETVAL |
|
|
1436 | |
|
|
1437 | void |
|
|
1438 | mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) |
|
|
1439 | PPCODE: |
|
|
1440 | sv_unmagic (scalar, MMAP_MAGIC); |
|
|
1441 | { |
|
|
1442 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
|
|
1443 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
|
|
1444 | if (addr == (void *)-1) |
|
|
1445 | XSRETURN_NO; |
|
|
1446 | |
|
|
1447 | sv_force_normal (scalar); |
|
|
1448 | |
|
|
1449 | /* we store the length in mg_obj, as namlen is I32 :/ */ |
|
|
1450 | sv_magicext (scalar, 0, MMAP_MAGIC, &mmap_vtbl, (char *)addr, 0) |
|
|
1451 | ->mg_obj = (SV *)length; |
|
|
1452 | |
|
|
1453 | SvUPGRADE (scalar, SVt_PV); /* nop... */ |
|
|
1454 | |
|
|
1455 | if (!(prot & PROT_WRITE)) |
|
|
1456 | SvREADONLY_on (scalar); |
|
|
1457 | |
|
|
1458 | if (SvLEN (scalar)) |
|
|
1459 | Safefree (SvPVX (scalar)); |
|
|
1460 | |
|
|
1461 | SvPVX (scalar) = (char *)addr; |
|
|
1462 | SvCUR_set (scalar, length); |
|
|
1463 | SvLEN_set (scalar, 0); |
|
|
1464 | SvPOK_only (scalar); |
|
|
1465 | |
|
|
1466 | XSRETURN_YES; |
|
|
1467 | } |
|
|
1468 | |
|
|
1469 | void |
|
|
1470 | munmap (SV *scalar) |
|
|
1471 | CODE: |
|
|
1472 | sv_unmagic (scalar, MMAP_MAGIC); |
|
|
1473 | |
|
|
1474 | int |
|
|
1475 | madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
|
|
1476 | ALIAS: |
|
|
1477 | mprotect = 1 |
|
|
1478 | CODE: |
|
|
1479 | { |
|
|
1480 | STRLEN svlen; |
|
|
1481 | void *addr = SvPVbyte (scalar, svlen); |
|
|
1482 | size_t len = SvUV (length); |
|
|
1483 | |
|
|
1484 | if (offset < 0) |
|
|
1485 | offset += svlen; |
|
|
1486 | |
|
|
1487 | if (offset < 0 || offset > svlen) |
|
|
1488 | croak ("offset outside of scalar"); |
|
|
1489 | |
|
|
1490 | if (!SvOK (length) || len + offset > svlen) |
|
|
1491 | len = svlen - offset; |
|
|
1492 | |
|
|
1493 | addr = (void *)(((intptr_t)addr) + offset); |
|
|
1494 | eio_page_align (&addr, &len); |
|
|
1495 | |
|
|
1496 | switch (ix) |
|
|
1497 | { |
|
|
1498 | case 0: RETVAL = posix_madvise (addr, len, advice_or_prot); break; |
|
|
1499 | case 1: RETVAL = mprotect (addr, len, advice_or_prot); break; |
|
|
1500 | } |
|
|
1501 | } |
|
|
1502 | OUTPUT: |
|
|
1503 | RETVAL |
|
|
1504 | |
|
|
1505 | int |
|
|
1506 | munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef) |
|
|
1507 | CODE: |
|
|
1508 | { |
|
|
1509 | STRLEN svlen; |
|
|
1510 | void *addr = SvPVbyte (scalar, svlen); |
|
|
1511 | size_t len = SvUV (length); |
|
|
1512 | |
|
|
1513 | if (offset < 0) |
|
|
1514 | offset += svlen; |
|
|
1515 | |
|
|
1516 | if (offset < 0 || offset > svlen) |
|
|
1517 | croak ("offset outside of scalar"); |
|
|
1518 | |
|
|
1519 | if (!SvOK (length) || len + offset > svlen) |
|
|
1520 | len = svlen - offset; |
|
|
1521 | |
|
|
1522 | addr = (void *)(((intptr_t)addr) + offset); |
|
|
1523 | eio_page_align (&addr, &len); |
|
|
1524 | #if _POSIX_MEMLOCK |
|
|
1525 | RETVAL = munlock (addr, len); |
|
|
1526 | #else |
|
|
1527 | RETVAL = ((errno = ENOSYS), -1); |
|
|
1528 | #endif |
|
|
1529 | } |
|
|
1530 | OUTPUT: |
|
|
1531 | RETVAL |
|
|
1532 | |
|
|
1533 | int |
|
|
1534 | munlockall () |
|
|
1535 | CODE: |
|
|
1536 | #if _POSIX_MEMLOCK |
|
|
1537 | munlockall (); |
|
|
1538 | #else |
|
|
1539 | RETVAL = -1; |
|
|
1540 | errno = ENOSYS; |
|
|
1541 | #endif |
|
|
1542 | OUTPUT: |
|
|
1543 | RETVAL |
1147 | |
1544 | |
1148 | void _on_next_submit (SV *cb) |
1545 | void _on_next_submit (SV *cb) |
1149 | CODE: |
1546 | CODE: |
1150 | SvREFCNT_dec (on_next_submit); |
1547 | SvREFCNT_dec (on_next_submit); |
1151 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1548 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |