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