… | |
… | |
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 || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
|
|
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 |
… | |
… | |
75 | |
82 | |
76 | #define EIO_STRUCT_STAT Stat_t |
83 | #define EIO_STRUCT_STAT Stat_t |
77 | |
84 | |
78 | /* use NV for 32 bit perls as it allows larger offsets */ |
85 | /* use NV for 32 bit perls as it allows larger offsets */ |
79 | #if IVSIZE >= 8 |
86 | #if IVSIZE >= 8 |
|
|
87 | # define VAL64 IV |
80 | # define SvVAL64 SvIV |
88 | # define SvVAL64 SvIV |
|
|
89 | # define newSVval64 newSViv |
81 | #else |
90 | #else |
|
|
91 | # define VAL64 NV |
82 | # define SvVAL64 SvNV |
92 | # define SvVAL64 SvNV |
|
|
93 | # define newSVval64 newSVnv |
83 | #endif |
94 | #endif |
84 | |
95 | |
85 | static HV *stash; |
96 | /*****************************************************************************/ |
|
|
97 | |
|
|
98 | #if __GNUC__ >= 3 |
|
|
99 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
|
|
100 | #else |
|
|
101 | # define expect(expr,value) (expr) |
|
|
102 | #endif |
|
|
103 | |
|
|
104 | #define expect_false(expr) expect ((expr) != 0, 0) |
|
|
105 | #define expect_true(expr) expect ((expr) != 0, 1) |
|
|
106 | |
|
|
107 | /*****************************************************************************/ |
|
|
108 | |
86 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
109 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
|
|
110 | typedef int aio_rfd; /* read file desriptor */ |
|
|
111 | typedef int aio_wfd; /* write file descriptor */ |
87 | |
112 | |
88 | #define AIO_REQ_KLASS "IO::AIO::REQ" |
113 | static HV *aio_stash, *aio_req_stash, *aio_grp_stash; |
89 | #define AIO_GRP_KLASS "IO::AIO::GRP" |
|
|
90 | |
114 | |
91 | #define EIO_REQ_MEMBERS \ |
115 | #define EIO_REQ_MEMBERS \ |
92 | SV *callback; \ |
116 | SV *callback; \ |
93 | SV *sv1, *sv2; \ |
117 | SV *sv1, *sv2; \ |
94 | STRLEN stroffset; \ |
118 | STRLEN stroffset; \ |
95 | SV *self; |
119 | SV *self; |
96 | |
120 | |
97 | #define EIO_NO_WRAPPERS 1 |
121 | #define EIO_NO_WRAPPERS 1 |
98 | |
122 | |
|
|
123 | #include "libeio/config.h" |
99 | #include "libeio/eio.h" |
124 | #include "libeio/eio.h" |
|
|
125 | |
|
|
126 | #ifndef POSIX_FADV_NORMAL |
|
|
127 | # define POSIX_FADV_NORMAL 0 |
|
|
128 | #endif |
|
|
129 | #ifndef POSIX_FADV_SEQUENTIAL |
|
|
130 | # define POSIX_FADV_SEQUENTIAL 0 |
|
|
131 | #endif |
|
|
132 | #ifndef POSIX_FADV_RANDOM |
|
|
133 | # define POSIX_FADV_RANDOM 0 |
|
|
134 | #endif |
|
|
135 | #ifndef POSIX_FADV_NOREUSE |
|
|
136 | # define POSIX_FADV_NOREUSE 0 |
|
|
137 | #endif |
|
|
138 | #ifndef POSIX_FADV_WILLNEED |
|
|
139 | # define POSIX_FADV_WILLNEED 0 |
|
|
140 | #endif |
|
|
141 | #ifndef POSIX_FADV_DONTNEED |
|
|
142 | # define POSIX_FADV_DONTNEED 0 |
|
|
143 | #endif |
|
|
144 | |
|
|
145 | #if !HAVE_POSIX_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 | #endif |
|
|
152 | #ifndef POSIX_MADV_SEQUENTIAL |
|
|
153 | # define POSIX_MADV_SEQUENTIAL 0 |
|
|
154 | #endif |
|
|
155 | #ifndef POSIX_MADV_RANDOM |
|
|
156 | # define POSIX_MADV_RANDOM 0 |
|
|
157 | #endif |
|
|
158 | #ifndef POSIX_MADV_WILLNEED |
|
|
159 | # define POSIX_MADV_WILLNEED 0 |
|
|
160 | #endif |
|
|
161 | #ifndef POSIX_MADV_DONTNEED |
|
|
162 | # define POSIX_MADV_DONTNEED 0 |
|
|
163 | #endif |
|
|
164 | |
|
|
165 | #if !HAVE_POSIX_MADVISE |
|
|
166 | # define posix_madvise(a,b,c) errno = ENOSYS /* also return ENOSYS */ |
|
|
167 | #endif |
|
|
168 | |
|
|
169 | #ifndef PROT_NONE |
|
|
170 | # define PROT_NONE 0 |
|
|
171 | #endif |
|
|
172 | #ifndef PROT_READ |
|
|
173 | # define PROT_READ 0 |
|
|
174 | #endif |
|
|
175 | #ifndef PROT_WRITE |
|
|
176 | # define PROT_READ 0 |
|
|
177 | #endif |
|
|
178 | #ifndef PROT_EXEC |
|
|
179 | # define PROT_EXEC 0 |
|
|
180 | #endif |
|
|
181 | |
|
|
182 | #ifndef ST_NODEV |
|
|
183 | # define ST_NODEV 0 |
|
|
184 | #endif |
|
|
185 | #ifndef ST_NOEXEC |
|
|
186 | # define ST_NOEXEC 0 |
|
|
187 | #endif |
|
|
188 | #ifndef ST_SYNCHRONOUS |
|
|
189 | # define ST_SYNCHRONOUS 0 |
|
|
190 | #endif |
|
|
191 | #ifndef ST_MANDLOCK |
|
|
192 | # define ST_MANDLOCK 0 |
|
|
193 | #endif |
|
|
194 | #ifndef ST_WRITE |
|
|
195 | # define ST_WRITE 0 |
|
|
196 | #endif |
|
|
197 | #ifndef ST_APPEND |
|
|
198 | # define ST_APPEND 0 |
|
|
199 | #endif |
|
|
200 | #ifndef ST_IMMUTABLE |
|
|
201 | # define ST_IMMUTABLE 0 |
|
|
202 | #endif |
|
|
203 | #ifndef ST_NOATIME |
|
|
204 | # define ST_NOATIME 0 |
|
|
205 | #endif |
|
|
206 | #ifndef ST_NODIRATIME |
|
|
207 | # define ST_NODIRATIME 0 |
|
|
208 | #endif |
|
|
209 | #ifndef ST_RELATIME |
|
|
210 | # define ST_RELATIME 0 |
|
|
211 | #endif |
|
|
212 | |
|
|
213 | #ifndef MAP_ANONYMOUS |
|
|
214 | # ifdef MAP_ANON |
|
|
215 | # define MAP_ANONYMOUS MAP_ANON |
|
|
216 | # else |
|
|
217 | # define MAP_ANONYMOUS MAP_FIXED /* and hope this fails */ |
|
|
218 | # endif |
|
|
219 | #endif |
|
|
220 | #ifndef MAP_HUGETLB |
|
|
221 | # define MAP_HUGETLB 0 |
|
|
222 | #endif |
|
|
223 | #ifndef MAP_LOCKED |
|
|
224 | # define MAP_LOCKED 0 |
|
|
225 | #endif |
|
|
226 | #ifndef MAP_NORESERVE |
|
|
227 | # define MAP_NORESERVE 0 |
|
|
228 | #endif |
|
|
229 | #ifndef MAP_POPULATE |
|
|
230 | # define MAP_POPULATE 0 |
|
|
231 | #endif |
|
|
232 | #ifndef MAP_NONBLOCK |
|
|
233 | # define MAP_NONBLOCK 0 |
|
|
234 | #endif |
|
|
235 | |
|
|
236 | #ifndef PAGESIZE |
|
|
237 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
|
|
238 | #endif |
100 | |
239 | |
101 | static int req_invoke (eio_req *req); |
240 | static int req_invoke (eio_req *req); |
102 | #define EIO_FINISH(req) req_invoke (req) |
241 | #define EIO_FINISH(req) req_invoke (req) |
103 | static void aio_grp_feed (eio_req *grp); |
|
|
104 | #define EIO_FEED(req) aio_grp_feed (req) |
|
|
105 | static void req_destroy (eio_req *grp); |
242 | static void req_destroy (eio_req *grp); |
106 | #define EIO_DESTROY(req) req_destroy (req) |
243 | #define EIO_DESTROY(req) req_destroy (req) |
107 | |
244 | |
108 | enum { |
245 | enum { |
109 | FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ |
246 | FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ |
… | |
… | |
116 | |
253 | |
117 | static SV *on_next_submit; |
254 | static SV *on_next_submit; |
118 | static int next_pri = EIO_PRI_DEFAULT; |
255 | static int next_pri = EIO_PRI_DEFAULT; |
119 | static int max_outstanding; |
256 | static int max_outstanding; |
120 | |
257 | |
121 | static int respipe_osf [2], respipe [2] = { -1, -1 }; |
258 | static s_epipe respipe; |
122 | |
259 | |
123 | static void req_destroy (aio_req req); |
260 | static void req_destroy (aio_req req); |
124 | static void req_cancel (aio_req req); |
261 | static void req_cancel (aio_req req); |
125 | |
262 | |
126 | static void want_poll (void) |
263 | static void want_poll (void) |
127 | { |
264 | { |
128 | /* write a dummy byte to the pipe so fh becomes ready */ |
265 | /* write a dummy byte to the pipe so fh becomes ready */ |
129 | respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1); |
266 | s_epipe_signal (&respipe); |
130 | } |
267 | } |
131 | |
268 | |
132 | static void done_poll (void) |
269 | static void done_poll (void) |
133 | { |
270 | { |
134 | /* read any signals sent by the worker threads */ |
271 | /* read any signals sent by the worker threads */ |
135 | char buf [4]; |
272 | s_epipe_drain (&respipe); |
136 | while (respipe_read (respipe [0], buf, 4) == 4) |
|
|
137 | ; |
|
|
138 | } |
273 | } |
139 | |
274 | |
140 | /* must be called at most once */ |
275 | /* must be called at most once */ |
141 | static SV *req_sv (aio_req req, const char *klass) |
276 | static SV *req_sv (aio_req req, HV *stash) |
142 | { |
277 | { |
143 | if (!req->self) |
278 | if (!req->self) |
144 | { |
279 | { |
145 | req->self = (SV *)newHV (); |
280 | req->self = (SV *)newHV (); |
146 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
281 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
147 | } |
282 | } |
148 | |
283 | |
149 | return sv_2mortal (sv_bless (newRV_inc (req->self), gv_stashpv (klass, 1))); |
284 | return sv_2mortal (sv_bless (newRV_inc (req->self), stash)); |
150 | } |
285 | } |
151 | |
286 | |
152 | static aio_req SvAIO_REQ (SV *sv) |
287 | static aio_req SvAIO_REQ (SV *sv) |
153 | { |
288 | { |
154 | MAGIC *mg; |
289 | MAGIC *mg; |
155 | |
290 | |
156 | if (!sv_derived_from (sv, AIO_REQ_KLASS) || !SvROK (sv)) |
291 | if (!SvROK (sv) |
|
|
292 | || (SvSTASH (SvRV (sv)) != aio_grp_stash |
|
|
293 | && SvSTASH (SvRV (sv)) != aio_req_stash |
|
|
294 | && !sv_derived_from (sv, "IO::AIO::REQ"))) |
157 | croak ("object of class " AIO_REQ_KLASS " expected"); |
295 | croak ("object of class IO::AIO::REQ expected"); |
158 | |
296 | |
159 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
297 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
160 | |
298 | |
161 | return mg ? (aio_req)mg->mg_ptr : 0; |
299 | return mg ? (aio_req)mg->mg_ptr : 0; |
162 | } |
300 | } |
… | |
… | |
168 | dSP; |
306 | dSP; |
169 | |
307 | |
170 | ENTER; |
308 | ENTER; |
171 | SAVETMPS; |
309 | SAVETMPS; |
172 | PUSHMARK (SP); |
310 | PUSHMARK (SP); |
173 | XPUSHs (req_sv (grp, AIO_GRP_KLASS)); |
311 | XPUSHs (req_sv (grp, aio_grp_stash)); |
174 | PUTBACK; |
312 | PUTBACK; |
175 | call_sv (grp->sv2, G_VOID | G_EVAL | G_KEEPERR); |
313 | call_sv (grp->sv2, G_VOID | G_EVAL | G_KEEPERR); |
176 | SPAGAIN; |
314 | SPAGAIN; |
177 | FREETMPS; |
315 | FREETMPS; |
178 | LEAVE; |
316 | LEAVE; |
… | |
… | |
181 | |
319 | |
182 | static void req_submit (eio_req *req) |
320 | static void req_submit (eio_req *req) |
183 | { |
321 | { |
184 | eio_submit (req); |
322 | eio_submit (req); |
185 | |
323 | |
186 | if (on_next_submit) |
324 | if (expect_false (on_next_submit)) |
187 | { |
325 | { |
188 | dSP; |
326 | dSP; |
189 | SV *cb = sv_2mortal (on_next_submit); |
327 | SV *cb = sv_2mortal (on_next_submit); |
190 | |
328 | |
191 | on_next_submit = 0; |
329 | on_next_submit = 0; |
… | |
… | |
196 | } |
334 | } |
197 | } |
335 | } |
198 | |
336 | |
199 | static int req_invoke (eio_req *req) |
337 | static int req_invoke (eio_req *req) |
200 | { |
338 | { |
201 | dSP; |
|
|
202 | |
|
|
203 | if (req->flags & FLAG_SV2_RO_OFF) |
339 | if (req->flags & FLAG_SV2_RO_OFF) |
204 | SvREADONLY_off (req->sv2); |
340 | SvREADONLY_off (req->sv2); |
205 | |
341 | |
206 | if (!EIO_CANCELLED (req) && SvOK (req->callback)) |
342 | if (!EIO_CANCELLED (req) && req->callback) |
207 | { |
343 | { |
|
|
344 | dSP; |
|
|
345 | static SV *sv_result_cache; /* caches the result integer SV */ |
|
|
346 | SV *sv_result; |
|
|
347 | |
208 | ENTER; |
348 | ENTER; |
209 | SAVETMPS; |
349 | SAVETMPS; |
210 | PUSHMARK (SP); |
350 | PUSHMARK (SP); |
211 | EXTEND (SP, 1); |
351 | EXTEND (SP, 1); |
|
|
352 | |
|
|
353 | /* do not recreate the result IV from scratch each time */ |
|
|
354 | if (expect_true (sv_result_cache)) |
|
|
355 | { |
|
|
356 | sv_result = sv_result_cache; sv_result_cache = 0; |
|
|
357 | SvIV_set (sv_result, req->result); |
|
|
358 | SvIOK_only (sv_result); |
|
|
359 | } |
|
|
360 | else |
|
|
361 | { |
|
|
362 | sv_result = newSViv (req->result); |
|
|
363 | SvREADONLY_on (sv_result); |
|
|
364 | } |
212 | |
365 | |
213 | switch (req->type) |
366 | switch (req->type) |
214 | { |
367 | { |
215 | case EIO_READDIR: |
368 | case EIO_READDIR: |
216 | { |
369 | { |
217 | SV *rv = &PL_sv_undef; |
370 | SV *rv = &PL_sv_undef; |
218 | |
371 | |
219 | if (req->result >= 0) |
372 | if (req->result >= 0) |
220 | { |
373 | { |
221 | int i; |
374 | int i; |
222 | char *buf = req->ptr2; |
375 | char *names = (char *)req->ptr2; |
|
|
376 | eio_dirent *ent = (eio_dirent *)req->ptr1; /* might be 0 */ |
223 | AV *av = newAV (); |
377 | AV *av = newAV (); |
224 | |
378 | |
225 | av_extend (av, req->result - 1); |
379 | av_extend (av, req->result - 1); |
226 | |
380 | |
227 | for (i = 0; i < req->result; ++i) |
381 | for (i = 0; i < req->result; ++i) |
228 | { |
382 | { |
229 | SV *sv = newSVpv (buf, 0); |
383 | if (req->int1 & EIO_READDIR_DENTS) |
|
|
384 | { |
|
|
385 | SV *namesv = newSVpvn (names + ent->nameofs, ent->namelen); |
230 | |
386 | |
|
|
387 | if (req->int1 & EIO_READDIR_CUSTOM2) |
|
|
388 | { |
|
|
389 | static SV *sv_type [EIO_DT_MAX + 1]; /* type sv cache */ |
|
|
390 | AV *avent = newAV (); |
|
|
391 | |
|
|
392 | av_extend (avent, 2); |
|
|
393 | |
|
|
394 | if (!sv_type [ent->type]) |
|
|
395 | { |
|
|
396 | sv_type [ent->type] = newSViv (ent->type); |
|
|
397 | SvREADONLY_on (sv_type [ent->type]); |
|
|
398 | } |
|
|
399 | |
|
|
400 | av_store (avent, 0, namesv); |
|
|
401 | av_store (avent, 1, SvREFCNT_inc (sv_type [ent->type])); |
|
|
402 | av_store (avent, 2, IVSIZE >= 8 ? newSVuv (ent->inode) : newSVnv (ent->inode)); |
|
|
403 | |
|
|
404 | av_store (av, i, newRV_noinc ((SV *)avent)); |
|
|
405 | } |
|
|
406 | else |
231 | av_store (av, i, sv); |
407 | av_store (av, i, namesv); |
|
|
408 | |
|
|
409 | ++ent; |
|
|
410 | } |
|
|
411 | else |
|
|
412 | { |
|
|
413 | SV *name = newSVpv (names, 0); |
|
|
414 | av_store (av, i, name); |
232 | buf += SvCUR (sv) + 1; |
415 | names += SvCUR (name) + 1; |
|
|
416 | } |
233 | } |
417 | } |
234 | |
418 | |
235 | rv = sv_2mortal (newRV_noinc ((SV *)av)); |
419 | rv = sv_2mortal (newRV_noinc ((SV *)av)); |
236 | } |
420 | } |
237 | |
421 | |
238 | PUSHs (rv); |
422 | PUSHs (rv); |
|
|
423 | |
|
|
424 | if (req->int1 & EIO_READDIR_CUSTOM1) |
|
|
425 | XPUSHs (sv_2mortal (newSViv (req->int1 & ~(EIO_READDIR_CUSTOM1 | EIO_READDIR_CUSTOM2)))); |
239 | } |
426 | } |
240 | break; |
427 | break; |
241 | |
428 | |
242 | case EIO_OPEN: |
429 | case EIO_OPEN: |
243 | { |
430 | { |
… | |
… | |
249 | GV *gv = (GV *)sv_newmortal (); |
436 | GV *gv = (GV *)sv_newmortal (); |
250 | int flags = req->int1 & (O_RDONLY | O_WRONLY | O_RDWR); |
437 | int flags = req->int1 & (O_RDONLY | O_WRONLY | O_RDWR); |
251 | char sym [64]; |
438 | char sym [64]; |
252 | int symlen; |
439 | int symlen; |
253 | |
440 | |
254 | symlen = snprintf (sym, sizeof (sym), "fd#%d", req->result); |
441 | symlen = snprintf (sym, sizeof (sym), "fd#%d", (int)req->result); |
255 | gv_init (gv, stash, sym, symlen, 0); |
442 | gv_init (gv, aio_stash, sym, symlen, 0); |
256 | |
443 | |
257 | symlen = snprintf ( |
444 | symlen = snprintf ( |
258 | sym, |
445 | sym, |
259 | sizeof (sym), |
446 | sizeof (sym), |
260 | "%s&=%d", |
447 | "%s&=%d", |
261 | flags == O_RDONLY ? "<" : flags == O_WRONLY ? ">" : "+<", |
448 | flags == O_RDONLY ? "<" : flags == O_WRONLY ? ">" : "+<", |
262 | req->result |
449 | (int)req->result |
263 | ); |
450 | ); |
264 | |
451 | |
265 | if (do_open (gv, sym, symlen, 0, 0, 0, 0)) |
452 | if (do_open (gv, sym, symlen, 0, 0, 0, 0)) |
266 | fh = (SV *)gv; |
453 | fh = (SV *)gv; |
267 | } |
454 | } |
268 | |
455 | |
269 | PUSHs (fh); |
456 | PUSHs (fh); |
270 | } |
457 | } |
|
|
458 | break; |
|
|
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 | |
271 | break; |
488 | break; |
272 | |
489 | |
273 | case EIO_GROUP: |
490 | case EIO_GROUP: |
274 | req->int1 = 2; /* mark group as finished */ |
491 | req->int1 = 2; /* mark group as finished */ |
275 | |
492 | |
… | |
… | |
297 | case EIO_LSTAT: |
514 | case EIO_LSTAT: |
298 | case EIO_FSTAT: |
515 | case EIO_FSTAT: |
299 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
516 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
300 | PL_laststatval = req->result; |
517 | PL_laststatval = req->result; |
301 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
518 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
302 | PUSHs (sv_2mortal (newSViv (req->result))); |
519 | PUSHs (sv_result); |
303 | break; |
520 | break; |
304 | |
521 | |
305 | case EIO_READ: |
522 | case EIO_READ: |
|
|
523 | { |
306 | 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)); |
307 | *SvEND (req->sv2) = 0; |
525 | *SvEND (req->sv2) = 0; |
308 | PUSHs (sv_2mortal (newSViv (req->result))); |
526 | SvPOK_only (req->sv2); |
|
|
527 | SvSETMAGIC (req->sv2); |
|
|
528 | PUSHs (sv_result); |
|
|
529 | } |
309 | break; |
530 | break; |
310 | |
531 | |
311 | case EIO_DUP2: |
532 | case EIO_DUP2: /* EIO_DUP2 actually means aio_close(), so fudge result value */ |
312 | if (req->result > 0) |
533 | if (req->result > 0) |
313 | req->result = 0; |
534 | SvIV_set (sv_result, 0); |
314 | /* FALLTHROUGH */ |
535 | /* FALLTHROUGH */ |
315 | |
536 | |
316 | default: |
537 | default: |
317 | PUSHs (sv_2mortal (newSViv (req->result))); |
538 | PUSHs (sv_result); |
318 | break; |
539 | break; |
319 | } |
540 | } |
320 | |
541 | |
321 | errno = req->errorno; |
542 | errno = req->errorno; |
322 | |
543 | |
323 | PUTBACK; |
544 | PUTBACK; |
324 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
545 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
325 | 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; |
326 | |
552 | |
327 | FREETMPS; |
553 | FREETMPS; |
328 | LEAVE; |
554 | LEAVE; |
329 | |
555 | |
330 | PUTBACK; |
556 | PUTBACK; |
… | |
… | |
359 | grp->sv2 = 0; |
585 | grp->sv2 = 0; |
360 | |
586 | |
361 | eio_grp_cancel (grp); |
587 | eio_grp_cancel (grp); |
362 | } |
588 | } |
363 | |
589 | |
364 | #ifdef USE_SOCKETS_AS_HANDLES |
|
|
365 | # define TO_SOCKET(x) (win32_get_osfhandle (x)) |
|
|
366 | #else |
|
|
367 | # define TO_SOCKET(x) (x) |
|
|
368 | #endif |
|
|
369 | |
|
|
370 | static void |
590 | static void |
371 | create_respipe (void) |
591 | create_respipe (void) |
372 | { |
592 | { |
373 | int old_readfd = respipe [0]; |
|
|
374 | |
|
|
375 | if (respipe [1] >= 0) |
|
|
376 | respipe_close (TO_SOCKET (respipe [1])); |
|
|
377 | |
|
|
378 | #ifdef _WIN32 |
|
|
379 | if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe)) |
|
|
380 | #else |
|
|
381 | if (pipe (respipe)) |
593 | if (s_epipe_renew (&respipe)) |
382 | #endif |
|
|
383 | croak ("unable to initialize result pipe"); |
594 | croak ("IO::AIO: unable to initialize result pipe"); |
384 | |
|
|
385 | if (old_readfd >= 0) |
|
|
386 | { |
|
|
387 | if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0) |
|
|
388 | croak ("unable to initialize result pipe(2)"); |
|
|
389 | |
|
|
390 | respipe_close (respipe [0]); |
|
|
391 | respipe [0] = old_readfd; |
|
|
392 | } |
|
|
393 | |
|
|
394 | #ifdef _WIN32 |
|
|
395 | int arg = 1; |
|
|
396 | if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg) |
|
|
397 | || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg)) |
|
|
398 | #else |
|
|
399 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK) |
|
|
400 | || fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
|
|
401 | #endif |
|
|
402 | croak ("unable to initialize result pipe(3)"); |
|
|
403 | |
|
|
404 | respipe_osf [0] = TO_SOCKET (respipe [0]); |
|
|
405 | respipe_osf [1] = TO_SOCKET (respipe [1]); |
|
|
406 | } |
595 | } |
407 | |
596 | |
408 | static void poll_wait (void) |
597 | static void poll_wait (void) |
409 | { |
598 | { |
410 | fd_set rfd; |
|
|
411 | |
|
|
412 | while (eio_nreqs ()) |
599 | while (eio_nreqs ()) |
413 | { |
600 | { |
414 | int size; |
601 | int size; |
415 | |
602 | |
416 | X_LOCK (reslock); |
603 | X_LOCK (reslock); |
… | |
… | |
420 | if (size) |
607 | if (size) |
421 | return; |
608 | return; |
422 | |
609 | |
423 | etp_maybe_start_thread (); |
610 | etp_maybe_start_thread (); |
424 | |
611 | |
425 | FD_ZERO (&rfd); |
612 | s_epipe_wait (&respipe); |
426 | FD_SET (respipe [0], &rfd); |
|
|
427 | |
|
|
428 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
|
|
429 | } |
613 | } |
430 | } |
614 | } |
431 | |
615 | |
432 | static int poll_cb (void) |
616 | static int poll_cb (void) |
433 | { |
617 | { |
… | |
… | |
448 | static void atfork_child (void) |
632 | static void atfork_child (void) |
449 | { |
633 | { |
450 | create_respipe (); |
634 | create_respipe (); |
451 | } |
635 | } |
452 | |
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 | #endif |
|
|
643 | |
|
|
644 | #if !_POSIX_MEMORY_PROTECTION |
|
|
645 | # define mprotect(addr,len,prot) (errno = ENOSYS, -1) |
|
|
646 | # define PROT_NONE 0 |
|
|
647 | # define PROT_WRITE 0 |
|
|
648 | # define MAP_PRIVATE 0 |
|
|
649 | # define MAP_SHARED 0 |
|
|
650 | # define MAP_FIXED 0 |
|
|
651 | #endif |
|
|
652 | |
|
|
653 | #define MMAP_MAGIC PERL_MAGIC_ext |
|
|
654 | |
|
|
655 | static int |
|
|
656 | mmap_free (pTHX_ SV *sv, MAGIC *mg) |
|
|
657 | { |
|
|
658 | int old_errno = errno; |
|
|
659 | munmap (mg->mg_ptr, (size_t)mg->mg_obj); |
|
|
660 | errno = old_errno; |
|
|
661 | |
|
|
662 | mg->mg_obj = 0; /* just in case */ |
|
|
663 | |
|
|
664 | SvREADONLY_off (sv); |
|
|
665 | |
|
|
666 | if (SvPVX (sv) != mg->mg_ptr) |
|
|
667 | croak ("ERROR: IO::AIO::mmap-mapped scalar changed location, detected"); |
|
|
668 | |
|
|
669 | SvCUR_set (sv, 0); |
|
|
670 | SvPVX (sv) = 0; |
|
|
671 | SvOK_off (sv); |
|
|
672 | |
|
|
673 | return 0; |
|
|
674 | } |
|
|
675 | |
|
|
676 | static MGVTBL mmap_vtbl = { |
|
|
677 | 0, 0, 0, 0, mmap_free |
|
|
678 | }; |
|
|
679 | |
|
|
680 | /*****************************************************************************/ |
|
|
681 | |
|
|
682 | static SV * |
|
|
683 | get_cb (SV *cb_sv) |
|
|
684 | { |
|
|
685 | SvGETMAGIC (cb_sv); |
|
|
686 | return SvOK (cb_sv) ? s_get_cv_croak (cb_sv) : 0; |
|
|
687 | } |
|
|
688 | |
453 | #define dREQ \ |
689 | #define dREQ \ |
|
|
690 | SV *cb_cv; \ |
454 | aio_req req; \ |
691 | aio_req req; \ |
455 | int req_pri = next_pri; \ |
692 | int req_pri = next_pri; \ |
456 | next_pri = EIO_PRI_DEFAULT; \ |
693 | next_pri = EIO_PRI_DEFAULT; \ |
457 | \ |
694 | \ |
458 | if (SvOK (callback) && !SvROK (callback)) \ |
695 | cb_cv = get_cb (callback); \ |
459 | croak ("callback must be undef or of reference type"); \ |
|
|
460 | \ |
696 | \ |
461 | Newz (0, req, 1, eio_req); \ |
697 | Newz (0, req, 1, eio_req); \ |
462 | if (!req) \ |
698 | if (!req) \ |
463 | croak ("out of memory during eio_req allocation"); \ |
699 | croak ("out of memory during eio_req allocation"); \ |
464 | \ |
700 | \ |
465 | req->callback = newSVsv (callback); \ |
701 | req->callback = SvREFCNT_inc (cb_cv); \ |
466 | req->pri = req_pri |
702 | req->pri = req_pri |
467 | |
703 | |
468 | #define REQ_SEND \ |
704 | #define REQ_SEND \ |
469 | PUTBACK; \ |
705 | PUTBACK; \ |
470 | req_submit (req); \ |
706 | req_submit (req); \ |
471 | SPAGAIN; \ |
707 | SPAGAIN; \ |
472 | \ |
708 | \ |
473 | if (GIMME_V != G_VOID) \ |
709 | if (GIMME_V != G_VOID) \ |
474 | XPUSHs (req_sv (req, AIO_REQ_KLASS)); |
710 | XPUSHs (req_sv (req, aio_req_stash)); |
475 | |
711 | |
476 | MODULE = IO::AIO PACKAGE = IO::AIO |
712 | MODULE = IO::AIO PACKAGE = IO::AIO |
477 | |
713 | |
478 | PROTOTYPES: ENABLE |
714 | PROTOTYPES: ENABLE |
479 | |
715 | |
480 | BOOT: |
716 | BOOT: |
481 | { |
717 | { |
482 | stash = gv_stashpv ("IO::AIO", 1); |
718 | static const struct { |
483 | |
719 | const char *name; |
484 | newCONSTSUB (stash, "EXDEV", newSViv (EXDEV)); |
720 | IV iv; |
485 | newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY)); |
721 | } *civ, const_iv[] = { |
486 | newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY)); |
722 | # define const_niv(name, value) { # name, (IV) value }, |
487 | newCONSTSUB (stash, "O_CREAT", newSViv (O_CREAT)); |
723 | # define const_iv(name) { # name, (IV) name }, |
488 | newCONSTSUB (stash, "O_TRUNC", newSViv (O_TRUNC)); |
724 | # define const_eio(name) { # name, (IV) EIO_ ## name }, |
|
|
725 | const_iv (EXDEV) |
|
|
726 | const_iv (ENOSYS) |
|
|
727 | const_iv (O_RDONLY) |
|
|
728 | const_iv (O_WRONLY) |
|
|
729 | const_iv (O_RDWR) |
|
|
730 | const_iv (O_CREAT) |
|
|
731 | const_iv (O_TRUNC) |
|
|
732 | const_iv (O_EXCL) |
|
|
733 | const_iv (O_APPEND) |
489 | #ifndef _WIN32 |
734 | #ifndef _WIN32 |
490 | newCONSTSUB (stash, "S_IFIFO", newSViv (S_IFIFO)); |
735 | const_iv (S_IFIFO) |
491 | #endif |
736 | #endif |
|
|
737 | const_niv (FADV_NORMAL , POSIX_FADV_NORMAL) |
|
|
738 | const_niv (FADV_SEQUENTIAL, POSIX_FADV_SEQUENTIAL) |
|
|
739 | const_niv (FADV_RANDOM , POSIX_FADV_RANDOM) |
|
|
740 | const_niv (FADV_NOREUSE , POSIX_FADV_NOREUSE) |
|
|
741 | const_niv (FADV_WILLNEED , POSIX_FADV_WILLNEED) |
|
|
742 | const_niv (FADV_DONTNEED , POSIX_FADV_DONTNEED) |
492 | |
743 | |
|
|
744 | const_niv (MADV_NORMAL , POSIX_MADV_NORMAL) |
|
|
745 | const_niv (MADV_SEQUENTIAL, POSIX_MADV_SEQUENTIAL) |
|
|
746 | const_niv (MADV_RANDOM , POSIX_MADV_RANDOM) |
|
|
747 | const_niv (MADV_WILLNEED , POSIX_MADV_WILLNEED) |
|
|
748 | const_niv (MADV_DONTNEED , POSIX_MADV_DONTNEED) |
|
|
749 | |
|
|
750 | const_iv (ST_RDONLY) |
|
|
751 | const_iv (ST_NOSUID) |
|
|
752 | const_iv (ST_NODEV) |
|
|
753 | const_iv (ST_NOEXEC) |
|
|
754 | const_iv (ST_SYNCHRONOUS) |
|
|
755 | const_iv (ST_MANDLOCK) |
|
|
756 | const_iv (ST_WRITE) |
|
|
757 | const_iv (ST_APPEND) |
|
|
758 | const_iv (ST_IMMUTABLE) |
|
|
759 | const_iv (ST_NOATIME) |
|
|
760 | const_iv (ST_NODIRATIME) |
|
|
761 | const_iv (ST_RELATIME) |
|
|
762 | |
|
|
763 | const_iv (PROT_NONE) |
|
|
764 | const_iv (PROT_EXEC) |
|
|
765 | const_iv (PROT_READ) |
|
|
766 | const_iv (PROT_WRITE) |
|
|
767 | |
|
|
768 | /*const_iv (MAP_FIXED)*/ |
|
|
769 | const_iv (MAP_PRIVATE) |
|
|
770 | const_iv (MAP_SHARED) |
|
|
771 | const_iv (MAP_ANONYMOUS) |
|
|
772 | |
|
|
773 | /* linuxish */ |
|
|
774 | const_iv (MAP_HUGETLB) |
|
|
775 | const_iv (MAP_LOCKED) |
|
|
776 | const_iv (MAP_NORESERVE) |
|
|
777 | const_iv (MAP_POPULATE) |
|
|
778 | const_iv (MAP_NONBLOCK) |
|
|
779 | |
|
|
780 | const_eio (MCL_FUTURE) |
|
|
781 | const_eio (MCL_CURRENT) |
|
|
782 | |
|
|
783 | const_eio (MS_ASYNC) |
|
|
784 | const_eio (MS_INVALIDATE) |
|
|
785 | const_eio (MS_SYNC) |
|
|
786 | |
|
|
787 | const_eio (MT_MODIFY) |
|
|
788 | |
|
|
789 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
|
|
790 | const_eio (SYNC_FILE_RANGE_WRITE) |
|
|
791 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
|
|
792 | |
|
|
793 | const_eio (READDIR_DENTS) |
|
|
794 | const_eio (READDIR_DIRS_FIRST) |
|
|
795 | const_eio (READDIR_STAT_ORDER) |
|
|
796 | const_eio (READDIR_FOUND_UNKNOWN) |
|
|
797 | |
|
|
798 | const_eio (DT_UNKNOWN) |
|
|
799 | const_eio (DT_FIFO) |
|
|
800 | const_eio (DT_CHR) |
|
|
801 | const_eio (DT_DIR) |
|
|
802 | const_eio (DT_BLK) |
|
|
803 | const_eio (DT_REG) |
|
|
804 | const_eio (DT_LNK) |
|
|
805 | const_eio (DT_SOCK) |
|
|
806 | const_eio (DT_WHT) |
|
|
807 | }; |
|
|
808 | |
|
|
809 | aio_stash = gv_stashpv ("IO::AIO" , 1); |
|
|
810 | aio_req_stash = gv_stashpv ("IO::AIO::REQ", 1); |
|
|
811 | aio_grp_stash = gv_stashpv ("IO::AIO::GRP", 1); |
|
|
812 | |
|
|
813 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
|
|
814 | newCONSTSUB (aio_stash, (char *)civ->name, newSViv (civ->iv)); |
|
|
815 | |
|
|
816 | newCONSTSUB (aio_stash, "PAGESIZE", newSViv (PAGESIZE)); |
|
|
817 | |
493 | create_respipe (); |
818 | create_respipe (); |
494 | |
819 | |
495 | if (eio_init (want_poll, done_poll) < 0) |
820 | if (eio_init (want_poll, done_poll) < 0) |
496 | croak ("IO::AIO: unable to initialise eio library"); |
821 | croak ("IO::AIO: unable to initialise eio library"); |
497 | |
822 | |
498 | /* atfork child called in fifo order, so before eio's handler */ |
823 | /* atfork child called in fifo order, so before eio's handler */ |
499 | X_THREAD_ATFORK (0, 0, atfork_child); |
824 | X_THREAD_ATFORK (0, 0, atfork_child); |
500 | } |
825 | } |
501 | |
826 | |
502 | void |
827 | void |
503 | max_poll_reqs (int nreqs) |
828 | max_poll_reqs (int nreqs) |
504 | PROTOTYPE: $ |
829 | PROTOTYPE: $ |
… | |
… | |
535 | CODE: |
860 | CODE: |
536 | max_outstanding = maxreqs; |
861 | max_outstanding = maxreqs; |
537 | |
862 | |
538 | void |
863 | void |
539 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
864 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
540 | PROTOTYPE: $$$;$ |
|
|
541 | PPCODE: |
865 | PPCODE: |
542 | { |
866 | { |
543 | dREQ; |
867 | dREQ; |
544 | |
868 | |
545 | req->type = EIO_OPEN; |
869 | req->type = EIO_OPEN; |
… | |
… | |
551 | REQ_SEND; |
875 | REQ_SEND; |
552 | } |
876 | } |
553 | |
877 | |
554 | void |
878 | void |
555 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
879 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
556 | PROTOTYPE: $;$ |
|
|
557 | ALIAS: |
880 | ALIAS: |
558 | aio_fsync = EIO_FSYNC |
881 | aio_fsync = EIO_FSYNC |
559 | aio_fdatasync = EIO_FDATASYNC |
882 | aio_fdatasync = EIO_FDATASYNC |
560 | PPCODE: |
883 | PPCODE: |
561 | { |
884 | { |
|
|
885 | int fd = s_fileno_croak (fh, 0); |
562 | dREQ; |
886 | dREQ; |
563 | |
887 | |
564 | req->type = ix; |
888 | req->type = ix; |
565 | req->sv1 = newSVsv (fh); |
889 | req->sv1 = newSVsv (fh); |
566 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh))); |
890 | req->int1 = fd; |
567 | |
891 | |
568 | REQ_SEND (req); |
892 | REQ_SEND (req); |
569 | } |
893 | } |
570 | |
894 | |
571 | void |
895 | void |
|
|
896 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
|
|
897 | PPCODE: |
|
|
898 | { |
|
|
899 | int fd = s_fileno_croak (fh, 0); |
|
|
900 | dREQ; |
|
|
901 | |
|
|
902 | req->type = EIO_SYNC_FILE_RANGE; |
|
|
903 | req->sv1 = newSVsv (fh); |
|
|
904 | req->int1 = fd; |
|
|
905 | req->offs = offset; |
|
|
906 | req->size = nbytes; |
|
|
907 | req->int2 = flags; |
|
|
908 | |
|
|
909 | REQ_SEND (req); |
|
|
910 | } |
|
|
911 | |
|
|
912 | void |
572 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
913 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
573 | PROTOTYPE: $;$ |
|
|
574 | PPCODE: |
914 | PPCODE: |
575 | { |
915 | { |
576 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
916 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
|
|
917 | int fd = s_fileno_croak (fh, 0); |
577 | dREQ; |
918 | dREQ; |
578 | |
919 | |
579 | if (close_pipe < 0) |
920 | if (close_pipe < 0) |
580 | { |
921 | { |
581 | int pipefd [2]; |
922 | int pipefd [2]; |
… | |
… | |
589 | } |
930 | } |
590 | |
931 | |
591 | req->type = EIO_DUP2; |
932 | req->type = EIO_DUP2; |
592 | req->int1 = close_pipe; |
933 | req->int1 = close_pipe; |
593 | req->sv2 = newSVsv (fh); |
934 | req->sv2 = newSVsv (fh); |
594 | req->int2 = PerlIO_fileno (IoIFP (sv_2io (fh))); |
935 | req->int2 = fd; |
595 | |
936 | |
596 | REQ_SEND (req); |
937 | REQ_SEND (req); |
597 | } |
938 | } |
598 | |
939 | |
599 | void |
940 | void |
600 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
941 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
601 | ALIAS: |
942 | ALIAS: |
602 | aio_read = EIO_READ |
943 | aio_read = EIO_READ |
603 | aio_write = EIO_WRITE |
944 | aio_write = EIO_WRITE |
604 | PROTOTYPE: $$$$$;$ |
|
|
605 | PPCODE: |
945 | PPCODE: |
606 | { |
946 | { |
607 | STRLEN svlen; |
947 | STRLEN svlen; |
|
|
948 | int fd = s_fileno_croak (fh, ix == EIO_WRITE); |
608 | char *svptr = SvPVbyte (data, svlen); |
949 | char *svptr = SvPVbyte (data, svlen); |
609 | UV len = SvUV (length); |
950 | UV len = SvUV (length); |
610 | |
|
|
611 | SvUPGRADE (data, SVt_PV); |
|
|
612 | SvPOK_on (data); |
|
|
613 | |
951 | |
614 | if (dataoffset < 0) |
952 | if (dataoffset < 0) |
615 | dataoffset += svlen; |
953 | dataoffset += svlen; |
616 | |
954 | |
617 | if (dataoffset < 0 || dataoffset > svlen) |
955 | if (dataoffset < 0 || dataoffset > svlen) |
… | |
… | |
623 | if (!SvOK (length) || len + dataoffset > svlen) |
961 | if (!SvOK (length) || len + dataoffset > svlen) |
624 | len = svlen - dataoffset; |
962 | len = svlen - dataoffset; |
625 | } |
963 | } |
626 | else |
964 | else |
627 | { |
965 | { |
628 | /* read: grow scalar as necessary */ |
966 | /* read: check type and grow scalar as necessary */ |
|
|
967 | SvUPGRADE (data, SVt_PV); |
629 | svptr = SvGROW (data, len + dataoffset + 1); |
968 | svptr = SvGROW (data, len + dataoffset + 1); |
630 | } |
969 | } |
631 | |
970 | |
632 | if (len < 0) |
|
|
633 | croak ("length must not be negative"); |
|
|
634 | |
|
|
635 | { |
971 | { |
636 | dREQ; |
972 | dREQ; |
637 | |
973 | |
638 | req->type = ix; |
974 | req->type = ix; |
639 | req->sv1 = newSVsv (fh); |
975 | req->sv1 = newSVsv (fh); |
640 | req->int1 = PerlIO_fileno (ix == EIO_READ ? IoIFP (sv_2io (fh)) |
976 | req->int1 = fd; |
641 | : IoOFP (sv_2io (fh))); |
|
|
642 | req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
977 | req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
643 | req->size = len; |
978 | req->size = len; |
644 | req->sv2 = SvREFCNT_inc (data); |
979 | req->sv2 = SvREFCNT_inc (data); |
645 | req->ptr2 = (char *)svptr + dataoffset; |
980 | req->ptr2 = (char *)svptr + dataoffset; |
646 | req->stroffset = dataoffset; |
981 | req->stroffset = dataoffset; |
… | |
… | |
655 | } |
990 | } |
656 | } |
991 | } |
657 | |
992 | |
658 | void |
993 | void |
659 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
994 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
660 | PROTOTYPE: $$;$ |
|
|
661 | PPCODE: |
995 | PPCODE: |
662 | { |
996 | { |
663 | SV *data; |
997 | SV *data; |
664 | dREQ; |
998 | dREQ; |
665 | |
999 | |
… | |
… | |
669 | |
1003 | |
670 | REQ_SEND; |
1004 | REQ_SEND; |
671 | } |
1005 | } |
672 | |
1006 | |
673 | void |
1007 | void |
674 | aio_sendfile (SV *out_fh, SV *in_fh, SV *in_offset, UV length, SV *callback=&PL_sv_undef) |
1008 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
675 | PROTOTYPE: $$$$;$ |
|
|
676 | PPCODE: |
1009 | PPCODE: |
677 | { |
1010 | { |
|
|
1011 | int ifd = s_fileno_croak (in_fh , 0); |
|
|
1012 | int ofd = s_fileno_croak (out_fh, 1); |
678 | dREQ; |
1013 | dREQ; |
679 | |
1014 | |
680 | req->type = EIO_SENDFILE; |
1015 | req->type = EIO_SENDFILE; |
681 | req->sv1 = newSVsv (out_fh); |
1016 | req->sv1 = newSVsv (out_fh); |
682 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (out_fh))); |
1017 | req->int1 = ofd; |
683 | req->sv2 = newSVsv (in_fh); |
1018 | req->sv2 = newSVsv (in_fh); |
684 | req->int2 = PerlIO_fileno (IoIFP (sv_2io (in_fh))); |
1019 | req->int2 = ifd; |
685 | req->offs = SvVAL64 (in_offset); |
1020 | req->offs = in_offset; |
686 | req->size = length; |
1021 | req->size = length; |
687 | |
1022 | |
688 | REQ_SEND; |
1023 | REQ_SEND; |
689 | } |
1024 | } |
690 | |
1025 | |
691 | void |
1026 | void |
692 | aio_readahead (SV *fh, SV *offset, IV length, SV *callback=&PL_sv_undef) |
1027 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
693 | PROTOTYPE: $$$;$ |
|
|
694 | PPCODE: |
1028 | PPCODE: |
695 | { |
1029 | { |
|
|
1030 | int fd = s_fileno_croak (fh, 0); |
696 | dREQ; |
1031 | dREQ; |
697 | |
1032 | |
698 | req->type = EIO_READAHEAD; |
1033 | req->type = EIO_READAHEAD; |
699 | req->sv1 = newSVsv (fh); |
1034 | req->sv1 = newSVsv (fh); |
700 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh))); |
1035 | req->int1 = fd; |
701 | req->offs = SvVAL64 (offset); |
1036 | req->offs = offset; |
702 | req->size = length; |
1037 | req->size = length; |
703 | |
1038 | |
704 | REQ_SEND; |
1039 | REQ_SEND; |
705 | } |
1040 | } |
706 | |
1041 | |
707 | void |
1042 | void |
708 | aio_stat (SV8 *fh_or_path, SV *callback=&PL_sv_undef) |
1043 | aio_stat (SV8 *fh_or_path, SV *callback=&PL_sv_undef) |
709 | ALIAS: |
1044 | ALIAS: |
710 | aio_stat = EIO_STAT |
1045 | aio_stat = EIO_STAT |
711 | aio_lstat = EIO_LSTAT |
1046 | aio_lstat = EIO_LSTAT |
|
|
1047 | aio_statvfs = EIO_STATVFS |
712 | PPCODE: |
1048 | PPCODE: |
713 | { |
1049 | { |
714 | dREQ; |
1050 | dREQ; |
715 | |
1051 | |
716 | req->sv1 = newSVsv (fh_or_path); |
1052 | req->sv1 = newSVsv (fh_or_path); |
… | |
… | |
720 | req->type = ix; |
1056 | req->type = ix; |
721 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
1057 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
722 | } |
1058 | } |
723 | else |
1059 | else |
724 | { |
1060 | { |
725 | req->type = EIO_FSTAT; |
1061 | req->type = ix == EIO_STATVFS ? EIO_FSTATVFS : EIO_FSTAT; |
726 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
1062 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
727 | } |
1063 | } |
728 | |
1064 | |
729 | REQ_SEND; |
1065 | REQ_SEND; |
730 | } |
1066 | } |
… | |
… | |
825 | |
1161 | |
826 | REQ_SEND; |
1162 | REQ_SEND; |
827 | } |
1163 | } |
828 | |
1164 | |
829 | void |
1165 | void |
|
|
1166 | aio_readdirx (SV8 *pathname, IV flags, SV *callback=&PL_sv_undef) |
|
|
1167 | PPCODE: |
|
|
1168 | { |
|
|
1169 | dREQ; |
|
|
1170 | |
|
|
1171 | req->type = EIO_READDIR; |
|
|
1172 | req->sv1 = newSVsv (pathname); |
|
|
1173 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
1174 | req->int1 = flags | EIO_READDIR_DENTS | EIO_READDIR_CUSTOM1; |
|
|
1175 | |
|
|
1176 | if (flags & EIO_READDIR_DENTS) |
|
|
1177 | req->int1 |= EIO_READDIR_CUSTOM2; |
|
|
1178 | |
|
|
1179 | REQ_SEND; |
|
|
1180 | } |
|
|
1181 | |
|
|
1182 | void |
830 | aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
1183 | aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
831 | ALIAS: |
1184 | ALIAS: |
832 | aio_unlink = EIO_UNLINK |
1185 | aio_unlink = EIO_UNLINK |
833 | aio_rmdir = EIO_RMDIR |
1186 | aio_rmdir = EIO_RMDIR |
834 | aio_readdir = EIO_READDIR |
1187 | aio_readdir = EIO_READDIR |
… | |
… | |
876 | |
1229 | |
877 | REQ_SEND; |
1230 | REQ_SEND; |
878 | } |
1231 | } |
879 | |
1232 | |
880 | void |
1233 | void |
|
|
1234 | aio_mtouch (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, int flags = 0, SV *callback=&PL_sv_undef) |
|
|
1235 | ALIAS: |
|
|
1236 | aio_mtouch = EIO_MTOUCH |
|
|
1237 | aio_msync = EIO_MSYNC |
|
|
1238 | PPCODE: |
|
|
1239 | { |
|
|
1240 | STRLEN svlen; |
|
|
1241 | char *svptr = SvPVbyte (data, svlen); |
|
|
1242 | UV len = SvUV (length); |
|
|
1243 | |
|
|
1244 | if (offset < 0) |
|
|
1245 | offset += svlen; |
|
|
1246 | |
|
|
1247 | if (offset < 0 || offset > svlen) |
|
|
1248 | croak ("offset outside of scalar"); |
|
|
1249 | |
|
|
1250 | if (!SvOK (length) || len + offset > svlen) |
|
|
1251 | len = svlen - offset; |
|
|
1252 | |
|
|
1253 | { |
|
|
1254 | dREQ; |
|
|
1255 | |
|
|
1256 | req->type = ix; |
|
|
1257 | req->sv2 = SvREFCNT_inc (data); |
|
|
1258 | req->ptr2 = (char *)svptr + offset; |
|
|
1259 | req->size = len; |
|
|
1260 | req->int1 = flags; |
|
|
1261 | |
|
|
1262 | REQ_SEND; |
|
|
1263 | } |
|
|
1264 | } |
|
|
1265 | |
|
|
1266 | void |
|
|
1267 | aio_mlock (SV8 *data, IV offset = 0, SV *length = &PL_sv_undef, SV *callback=&PL_sv_undef) |
|
|
1268 | PPCODE: |
|
|
1269 | { |
|
|
1270 | STRLEN svlen; |
|
|
1271 | char *svptr = SvPVbyte (data, svlen); |
|
|
1272 | UV len = SvUV (length); |
|
|
1273 | |
|
|
1274 | if (offset < 0) |
|
|
1275 | offset += svlen; |
|
|
1276 | |
|
|
1277 | if (offset < 0 || offset > svlen) |
|
|
1278 | croak ("offset outside of scalar"); |
|
|
1279 | |
|
|
1280 | if (!SvOK (length) || len + offset > svlen) |
|
|
1281 | len = svlen - offset; |
|
|
1282 | |
|
|
1283 | { |
|
|
1284 | dREQ; |
|
|
1285 | |
|
|
1286 | req->type = EIO_MLOCK; |
|
|
1287 | req->sv2 = SvREFCNT_inc (data); |
|
|
1288 | req->ptr2 = (char *)svptr + offset; |
|
|
1289 | req->size = len; |
|
|
1290 | |
|
|
1291 | REQ_SEND; |
|
|
1292 | } |
|
|
1293 | } |
|
|
1294 | |
|
|
1295 | void |
|
|
1296 | aio_mlockall (IV flags, SV *callback=&PL_sv_undef) |
|
|
1297 | PPCODE: |
|
|
1298 | { |
|
|
1299 | dREQ; |
|
|
1300 | |
|
|
1301 | req->type = EIO_MLOCKALL; |
|
|
1302 | req->int1 = flags; |
|
|
1303 | |
|
|
1304 | REQ_SEND; |
|
|
1305 | } |
|
|
1306 | |
|
|
1307 | void |
881 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
1308 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
882 | PPCODE: |
1309 | PPCODE: |
883 | { |
1310 | { |
884 | dREQ; |
1311 | dREQ; |
885 | |
1312 | |
… | |
… | |
889 | REQ_SEND; |
1316 | REQ_SEND; |
890 | } |
1317 | } |
891 | |
1318 | |
892 | void |
1319 | void |
893 | aio_group (SV *callback=&PL_sv_undef) |
1320 | aio_group (SV *callback=&PL_sv_undef) |
894 | PROTOTYPE: ;$ |
|
|
895 | PPCODE: |
1321 | PPCODE: |
896 | { |
1322 | { |
897 | dREQ; |
1323 | dREQ; |
898 | |
1324 | |
899 | req->type = EIO_GROUP; |
1325 | req->type = EIO_GROUP; |
900 | |
1326 | |
901 | eio_submit (req); |
1327 | req_submit (req); |
902 | XPUSHs (req_sv (req, AIO_GRP_KLASS)); |
1328 | XPUSHs (req_sv (req, aio_grp_stash)); |
903 | } |
1329 | } |
904 | |
1330 | |
905 | void |
1331 | void |
906 | aio_nop (SV *callback=&PL_sv_undef) |
1332 | aio_nop (SV *callback=&PL_sv_undef) |
907 | ALIAS: |
1333 | ALIAS: |
… | |
… | |
916 | REQ_SEND; |
1342 | REQ_SEND; |
917 | } |
1343 | } |
918 | |
1344 | |
919 | int |
1345 | int |
920 | aioreq_pri (int pri = 0) |
1346 | aioreq_pri (int pri = 0) |
921 | PROTOTYPE: ;$ |
|
|
922 | CODE: |
1347 | CODE: |
923 | RETVAL = next_pri; |
1348 | RETVAL = next_pri; |
924 | if (items > 0) |
1349 | if (items > 0) |
925 | { |
1350 | { |
926 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
1351 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
… | |
… | |
938 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
1363 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
939 | next_pri = nice; |
1364 | next_pri = nice; |
940 | |
1365 | |
941 | void |
1366 | void |
942 | flush () |
1367 | flush () |
943 | PROTOTYPE: |
|
|
944 | CODE: |
1368 | CODE: |
945 | while (eio_nreqs ()) |
1369 | while (eio_nreqs ()) |
946 | { |
1370 | { |
947 | poll_wait (); |
1371 | poll_wait (); |
948 | poll_cb (); |
1372 | poll_cb (); |
949 | } |
1373 | } |
950 | |
1374 | |
951 | int |
1375 | int |
952 | poll() |
1376 | poll () |
953 | PROTOTYPE: |
|
|
954 | CODE: |
1377 | CODE: |
955 | poll_wait (); |
1378 | poll_wait (); |
956 | RETVAL = poll_cb (); |
1379 | RETVAL = poll_cb (); |
957 | OUTPUT: |
1380 | OUTPUT: |
958 | RETVAL |
1381 | RETVAL |
959 | |
1382 | |
960 | int |
1383 | int |
961 | poll_fileno() |
1384 | poll_fileno () |
962 | PROTOTYPE: |
|
|
963 | CODE: |
1385 | CODE: |
964 | RETVAL = respipe [0]; |
1386 | RETVAL = s_epipe_fd (&respipe); |
965 | OUTPUT: |
1387 | OUTPUT: |
966 | RETVAL |
1388 | RETVAL |
967 | |
1389 | |
968 | int |
1390 | int |
969 | poll_cb(...) |
1391 | poll_cb (...) |
970 | PROTOTYPE: |
1392 | PROTOTYPE: |
971 | CODE: |
1393 | CODE: |
972 | RETVAL = poll_cb (); |
1394 | RETVAL = poll_cb (); |
973 | OUTPUT: |
1395 | OUTPUT: |
974 | RETVAL |
1396 | RETVAL |
975 | |
1397 | |
976 | void |
1398 | void |
977 | poll_wait() |
1399 | poll_wait () |
978 | PROTOTYPE: |
|
|
979 | CODE: |
1400 | CODE: |
980 | poll_wait (); |
1401 | poll_wait (); |
981 | |
1402 | |
982 | int |
1403 | int |
983 | nreqs() |
1404 | nreqs () |
984 | PROTOTYPE: |
|
|
985 | CODE: |
1405 | CODE: |
986 | RETVAL = eio_nreqs (); |
1406 | RETVAL = eio_nreqs (); |
987 | OUTPUT: |
1407 | OUTPUT: |
988 | RETVAL |
1408 | RETVAL |
989 | |
1409 | |
990 | int |
1410 | int |
991 | nready() |
1411 | nready () |
992 | PROTOTYPE: |
|
|
993 | CODE: |
1412 | CODE: |
994 | RETVAL = eio_nready (); |
1413 | RETVAL = eio_nready (); |
995 | OUTPUT: |
1414 | OUTPUT: |
996 | RETVAL |
1415 | RETVAL |
997 | |
1416 | |
998 | int |
1417 | int |
999 | npending() |
1418 | npending () |
1000 | PROTOTYPE: |
|
|
1001 | CODE: |
1419 | CODE: |
1002 | RETVAL = eio_npending (); |
1420 | RETVAL = eio_npending (); |
1003 | OUTPUT: |
1421 | OUTPUT: |
1004 | RETVAL |
1422 | RETVAL |
1005 | |
1423 | |
1006 | int |
1424 | int |
1007 | nthreads() |
1425 | nthreads () |
1008 | PROTOTYPE: |
|
|
1009 | CODE: |
1426 | CODE: |
1010 | RETVAL = eio_nthreads (); |
1427 | RETVAL = eio_nthreads (); |
1011 | OUTPUT: |
1428 | OUTPUT: |
1012 | RETVAL |
1429 | RETVAL |
1013 | |
1430 | |
|
|
1431 | int |
|
|
1432 | fadvise (aio_rfd fh, off_t offset, off_t length, IV advice) |
|
|
1433 | CODE: |
|
|
1434 | RETVAL = posix_fadvise (fh, offset, length, advice); |
|
|
1435 | OUTPUT: |
|
|
1436 | RETVAL |
|
|
1437 | |
|
|
1438 | ssize_t |
|
|
1439 | sendfile (aio_wfd ofh, aio_rfd ifh, off_t offset, size_t count) |
|
|
1440 | CODE: |
|
|
1441 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
|
|
1442 | OUTPUT: |
|
|
1443 | RETVAL |
|
|
1444 | |
|
|
1445 | void |
|
|
1446 | mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) |
|
|
1447 | PPCODE: |
|
|
1448 | sv_unmagic (scalar, MMAP_MAGIC); |
|
|
1449 | { |
|
|
1450 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
|
|
1451 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
|
|
1452 | if (addr == (void *)-1) |
|
|
1453 | XSRETURN_NO; |
|
|
1454 | |
|
|
1455 | sv_force_normal (scalar); |
|
|
1456 | |
|
|
1457 | /* we store the length in mg_obj, as namlen is I32 :/ */ |
|
|
1458 | sv_magicext (scalar, 0, MMAP_MAGIC, &mmap_vtbl, (char *)addr, 0) |
|
|
1459 | ->mg_obj = (SV *)length; |
|
|
1460 | |
|
|
1461 | SvUPGRADE (scalar, SVt_PV); /* nop... */ |
|
|
1462 | |
|
|
1463 | if (!(prot & PROT_WRITE)) |
|
|
1464 | SvREADONLY_on (scalar); |
|
|
1465 | |
|
|
1466 | if (SvLEN (scalar)) |
|
|
1467 | Safefree (SvPVX (scalar)); |
|
|
1468 | |
|
|
1469 | SvPVX (scalar) = (char *)addr; |
|
|
1470 | SvCUR_set (scalar, length); |
|
|
1471 | SvLEN_set (scalar, 0); |
|
|
1472 | SvPOK_only (scalar); |
|
|
1473 | |
|
|
1474 | XSRETURN_YES; |
|
|
1475 | } |
|
|
1476 | |
|
|
1477 | void |
|
|
1478 | munmap (SV *scalar) |
|
|
1479 | CODE: |
|
|
1480 | sv_unmagic (scalar, MMAP_MAGIC); |
|
|
1481 | |
|
|
1482 | int |
|
|
1483 | madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
|
|
1484 | ALIAS: |
|
|
1485 | mprotect = 1 |
|
|
1486 | CODE: |
|
|
1487 | { |
|
|
1488 | STRLEN svlen; |
|
|
1489 | void *addr = SvPVbyte (scalar, svlen); |
|
|
1490 | size_t len = SvUV (length); |
|
|
1491 | |
|
|
1492 | if (offset < 0) |
|
|
1493 | offset += svlen; |
|
|
1494 | |
|
|
1495 | if (offset < 0 || offset > svlen) |
|
|
1496 | croak ("offset outside of scalar"); |
|
|
1497 | |
|
|
1498 | if (!SvOK (length) || len + offset > svlen) |
|
|
1499 | len = svlen - offset; |
|
|
1500 | |
|
|
1501 | addr = (void *)(((intptr_t)addr) + offset); |
|
|
1502 | eio_page_align (&addr, &len); |
|
|
1503 | |
|
|
1504 | switch (ix) |
|
|
1505 | { |
|
|
1506 | case 0: RETVAL = posix_madvise (addr, len, advice_or_prot); break; |
|
|
1507 | case 1: RETVAL = mprotect (addr, len, advice_or_prot); break; |
|
|
1508 | } |
|
|
1509 | } |
|
|
1510 | OUTPUT: |
|
|
1511 | RETVAL |
|
|
1512 | |
|
|
1513 | int |
|
|
1514 | munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef) |
|
|
1515 | CODE: |
|
|
1516 | { |
|
|
1517 | STRLEN svlen; |
|
|
1518 | void *addr = SvPVbyte (scalar, svlen); |
|
|
1519 | size_t len = SvUV (length); |
|
|
1520 | |
|
|
1521 | if (offset < 0) |
|
|
1522 | offset += svlen; |
|
|
1523 | |
|
|
1524 | if (offset < 0 || offset > svlen) |
|
|
1525 | croak ("offset outside of scalar"); |
|
|
1526 | |
|
|
1527 | if (!SvOK (length) || len + offset > svlen) |
|
|
1528 | len = svlen - offset; |
|
|
1529 | |
|
|
1530 | addr = (void *)(((intptr_t)addr) + offset); |
|
|
1531 | eio_page_align (&addr, &len); |
|
|
1532 | #if _POSIX_MEMLOCK_RANGE |
|
|
1533 | RETVAL = munlock (addr, len); |
|
|
1534 | #else |
|
|
1535 | RETVAL = ((errno = ENOSYS), -1); |
|
|
1536 | #endif |
|
|
1537 | } |
|
|
1538 | OUTPUT: |
|
|
1539 | RETVAL |
|
|
1540 | |
|
|
1541 | int |
|
|
1542 | munlockall () |
|
|
1543 | CODE: |
|
|
1544 | #if _POSIX_MEMLOCK |
|
|
1545 | munlockall (); |
|
|
1546 | #else |
|
|
1547 | RETVAL = -1; |
|
|
1548 | errno = ENOSYS; |
|
|
1549 | #endif |
|
|
1550 | OUTPUT: |
|
|
1551 | RETVAL |
|
|
1552 | |
1014 | void _on_next_submit (SV *cb) |
1553 | void _on_next_submit (SV *cb) |
1015 | CODE: |
1554 | CODE: |
1016 | SvREFCNT_dec (on_next_submit); |
1555 | SvREFCNT_dec (on_next_submit); |
1017 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1556 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
1018 | |
1557 | |
… | |
… | |
1025 | CODE: |
1564 | CODE: |
1026 | eio_cancel (req); |
1565 | eio_cancel (req); |
1027 | |
1566 | |
1028 | void |
1567 | void |
1029 | cb (aio_req_ornot req, SV *callback=&PL_sv_undef) |
1568 | cb (aio_req_ornot req, SV *callback=&PL_sv_undef) |
1030 | CODE: |
1569 | PPCODE: |
|
|
1570 | { |
|
|
1571 | if (GIMME_V != G_VOID) |
|
|
1572 | XPUSHs (req->callback ? sv_2mortal (newRV_inc (req->callback)) : &PL_sv_undef); |
|
|
1573 | |
|
|
1574 | if (items > 1) |
|
|
1575 | { |
|
|
1576 | SV *cb_cv =get_cb (callback); |
|
|
1577 | |
1031 | SvREFCNT_dec (req->callback); |
1578 | SvREFCNT_dec (req->callback); |
1032 | req->callback = newSVsv (callback); |
1579 | req->callback = SvREFCNT_inc (cb_cv); |
|
|
1580 | } |
|
|
1581 | } |
1033 | |
1582 | |
1034 | MODULE = IO::AIO PACKAGE = IO::AIO::GRP |
1583 | MODULE = IO::AIO PACKAGE = IO::AIO::GRP |
1035 | |
1584 | |
1036 | void |
1585 | void |
1037 | add (aio_req grp, ...) |
1586 | add (aio_req grp, ...) |
… | |
… | |
1069 | AV *av; |
1618 | AV *av; |
1070 | |
1619 | |
1071 | grp->errorno = errno; |
1620 | grp->errorno = errno; |
1072 | |
1621 | |
1073 | av = newAV (); |
1622 | av = newAV (); |
|
|
1623 | av_extend (av, items - 1); |
1074 | |
1624 | |
1075 | for (i = 1; i < items; ++i ) |
1625 | for (i = 1; i < items; ++i ) |
1076 | av_push (av, newSVsv (ST (i))); |
1626 | av_push (av, newSVsv (ST (i))); |
1077 | |
1627 | |
1078 | SvREFCNT_dec (grp->sv1); |
1628 | SvREFCNT_dec (grp->sv1); |
… | |
… | |
1092 | void |
1642 | void |
1093 | feed (aio_req grp, SV *callback=&PL_sv_undef) |
1643 | feed (aio_req grp, SV *callback=&PL_sv_undef) |
1094 | CODE: |
1644 | CODE: |
1095 | { |
1645 | { |
1096 | SvREFCNT_dec (grp->sv2); |
1646 | SvREFCNT_dec (grp->sv2); |
1097 | grp->sv2 = newSVsv (callback); |
1647 | grp->sv2 = newSVsv (callback); |
|
|
1648 | grp->feed = aio_grp_feed; |
1098 | |
1649 | |
1099 | if (grp->int2 <= 0) |
1650 | if (grp->int2 <= 0) |
1100 | grp->int2 = 2; |
1651 | grp->int2 = 2; |
1101 | |
1652 | |
1102 | eio_grp_limit (grp, grp->int2); |
1653 | eio_grp_limit (grp, grp->int2); |