1 | #define _REENTRANT 1 |
1 | #include "libeio/xthread.h" |
|
|
2 | |
2 | #include <errno.h> |
3 | #include <errno.h> |
3 | |
4 | |
4 | #include "EXTERN.h" |
5 | #include "EXTERN.h" |
5 | #include "perl.h" |
6 | #include "perl.h" |
6 | #include "XSUB.h" |
7 | #include "XSUB.h" |
7 | |
8 | |
8 | #include "autoconf/config.h" |
9 | #include <stddef.h> |
9 | |
10 | #include <stdlib.h> |
|
|
11 | #include <errno.h> |
10 | #include <sys/types.h> |
12 | #include <sys/types.h> |
11 | #include <sys/stat.h> |
13 | #include <sys/stat.h> |
12 | |
|
|
13 | #include <unistd.h> |
14 | #include <limits.h> |
14 | #include <fcntl.h> |
15 | #include <fcntl.h> |
15 | #include <signal.h> |
|
|
16 | #include <sched.h> |
16 | #include <sched.h> |
17 | |
17 | |
18 | #include <pthread.h> |
18 | /* perl namespace pollution */ |
|
|
19 | #undef VERSION |
19 | |
20 | |
20 | typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
21 | #ifdef _WIN32 |
21 | typedef void *OutputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
|
|
22 | typedef void *InOutStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
|
|
23 | |
22 | |
24 | #if __ia64 |
23 | # define EIO_STRUCT_DIRENT Direntry_t |
25 | # define STACKSIZE 65536 |
24 | # undef malloc |
|
|
25 | # undef free |
|
|
26 | |
|
|
27 | // perl overrides all those nice win32 functions |
|
|
28 | # undef open |
|
|
29 | # undef read |
|
|
30 | # undef write |
|
|
31 | # undef send |
|
|
32 | # undef recv |
|
|
33 | # undef stat |
|
|
34 | # undef fstat |
|
|
35 | # define lstat stat |
|
|
36 | # undef truncate |
|
|
37 | # undef ftruncate |
|
|
38 | # undef open |
|
|
39 | # undef close |
|
|
40 | # undef unlink |
|
|
41 | # undef rmdir |
|
|
42 | # undef rename |
|
|
43 | # undef lseek |
|
|
44 | |
|
|
45 | # define chown(a,b,c) (errno = ENOSYS, -1) |
|
|
46 | # define fchown(a,b,c) (errno = ENOSYS, -1) |
|
|
47 | # define fchmod(a,b) (errno = ENOSYS, -1) |
|
|
48 | # define symlink(a,b) (errno = ENOSYS, -1) |
|
|
49 | # define readlink(a,b,c) (errno = ENOSYS, -1) |
|
|
50 | # define mknod(a,b,c) (errno = ENOSYS, -1) |
|
|
51 | # define truncate(a,b) (errno = ENOSYS, -1) |
|
|
52 | # define ftruncate(fd,o) chsize ((fd), (o)) |
|
|
53 | # define fsync(fd) _commit (fd) |
|
|
54 | # define opendir(fd) (errno = ENOSYS, 0) |
|
|
55 | # define readdir(fd) (errno = ENOSYS, -1) |
|
|
56 | # define closedir(fd) (errno = ENOSYS, -1) |
|
|
57 | # define mkdir(a,b) mkdir (a) |
|
|
58 | |
26 | #else |
59 | #else |
27 | # define STACKSIZE 4096 |
60 | |
|
|
61 | # include <sys/time.h> |
|
|
62 | # include <sys/select.h> |
|
|
63 | # include <unistd.h> |
|
|
64 | # include <utime.h> |
|
|
65 | # include <signal.h> |
|
|
66 | # define EIO_STRUCT_DIRENT struct dirent |
|
|
67 | |
28 | #endif |
68 | #endif |
29 | |
69 | |
|
|
70 | /* perl stupidly overrides readdir and maybe others */ |
|
|
71 | /* with thread-unsafe versions, imagine that :( */ |
|
|
72 | #undef readdir |
|
|
73 | #undef opendir |
|
|
74 | #undef closedir |
|
|
75 | |
|
|
76 | #define EIO_STRUCT_STAT Stat_t |
|
|
77 | |
|
|
78 | /* use NV for 32 bit perls as it allows larger offsets */ |
|
|
79 | #if IVSIZE >= 8 |
|
|
80 | # define SvVAL64 SvIV |
|
|
81 | #else |
|
|
82 | # define SvVAL64 SvNV |
|
|
83 | #endif |
|
|
84 | |
|
|
85 | /*****************************************************************************/ |
|
|
86 | |
|
|
87 | #if __GNUC__ >= 3 |
|
|
88 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
|
|
89 | #else |
|
|
90 | # define expect(expr,value) (expr) |
|
|
91 | #endif |
|
|
92 | |
|
|
93 | #define expect_false(expr) expect ((expr) != 0, 0) |
|
|
94 | #define expect_true(expr) expect ((expr) != 0, 1) |
|
|
95 | |
|
|
96 | /*****************************************************************************/ |
|
|
97 | |
|
|
98 | static HV *stash; |
|
|
99 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
|
|
100 | |
|
|
101 | #define AIO_REQ_KLASS "IO::AIO::REQ" |
|
|
102 | #define AIO_GRP_KLASS "IO::AIO::GRP" |
|
|
103 | |
|
|
104 | #define EIO_REQ_MEMBERS \ |
|
|
105 | SV *callback; \ |
|
|
106 | SV *sv1, *sv2; \ |
|
|
107 | STRLEN stroffset; \ |
|
|
108 | SV *self; |
|
|
109 | |
|
|
110 | #define EIO_NO_WRAPPERS 1 |
|
|
111 | |
|
|
112 | #include "libeio/eio.h" |
|
|
113 | |
|
|
114 | static int req_invoke (eio_req *req); |
|
|
115 | #define EIO_FINISH(req) req_invoke (req) |
|
|
116 | static void req_destroy (eio_req *grp); |
|
|
117 | #define EIO_DESTROY(req) req_destroy (req) |
|
|
118 | |
30 | enum { |
119 | enum { |
31 | REQ_QUIT, |
120 | FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */ |
32 | REQ_OPEN, REQ_CLOSE, |
|
|
33 | REQ_READ, REQ_WRITE, REQ_READAHEAD, |
|
|
34 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, |
|
|
35 | REQ_FSYNC, REQ_FDATASYNC, |
|
|
36 | REQ_UNLINK, REQ_RMDIR, |
|
|
37 | REQ_SYMLINK, |
|
|
38 | }; |
121 | }; |
39 | |
122 | |
40 | typedef struct aio_cb { |
123 | #include "libeio/eio.c" |
41 | struct aio_cb *volatile next; |
|
|
42 | |
124 | |
43 | int type; |
|
|
44 | |
|
|
45 | int fd; |
|
|
46 | off_t offset; |
|
|
47 | size_t length; |
|
|
48 | ssize_t result; |
|
|
49 | mode_t mode; /* open */ |
|
|
50 | int errorno; |
|
|
51 | SV *data, *callback, *fh; |
|
|
52 | void *dataptr, *data2ptr; |
|
|
53 | STRLEN dataoffset; |
|
|
54 | |
|
|
55 | Stat_t *statdata; |
|
|
56 | } aio_cb; |
|
|
57 | |
|
|
58 | typedef aio_cb *aio_req; |
125 | typedef eio_req *aio_req; |
|
|
126 | typedef eio_req *aio_req_ornot; |
59 | |
127 | |
60 | static int started; |
128 | static SV *on_next_submit; |
61 | static volatile int nreqs; |
129 | static int next_pri = EIO_PRI_DEFAULT; |
62 | static int max_outstanding = 1<<30; |
130 | static int max_outstanding; |
63 | static int respipe [2]; |
|
|
64 | |
131 | |
65 | static pthread_mutex_t reslock = PTHREAD_MUTEX_INITIALIZER; |
132 | static int respipe_osf [2], respipe [2] = { -1, -1 }; |
66 | static pthread_mutex_t reqlock = PTHREAD_MUTEX_INITIALIZER; |
|
|
67 | static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; |
|
|
68 | |
133 | |
69 | static volatile aio_req reqs, reqe; /* queue start, queue end */ |
134 | static void req_destroy (aio_req req); |
70 | static volatile aio_req ress, rese; /* queue start, queue end */ |
|
|
71 | |
|
|
72 | static void free_req (aio_req req) |
135 | static void req_cancel (aio_req req); |
73 | { |
|
|
74 | if (req->data) |
|
|
75 | SvREFCNT_dec (req->data); |
|
|
76 | |
136 | |
|
|
137 | static void want_poll (void) |
|
|
138 | { |
|
|
139 | /* write a dummy byte to the pipe so fh becomes ready */ |
|
|
140 | respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1); |
|
|
141 | } |
|
|
142 | |
|
|
143 | static void done_poll (void) |
|
|
144 | { |
|
|
145 | /* read any signals sent by the worker threads */ |
|
|
146 | char buf [4]; |
|
|
147 | while (respipe_read (respipe [0], buf, 4) == 4) |
|
|
148 | ; |
|
|
149 | } |
|
|
150 | |
|
|
151 | /* must be called at most once */ |
|
|
152 | static SV *req_sv (aio_req req, const char *klass) |
|
|
153 | { |
|
|
154 | if (!req->self) |
|
|
155 | { |
|
|
156 | req->self = (SV *)newHV (); |
|
|
157 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
|
|
158 | } |
|
|
159 | |
|
|
160 | return sv_2mortal (sv_bless (newRV_inc (req->self), gv_stashpv (klass, 1))); |
|
|
161 | } |
|
|
162 | |
|
|
163 | static aio_req SvAIO_REQ (SV *sv) |
|
|
164 | { |
|
|
165 | MAGIC *mg; |
|
|
166 | |
|
|
167 | if (!sv_derived_from (sv, AIO_REQ_KLASS) || !SvROK (sv)) |
|
|
168 | croak ("object of class " AIO_REQ_KLASS " expected"); |
|
|
169 | |
|
|
170 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
|
|
171 | |
|
|
172 | return mg ? (aio_req)mg->mg_ptr : 0; |
|
|
173 | } |
|
|
174 | |
|
|
175 | static void aio_grp_feed (aio_req grp) |
|
|
176 | { |
|
|
177 | if (grp->sv2 && SvOK (grp->sv2)) |
|
|
178 | { |
|
|
179 | dSP; |
|
|
180 | |
|
|
181 | ENTER; |
|
|
182 | SAVETMPS; |
|
|
183 | PUSHMARK (SP); |
|
|
184 | XPUSHs (req_sv (grp, AIO_GRP_KLASS)); |
|
|
185 | PUTBACK; |
|
|
186 | call_sv (grp->sv2, G_VOID | G_EVAL | G_KEEPERR); |
|
|
187 | SPAGAIN; |
|
|
188 | FREETMPS; |
|
|
189 | LEAVE; |
|
|
190 | } |
|
|
191 | } |
|
|
192 | |
|
|
193 | static void req_submit (eio_req *req) |
|
|
194 | { |
|
|
195 | eio_submit (req); |
|
|
196 | |
|
|
197 | if (expect_false (on_next_submit)) |
|
|
198 | { |
|
|
199 | dSP; |
|
|
200 | SV *cb = sv_2mortal (on_next_submit); |
|
|
201 | |
|
|
202 | on_next_submit = 0; |
|
|
203 | |
|
|
204 | PUSHMARK (SP); |
|
|
205 | PUTBACK; |
|
|
206 | call_sv (cb, G_DISCARD | G_EVAL); |
|
|
207 | } |
|
|
208 | } |
|
|
209 | |
|
|
210 | static int req_invoke (eio_req *req) |
|
|
211 | { |
|
|
212 | dSP; |
|
|
213 | |
|
|
214 | if (req->flags & FLAG_SV2_RO_OFF) |
|
|
215 | SvREADONLY_off (req->sv2); |
|
|
216 | |
|
|
217 | if (!EIO_CANCELLED (req) && req->callback) |
|
|
218 | { |
|
|
219 | ENTER; |
|
|
220 | SAVETMPS; |
|
|
221 | PUSHMARK (SP); |
|
|
222 | EXTEND (SP, 1); |
|
|
223 | |
|
|
224 | switch (req->type) |
|
|
225 | { |
|
|
226 | case EIO_READDIR: |
|
|
227 | { |
|
|
228 | SV *rv = &PL_sv_undef; |
|
|
229 | |
|
|
230 | if (req->result >= 0) |
|
|
231 | { |
|
|
232 | int i; |
|
|
233 | char *buf = req->ptr2; |
|
|
234 | AV *av = newAV (); |
|
|
235 | |
|
|
236 | av_extend (av, req->result - 1); |
|
|
237 | |
|
|
238 | for (i = 0; i < req->result; ++i) |
|
|
239 | { |
|
|
240 | SV *sv = newSVpv (buf, 0); |
|
|
241 | |
|
|
242 | av_store (av, i, sv); |
|
|
243 | buf += SvCUR (sv) + 1; |
|
|
244 | } |
|
|
245 | |
|
|
246 | rv = sv_2mortal (newRV_noinc ((SV *)av)); |
|
|
247 | } |
|
|
248 | |
|
|
249 | PUSHs (rv); |
|
|
250 | } |
|
|
251 | break; |
|
|
252 | |
|
|
253 | case EIO_OPEN: |
|
|
254 | { |
|
|
255 | /* convert fd to fh */ |
|
|
256 | SV *fh = &PL_sv_undef; |
|
|
257 | |
|
|
258 | if (req->result >= 0) |
|
|
259 | { |
|
|
260 | GV *gv = (GV *)sv_newmortal (); |
|
|
261 | int flags = req->int1 & (O_RDONLY | O_WRONLY | O_RDWR); |
|
|
262 | char sym [64]; |
|
|
263 | int symlen; |
|
|
264 | |
|
|
265 | symlen = snprintf (sym, sizeof (sym), "fd#%d", req->result); |
|
|
266 | gv_init (gv, stash, sym, symlen, 0); |
|
|
267 | |
|
|
268 | symlen = snprintf ( |
|
|
269 | sym, |
|
|
270 | sizeof (sym), |
|
|
271 | "%s&=%d", |
|
|
272 | flags == O_RDONLY ? "<" : flags == O_WRONLY ? ">" : "+<", |
|
|
273 | req->result |
|
|
274 | ); |
|
|
275 | |
|
|
276 | if (do_open (gv, sym, symlen, 0, 0, 0, 0)) |
|
|
277 | fh = (SV *)gv; |
|
|
278 | } |
|
|
279 | |
|
|
280 | PUSHs (fh); |
|
|
281 | } |
|
|
282 | break; |
|
|
283 | |
|
|
284 | case EIO_GROUP: |
|
|
285 | req->int1 = 2; /* mark group as finished */ |
|
|
286 | |
|
|
287 | if (req->sv1) |
|
|
288 | { |
|
|
289 | int i; |
|
|
290 | AV *av = (AV *)req->sv1; |
|
|
291 | |
|
|
292 | EXTEND (SP, AvFILL (av) + 1); |
|
|
293 | for (i = 0; i <= AvFILL (av); ++i) |
|
|
294 | PUSHs (*av_fetch (av, i, 0)); |
|
|
295 | } |
|
|
296 | break; |
|
|
297 | |
|
|
298 | case EIO_NOP: |
|
|
299 | case EIO_BUSY: |
|
|
300 | break; |
|
|
301 | |
|
|
302 | case EIO_READLINK: |
|
|
303 | if (req->result > 0) |
|
|
304 | PUSHs (sv_2mortal (newSVpvn (req->ptr2, req->result))); |
|
|
305 | break; |
|
|
306 | |
|
|
307 | case EIO_STAT: |
|
|
308 | case EIO_LSTAT: |
|
|
309 | case EIO_FSTAT: |
|
|
310 | PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT; |
|
|
311 | PL_laststatval = req->result; |
|
|
312 | PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2); |
|
|
313 | PUSHs (sv_2mortal (newSViv (req->result))); |
|
|
314 | break; |
|
|
315 | |
|
|
316 | case EIO_READ: |
|
|
317 | SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0)); |
|
|
318 | *SvEND (req->sv2) = 0; |
|
|
319 | PUSHs (sv_2mortal (newSViv (req->result))); |
|
|
320 | break; |
|
|
321 | |
|
|
322 | case EIO_DUP2: |
|
|
323 | if (req->result > 0) |
|
|
324 | req->result = 0; |
|
|
325 | /* FALLTHROUGH */ |
|
|
326 | |
|
|
327 | default: |
|
|
328 | PUSHs (sv_2mortal (newSViv (req->result))); |
|
|
329 | break; |
|
|
330 | } |
|
|
331 | |
|
|
332 | errno = req->errorno; |
|
|
333 | |
|
|
334 | PUTBACK; |
|
|
335 | call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD); |
|
|
336 | SPAGAIN; |
|
|
337 | |
|
|
338 | FREETMPS; |
|
|
339 | LEAVE; |
|
|
340 | |
|
|
341 | PUTBACK; |
|
|
342 | } |
|
|
343 | |
|
|
344 | return !!SvTRUE (ERRSV); |
|
|
345 | } |
|
|
346 | |
|
|
347 | static void req_destroy (aio_req req) |
|
|
348 | { |
77 | if (req->fh) |
349 | if (req->self) |
|
|
350 | { |
|
|
351 | sv_unmagic (req->self, PERL_MAGIC_ext); |
78 | SvREFCNT_dec (req->fh); |
352 | SvREFCNT_dec (req->self); |
|
|
353 | } |
79 | |
354 | |
80 | if (req->statdata) |
355 | SvREFCNT_dec (req->sv1); |
81 | Safefree (req->statdata); |
356 | SvREFCNT_dec (req->sv2); |
82 | |
|
|
83 | if (req->callback) |
|
|
84 | SvREFCNT_dec (req->callback); |
357 | SvREFCNT_dec (req->callback); |
85 | |
358 | |
86 | Safefree (req); |
359 | Safefree (req); |
87 | } |
360 | } |
88 | |
361 | |
|
|
362 | static void req_cancel_subs (aio_req grp) |
|
|
363 | { |
|
|
364 | aio_req sub; |
|
|
365 | |
|
|
366 | if (grp->type != EIO_GROUP) |
|
|
367 | return; |
|
|
368 | |
|
|
369 | SvREFCNT_dec (grp->sv2); |
|
|
370 | grp->sv2 = 0; |
|
|
371 | |
|
|
372 | eio_grp_cancel (grp); |
|
|
373 | } |
|
|
374 | |
|
|
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 | |
89 | static void |
381 | static void |
90 | poll_wait () |
382 | create_respipe (void) |
91 | { |
383 | { |
92 | if (nreqs && !ress) |
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)) |
|
|
393 | #endif |
|
|
394 | croak ("unable to initialize result pipe"); |
|
|
395 | |
|
|
396 | if (old_readfd >= 0) |
93 | { |
397 | { |
94 | fd_set rfd; |
398 | if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0) |
95 | FD_ZERO(&rfd); |
399 | croak ("unable to initialize result pipe(2)"); |
96 | FD_SET(respipe [0], &rfd); |
|
|
97 | |
400 | |
98 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
401 | respipe_close (respipe [0]); |
|
|
402 | respipe [0] = old_readfd; |
99 | } |
403 | } |
100 | } |
|
|
101 | |
404 | |
102 | static int |
405 | #ifdef _WIN32 |
103 | poll_cb () |
406 | int arg = 1; |
104 | { |
407 | if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg) |
105 | dSP; |
408 | || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg)) |
106 | int count = 0; |
409 | #else |
107 | int do_croak = 0; |
410 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK) |
108 | aio_req req; |
411 | || fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
|
|
412 | #endif |
|
|
413 | croak ("unable to initialize result pipe(3)"); |
109 | |
414 | |
|
|
415 | respipe_osf [0] = TO_SOCKET (respipe [0]); |
|
|
416 | respipe_osf [1] = TO_SOCKET (respipe [1]); |
|
|
417 | } |
|
|
418 | |
|
|
419 | static void poll_wait (void) |
|
|
420 | { |
|
|
421 | fd_set rfd; |
|
|
422 | |
|
|
423 | while (eio_nreqs ()) |
|
|
424 | { |
|
|
425 | int size; |
|
|
426 | |
|
|
427 | X_LOCK (reslock); |
|
|
428 | size = res_queue.size; |
|
|
429 | X_UNLOCK (reslock); |
|
|
430 | |
|
|
431 | if (size) |
|
|
432 | return; |
|
|
433 | |
|
|
434 | etp_maybe_start_thread (); |
|
|
435 | |
|
|
436 | FD_ZERO (&rfd); |
|
|
437 | FD_SET (respipe [0], &rfd); |
|
|
438 | |
|
|
439 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
|
|
440 | } |
|
|
441 | } |
|
|
442 | |
|
|
443 | static int poll_cb (void) |
|
|
444 | { |
110 | for (;;) |
445 | for (;;) |
111 | { |
446 | { |
112 | pthread_mutex_lock (&reslock); |
447 | int res = eio_poll (); |
113 | req = ress; |
|
|
114 | |
448 | |
115 | if (req) |
449 | if (res > 0) |
116 | { |
|
|
117 | ress = req->next; |
|
|
118 | |
|
|
119 | if (!ress) |
|
|
120 | { |
|
|
121 | rese = 0; |
|
|
122 | |
|
|
123 | /* read any signals sent by the worker threads */ |
|
|
124 | char buf [32]; |
|
|
125 | while (read (respipe [0], buf, 32) == 32) |
|
|
126 | ; |
|
|
127 | } |
|
|
128 | } |
|
|
129 | |
|
|
130 | pthread_mutex_unlock (&reslock); |
|
|
131 | |
|
|
132 | if (!req) |
|
|
133 | break; |
|
|
134 | |
|
|
135 | nreqs--; |
|
|
136 | |
|
|
137 | if (req->type == REQ_QUIT) |
|
|
138 | started--; |
|
|
139 | else |
|
|
140 | { |
|
|
141 | int errorno = errno; |
|
|
142 | errno = req->errorno; |
|
|
143 | |
|
|
144 | if (req->type == REQ_READ) |
|
|
145 | SvCUR_set (req->data, req->dataoffset + (req->result > 0 ? req->result : 0)); |
|
|
146 | |
|
|
147 | if (req->data2ptr && (req->type == REQ_READ || req->type == REQ_WRITE)) |
|
|
148 | SvREADONLY_off (req->data); |
|
|
149 | |
|
|
150 | if (req->statdata) |
|
|
151 | { |
|
|
152 | PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT; |
|
|
153 | PL_laststatval = req->result; |
|
|
154 | PL_statcache = *(req->statdata); |
|
|
155 | } |
|
|
156 | |
|
|
157 | ENTER; |
|
|
158 | PUSHMARK (SP); |
|
|
159 | XPUSHs (sv_2mortal (newSViv (req->result))); |
|
|
160 | |
|
|
161 | if (req->type == REQ_OPEN) |
|
|
162 | { |
|
|
163 | /* convert fd to fh */ |
|
|
164 | SV *fh; |
|
|
165 | |
|
|
166 | PUTBACK; |
|
|
167 | call_pv ("IO::AIO::_fd2fh", G_SCALAR | G_EVAL); |
|
|
168 | SPAGAIN; |
|
|
169 | |
|
|
170 | fh = SvREFCNT_inc (POPs); |
|
|
171 | |
|
|
172 | PUSHMARK (SP); |
|
|
173 | XPUSHs (sv_2mortal (fh)); |
|
|
174 | } |
|
|
175 | |
|
|
176 | if (SvOK (req->callback)) |
|
|
177 | { |
|
|
178 | PUTBACK; |
|
|
179 | call_sv (req->callback, G_VOID | G_EVAL); |
|
|
180 | SPAGAIN; |
|
|
181 | |
|
|
182 | if (SvTRUE (ERRSV)) |
|
|
183 | { |
|
|
184 | free_req (req); |
|
|
185 | croak (0); |
450 | croak (0); |
186 | } |
|
|
187 | } |
|
|
188 | |
451 | |
189 | LEAVE; |
452 | if (!max_outstanding || max_outstanding > eio_nreqs ()) |
|
|
453 | return res; |
190 | |
454 | |
191 | errno = errorno; |
455 | poll_wait (); |
192 | count++; |
|
|
193 | } |
|
|
194 | |
|
|
195 | free_req (req); |
|
|
196 | } |
456 | } |
197 | |
|
|
198 | return count; |
|
|
199 | } |
|
|
200 | |
|
|
201 | static void *aio_proc(void *arg); |
|
|
202 | |
|
|
203 | static void |
|
|
204 | start_thread (void) |
|
|
205 | { |
|
|
206 | sigset_t fullsigset, oldsigset; |
|
|
207 | pthread_t tid; |
|
|
208 | pthread_attr_t attr; |
|
|
209 | |
|
|
210 | pthread_attr_init (&attr); |
|
|
211 | pthread_attr_setstacksize (&attr, STACKSIZE); |
|
|
212 | pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); |
|
|
213 | |
|
|
214 | sigfillset (&fullsigset); |
|
|
215 | sigprocmask (SIG_SETMASK, &fullsigset, &oldsigset); |
|
|
216 | |
|
|
217 | if (pthread_create (&tid, &attr, aio_proc, 0) == 0) |
|
|
218 | started++; |
|
|
219 | |
|
|
220 | sigprocmask (SIG_SETMASK, &oldsigset, 0); |
|
|
221 | } |
|
|
222 | |
|
|
223 | static void |
|
|
224 | send_req (aio_req req) |
|
|
225 | { |
|
|
226 | nreqs++; |
|
|
227 | |
|
|
228 | pthread_mutex_lock (&reqlock); |
|
|
229 | |
|
|
230 | req->next = 0; |
|
|
231 | |
|
|
232 | if (reqe) |
|
|
233 | { |
|
|
234 | reqe->next = req; |
|
|
235 | reqe = req; |
|
|
236 | } |
|
|
237 | else |
|
|
238 | reqe = reqs = req; |
|
|
239 | |
|
|
240 | pthread_cond_signal (&reqwait); |
|
|
241 | pthread_mutex_unlock (&reqlock); |
|
|
242 | |
|
|
243 | if (nreqs > max_outstanding) |
|
|
244 | for (;;) |
|
|
245 | { |
|
|
246 | poll_cb (); |
|
|
247 | |
|
|
248 | if (nreqs <= max_outstanding) |
|
|
249 | break; |
|
|
250 | |
|
|
251 | poll_wait (); |
|
|
252 | } |
|
|
253 | } |
|
|
254 | |
|
|
255 | static void |
|
|
256 | end_thread (void) |
|
|
257 | { |
|
|
258 | aio_req req; |
|
|
259 | Newz (0, req, 1, aio_cb); |
|
|
260 | req->type = REQ_QUIT; |
|
|
261 | |
|
|
262 | send_req (req); |
|
|
263 | } |
|
|
264 | |
|
|
265 | static void min_parallel (int nthreads) |
|
|
266 | { |
|
|
267 | while (nthreads > started) |
|
|
268 | start_thread (); |
|
|
269 | } |
|
|
270 | |
|
|
271 | static void max_parallel (int nthreads) |
|
|
272 | { |
|
|
273 | int cur = started; |
|
|
274 | |
|
|
275 | while (cur > nthreads) |
|
|
276 | { |
|
|
277 | end_thread (); |
|
|
278 | cur--; |
|
|
279 | } |
|
|
280 | |
|
|
281 | while (started > nthreads) |
|
|
282 | { |
|
|
283 | poll_wait (); |
|
|
284 | poll_cb (); |
|
|
285 | } |
|
|
286 | } |
|
|
287 | |
|
|
288 | static void create_pipe () |
|
|
289 | { |
|
|
290 | if (pipe (respipe)) |
|
|
291 | croak ("unable to initialize result pipe"); |
|
|
292 | |
|
|
293 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK)) |
|
|
294 | croak ("cannot set result pipe to nonblocking mode"); |
|
|
295 | |
|
|
296 | if (fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
|
|
297 | croak ("cannot set result pipe to nonblocking mode"); |
|
|
298 | } |
|
|
299 | |
|
|
300 | static void atfork_prepare (void) |
|
|
301 | { |
|
|
302 | pthread_mutex_lock (&reqlock); |
|
|
303 | pthread_mutex_lock (&reslock); |
|
|
304 | } |
|
|
305 | |
|
|
306 | static void atfork_parent (void) |
|
|
307 | { |
|
|
308 | pthread_mutex_unlock (&reslock); |
|
|
309 | pthread_mutex_unlock (&reqlock); |
|
|
310 | } |
457 | } |
311 | |
458 | |
312 | static void atfork_child (void) |
459 | static void atfork_child (void) |
313 | { |
460 | { |
314 | aio_req prv; |
461 | create_respipe (); |
315 | |
|
|
316 | int restart = started; |
|
|
317 | started = 0; |
|
|
318 | |
|
|
319 | while (reqs) |
|
|
320 | { |
|
|
321 | prv = reqs; |
|
|
322 | reqs = prv->next; |
|
|
323 | free_req (prv); |
|
|
324 | } |
|
|
325 | |
|
|
326 | reqs = reqe = 0; |
|
|
327 | |
|
|
328 | while (ress) |
|
|
329 | { |
|
|
330 | prv = ress; |
|
|
331 | ress = prv->next; |
|
|
332 | free_req (prv); |
|
|
333 | } |
|
|
334 | |
|
|
335 | ress = rese = 0; |
|
|
336 | |
|
|
337 | atfork_parent (); |
|
|
338 | |
|
|
339 | min_parallel (restart); |
|
|
340 | } |
462 | } |
341 | |
463 | |
342 | /*****************************************************************************/ |
|
|
343 | /* work around various missing functions */ |
|
|
344 | |
|
|
345 | #if !HAVE_PREADWRITE |
|
|
346 | # define pread aio_pread |
|
|
347 | # define pwrite aio_pwrite |
|
|
348 | |
|
|
349 | /* |
|
|
350 | * make our pread/pwrite safe against themselves, but not against |
|
|
351 | * normal read/write by using a mutex. slows down execution a lot, |
|
|
352 | * but that's your problem, not mine. |
|
|
353 | */ |
|
|
354 | static pthread_mutex_t iolock = PTHREAD_MUTEX_INITIALIZER; |
|
|
355 | |
|
|
356 | static ssize_t |
|
|
357 | pread (int fd, void *buf, size_t count, off_t offset) |
|
|
358 | { |
|
|
359 | ssize_t res; |
|
|
360 | off_t ooffset; |
|
|
361 | |
|
|
362 | pthread_mutex_lock (&iolock); |
|
|
363 | ooffset = lseek (fd, 0, SEEK_CUR); |
|
|
364 | lseek (fd, offset, SEEK_SET); |
|
|
365 | res = read (fd, buf, count); |
|
|
366 | lseek (fd, ooffset, SEEK_SET); |
|
|
367 | pthread_mutex_unlock (&iolock); |
|
|
368 | |
|
|
369 | return res; |
|
|
370 | } |
|
|
371 | |
|
|
372 | static ssize_t |
|
|
373 | pwrite (int fd, void *buf, size_t count, off_t offset) |
|
|
374 | { |
|
|
375 | ssize_t res; |
|
|
376 | off_t ooffset; |
|
|
377 | |
|
|
378 | pthread_mutex_lock (&iolock); |
|
|
379 | ooffset = lseek (fd, 0, SEEK_CUR); |
|
|
380 | lseek (fd, offset, SEEK_SET); |
|
|
381 | res = write (fd, buf, count); |
|
|
382 | lseek (fd, offset, SEEK_SET); |
|
|
383 | pthread_mutex_unlock (&iolock); |
|
|
384 | |
|
|
385 | return res; |
|
|
386 | } |
|
|
387 | #endif |
|
|
388 | |
|
|
389 | #if !HAVE_FDATASYNC |
|
|
390 | # define fdatasync fsync |
|
|
391 | #endif |
|
|
392 | |
|
|
393 | #if !HAVE_READAHEAD |
|
|
394 | # define readahead aio_readahead |
|
|
395 | |
|
|
396 | static char readahead_buf[4096]; |
|
|
397 | |
|
|
398 | static ssize_t |
|
|
399 | readahead (int fd, off_t offset, size_t count) |
|
|
400 | { |
|
|
401 | while (count > 0) |
|
|
402 | { |
|
|
403 | size_t len = count < sizeof (readahead_buf) ? count : sizeof (readahead_buf); |
|
|
404 | |
|
|
405 | pread (fd, readahead_buf, len, offset); |
|
|
406 | offset += len; |
|
|
407 | count -= len; |
|
|
408 | } |
|
|
409 | |
|
|
410 | errno = 0; |
|
|
411 | } |
|
|
412 | #endif |
|
|
413 | |
|
|
414 | /*****************************************************************************/ |
|
|
415 | |
|
|
416 | static void * |
464 | static SV * |
417 | aio_proc (void *thr_arg) |
465 | get_cb (SV *cb_sv) |
418 | { |
466 | { |
419 | aio_req req; |
467 | HV *st; |
420 | int type; |
468 | GV *gvp; |
|
|
469 | CV *cv; |
421 | |
470 | |
422 | do |
471 | if (!SvOK (cb_sv)) |
423 | { |
|
|
424 | pthread_mutex_lock (&reqlock); |
|
|
425 | |
|
|
426 | for (;;) |
|
|
427 | { |
|
|
428 | req = reqs; |
|
|
429 | |
|
|
430 | if (reqs) |
|
|
431 | { |
|
|
432 | reqs = reqs->next; |
|
|
433 | if (!reqs) reqe = 0; |
|
|
434 | } |
|
|
435 | |
|
|
436 | if (req) |
|
|
437 | break; |
|
|
438 | |
|
|
439 | pthread_cond_wait (&reqwait, &reqlock); |
|
|
440 | } |
|
|
441 | |
|
|
442 | pthread_mutex_unlock (&reqlock); |
|
|
443 | |
|
|
444 | errno = 0; /* strictly unnecessary */ |
|
|
445 | |
|
|
446 | type = req->type; |
|
|
447 | |
|
|
448 | switch (type) |
|
|
449 | { |
|
|
450 | case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; |
|
|
451 | case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; |
|
|
452 | |
|
|
453 | case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; |
|
|
454 | |
|
|
455 | case REQ_STAT: req->result = stat (req->dataptr, req->statdata); break; |
|
|
456 | case REQ_LSTAT: req->result = lstat (req->dataptr, req->statdata); break; |
|
|
457 | case REQ_FSTAT: req->result = fstat (req->fd , req->statdata); break; |
|
|
458 | |
|
|
459 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |
|
|
460 | case REQ_CLOSE: req->result = close (req->fd); break; |
|
|
461 | case REQ_UNLINK: req->result = unlink (req->dataptr); break; |
|
|
462 | case REQ_RMDIR: req->result = rmdir (req->dataptr); break; |
|
|
463 | case REQ_SYMLINK: req->result = symlink (req->data2ptr, req->dataptr); break; |
|
|
464 | |
|
|
465 | case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; |
|
|
466 | case REQ_FSYNC: req->result = fsync (req->fd); break; |
|
|
467 | |
|
|
468 | case REQ_QUIT: |
|
|
469 | break; |
|
|
470 | |
|
|
471 | default: |
|
|
472 | req->result = ENOSYS; |
|
|
473 | break; |
|
|
474 | } |
|
|
475 | |
|
|
476 | req->errorno = errno; |
|
|
477 | |
|
|
478 | pthread_mutex_lock (&reslock); |
|
|
479 | |
|
|
480 | req->next = 0; |
|
|
481 | |
|
|
482 | if (rese) |
|
|
483 | { |
|
|
484 | rese->next = req; |
|
|
485 | rese = req; |
|
|
486 | } |
|
|
487 | else |
|
|
488 | { |
|
|
489 | rese = ress = req; |
|
|
490 | |
|
|
491 | /* write a dummy byte to the pipe so fh becomes ready */ |
|
|
492 | write (respipe [1], &respipe, 1); |
|
|
493 | } |
|
|
494 | |
|
|
495 | pthread_mutex_unlock (&reslock); |
|
|
496 | } |
|
|
497 | while (type != REQ_QUIT); |
|
|
498 | |
|
|
499 | return 0; |
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; |
500 | } |
480 | } |
501 | |
481 | |
502 | #define dREQ \ |
482 | #define dREQ \ |
|
|
483 | SV *cb_cv; \ |
503 | aio_req req; \ |
484 | aio_req req; \ |
|
|
485 | int req_pri = next_pri; \ |
|
|
486 | next_pri = EIO_PRI_DEFAULT; \ |
504 | \ |
487 | \ |
505 | if (SvOK (callback) && !SvROK (callback)) \ |
488 | cb_cv = get_cb (callback); \ |
506 | croak ("clalback must be undef or of reference type"); \ |
|
|
507 | \ |
489 | \ |
508 | Newz (0, req, 1, aio_cb); \ |
490 | Newz (0, req, 1, eio_req); \ |
509 | if (!req) \ |
491 | if (!req) \ |
510 | croak ("out of memory during aio_req allocation"); \ |
492 | croak ("out of memory during eio_req allocation"); \ |
511 | \ |
493 | \ |
512 | req->callback = newSVsv (callback); |
494 | req->callback = SvREFCNT_inc (cb_cv); \ |
|
|
495 | req->pri = req_pri |
|
|
496 | |
|
|
497 | #define REQ_SEND \ |
|
|
498 | PUTBACK; \ |
|
|
499 | req_submit (req); \ |
|
|
500 | SPAGAIN; \ |
|
|
501 | \ |
|
|
502 | if (GIMME_V != G_VOID) \ |
|
|
503 | XPUSHs (req_sv (req, AIO_REQ_KLASS)); |
513 | |
504 | |
514 | MODULE = IO::AIO PACKAGE = IO::AIO |
505 | MODULE = IO::AIO PACKAGE = IO::AIO |
515 | |
506 | |
516 | PROTOTYPES: ENABLE |
507 | PROTOTYPES: ENABLE |
517 | |
508 | |
518 | BOOT: |
509 | BOOT: |
519 | { |
510 | { |
520 | create_pipe (); |
511 | stash = gv_stashpv ("IO::AIO", 1); |
521 | pthread_atfork (atfork_prepare, atfork_parent, atfork_child); |
|
|
522 | } |
|
|
523 | |
512 | |
|
|
513 | newCONSTSUB (stash, "EXDEV", newSViv (EXDEV)); |
|
|
514 | newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY)); |
|
|
515 | newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY)); |
|
|
516 | newCONSTSUB (stash, "O_CREAT", newSViv (O_CREAT)); |
|
|
517 | newCONSTSUB (stash, "O_TRUNC", newSViv (O_TRUNC)); |
|
|
518 | #ifndef _WIN32 |
|
|
519 | newCONSTSUB (stash, "S_IFIFO", newSViv (S_IFIFO)); |
|
|
520 | #endif |
|
|
521 | newCONSTSUB (stash, "S_IFIFO", newSViv (S_IFIFO)); |
|
|
522 | newCONSTSUB (stash, "SYNC_FILE_RANGE_WAIT_BEFORE", newSViv (EIO_SYNC_FILE_RANGE_WAIT_BEFORE)); |
|
|
523 | newCONSTSUB (stash, "SYNC_FILE_RANGE_WRITE" , newSViv (EIO_SYNC_FILE_RANGE_WRITE)); |
|
|
524 | newCONSTSUB (stash, "SYNC_FILE_RANGE_WAIT_AFTER" , newSViv (EIO_SYNC_FILE_RANGE_WAIT_AFTER)); |
|
|
525 | |
|
|
526 | create_respipe (); |
|
|
527 | |
|
|
528 | if (eio_init (want_poll, done_poll) < 0) |
|
|
529 | croak ("IO::AIO: unable to initialise eio library"); |
|
|
530 | |
|
|
531 | /* atfork child called in fifo order, so before eio's handler */ |
|
|
532 | X_THREAD_ATFORK (0, 0, atfork_child); |
|
|
533 | } |
|
|
534 | |
524 | void |
535 | void |
525 | min_parallel(nthreads) |
536 | max_poll_reqs (int nreqs) |
526 | int nthreads |
|
|
527 | PROTOTYPE: $ |
537 | PROTOTYPE: $ |
|
|
538 | CODE: |
|
|
539 | eio_set_max_poll_reqs (nreqs); |
528 | |
540 | |
529 | void |
541 | void |
530 | max_parallel(nthreads) |
542 | max_poll_time (double nseconds) |
531 | int nthreads |
|
|
532 | PROTOTYPE: $ |
543 | PROTOTYPE: $ |
533 | |
|
|
534 | int |
|
|
535 | max_outstanding(nreqs) |
|
|
536 | int nreqs |
|
|
537 | PROTOTYPE: $ |
|
|
538 | CODE: |
544 | CODE: |
539 | RETVAL = max_outstanding; |
545 | eio_set_max_poll_time (nseconds); |
|
|
546 | |
|
|
547 | void |
|
|
548 | min_parallel (int nthreads) |
|
|
549 | PROTOTYPE: $ |
|
|
550 | CODE: |
|
|
551 | eio_set_min_parallel (nthreads); |
|
|
552 | |
|
|
553 | void |
|
|
554 | max_parallel (int nthreads) |
|
|
555 | PROTOTYPE: $ |
|
|
556 | CODE: |
|
|
557 | eio_set_max_parallel (nthreads); |
|
|
558 | |
|
|
559 | void |
|
|
560 | max_idle (int nthreads) |
|
|
561 | PROTOTYPE: $ |
|
|
562 | CODE: |
|
|
563 | eio_set_max_idle (nthreads); |
|
|
564 | |
|
|
565 | void |
|
|
566 | max_outstanding (int maxreqs) |
|
|
567 | PROTOTYPE: $ |
|
|
568 | CODE: |
540 | max_outstanding = nreqs; |
569 | max_outstanding = maxreqs; |
541 | |
570 | |
542 | void |
571 | void |
543 | aio_open(pathname,flags,mode,callback=&PL_sv_undef) |
572 | aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef) |
544 | SV * pathname |
|
|
545 | int flags |
|
|
546 | int mode |
|
|
547 | SV * callback |
|
|
548 | PROTOTYPE: $$$;$ |
573 | PROTOTYPE: $$$;$ |
549 | CODE: |
574 | PPCODE: |
550 | { |
575 | { |
551 | dREQ; |
576 | dREQ; |
552 | |
577 | |
553 | req->type = REQ_OPEN; |
578 | req->type = EIO_OPEN; |
554 | req->data = newSVsv (pathname); |
579 | req->sv1 = newSVsv (pathname); |
555 | req->dataptr = SvPVbyte_nolen (req->data); |
580 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
556 | req->fd = flags; |
581 | req->int1 = flags; |
557 | req->mode = mode; |
582 | req->int2 = mode; |
558 | |
583 | |
559 | send_req (req); |
584 | REQ_SEND; |
560 | } |
585 | } |
561 | |
586 | |
562 | void |
587 | void |
563 | aio_close(fh,callback=&PL_sv_undef) |
588 | aio_fsync (SV *fh, SV *callback=&PL_sv_undef) |
564 | SV * fh |
|
|
565 | SV * callback |
|
|
566 | PROTOTYPE: $;$ |
589 | PROTOTYPE: $;$ |
567 | ALIAS: |
590 | ALIAS: |
568 | aio_close = REQ_CLOSE |
|
|
569 | aio_fsync = REQ_FSYNC |
591 | aio_fsync = EIO_FSYNC |
570 | aio_fdatasync = REQ_FDATASYNC |
592 | aio_fdatasync = EIO_FDATASYNC |
571 | CODE: |
593 | PPCODE: |
572 | { |
594 | { |
573 | dREQ; |
595 | dREQ; |
574 | |
596 | |
575 | req->type = ix; |
597 | req->type = ix; |
576 | req->fh = newSVsv (fh); |
598 | req->sv1 = newSVsv (fh); |
577 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); |
599 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh))); |
578 | |
600 | |
579 | send_req (req); |
601 | REQ_SEND (req); |
580 | } |
602 | } |
581 | |
603 | |
582 | void |
604 | void |
|
|
605 | aio_sync_file_range (SV *fh, SV *offset, SV *nbytes, IV flags, SV *callback=&PL_sv_undef) |
|
|
606 | PROTOTYPE: $$$$;$ |
|
|
607 | PPCODE: |
|
|
608 | { |
|
|
609 | dREQ; |
|
|
610 | |
|
|
611 | req->type = EIO_SYNC_FILE_RANGE; |
|
|
612 | req->sv1 = newSVsv (fh); |
|
|
613 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh))); |
|
|
614 | req->offs = SvVAL64 (offset); |
|
|
615 | req->size = SvVAL64 (nbytes); |
|
|
616 | req->int2 = flags; |
|
|
617 | |
|
|
618 | REQ_SEND (req); |
|
|
619 | } |
|
|
620 | |
|
|
621 | void |
|
|
622 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
|
|
623 | PROTOTYPE: $;$ |
|
|
624 | PPCODE: |
|
|
625 | { |
|
|
626 | static int close_pipe = -1; /* dummy fd to close fds via dup2 */ |
|
|
627 | dREQ; |
|
|
628 | |
|
|
629 | if (close_pipe < 0) |
|
|
630 | { |
|
|
631 | int pipefd [2]; |
|
|
632 | |
|
|
633 | if (pipe (pipefd) < 0 |
|
|
634 | || close (pipefd [1]) < 0 |
|
|
635 | || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0) |
|
|
636 | abort (); /*D*/ |
|
|
637 | |
|
|
638 | close_pipe = pipefd [0]; |
|
|
639 | } |
|
|
640 | |
|
|
641 | req->type = EIO_DUP2; |
|
|
642 | req->int1 = close_pipe; |
|
|
643 | req->sv2 = newSVsv (fh); |
|
|
644 | req->int2 = PerlIO_fileno (IoIFP (sv_2io (fh))); |
|
|
645 | |
|
|
646 | REQ_SEND (req); |
|
|
647 | } |
|
|
648 | |
|
|
649 | void |
583 | aio_read(fh,offset,length,data,dataoffset,callback=&PL_sv_undef) |
650 | aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) |
584 | SV * fh |
|
|
585 | UV offset |
|
|
586 | IV length |
|
|
587 | SV * data |
|
|
588 | IV dataoffset |
|
|
589 | SV * callback |
|
|
590 | ALIAS: |
651 | ALIAS: |
591 | aio_read = REQ_READ |
652 | aio_read = EIO_READ |
592 | aio_write = REQ_WRITE |
653 | aio_write = EIO_WRITE |
593 | PROTOTYPE: $$$$$;$ |
654 | PROTOTYPE: $$$$$;$ |
594 | CODE: |
655 | PPCODE: |
595 | { |
656 | { |
596 | aio_req req; |
|
|
597 | STRLEN svlen; |
657 | STRLEN svlen; |
598 | char *svptr = SvPVbyte (data, svlen); |
658 | char *svptr = SvPVbyte (data, svlen); |
|
|
659 | UV len = SvUV (length); |
599 | |
660 | |
600 | SvUPGRADE (data, SVt_PV); |
661 | SvUPGRADE (data, SVt_PV); |
601 | SvPOK_on (data); |
662 | SvPOK_on (data); |
602 | |
663 | |
603 | if (dataoffset < 0) |
664 | if (dataoffset < 0) |
604 | dataoffset += svlen; |
665 | dataoffset += svlen; |
605 | |
666 | |
606 | if (dataoffset < 0 || dataoffset > svlen) |
667 | if (dataoffset < 0 || dataoffset > svlen) |
607 | croak ("data offset outside of string"); |
668 | croak ("dataoffset outside of data scalar"); |
608 | |
669 | |
609 | if (ix == REQ_WRITE) |
670 | if (ix == EIO_WRITE) |
610 | { |
671 | { |
611 | /* write: check length and adjust. */ |
672 | /* write: check length and adjust. */ |
612 | if (length < 0 || length + dataoffset > svlen) |
673 | if (!SvOK (length) || len + dataoffset > svlen) |
613 | length = svlen - dataoffset; |
674 | len = svlen - dataoffset; |
614 | } |
675 | } |
615 | else |
676 | else |
616 | { |
677 | { |
617 | /* read: grow scalar as necessary */ |
678 | /* read: grow scalar as necessary */ |
618 | svptr = SvGROW (data, length + dataoffset); |
679 | svptr = SvGROW (data, len + dataoffset + 1); |
619 | } |
680 | } |
620 | |
681 | |
621 | if (length < 0) |
682 | if (len < 0) |
622 | croak ("length must not be negative"); |
683 | croak ("length must not be negative"); |
623 | |
684 | |
624 | { |
685 | { |
625 | dREQ; |
686 | dREQ; |
626 | |
687 | |
627 | req->type = ix; |
688 | req->type = ix; |
628 | req->fh = newSVsv (fh); |
689 | req->sv1 = newSVsv (fh); |
629 | req->fd = PerlIO_fileno (ix == REQ_READ ? IoIFP (sv_2io (fh)) |
690 | req->int1 = PerlIO_fileno (ix == EIO_READ ? IoIFP (sv_2io (fh)) |
630 | : IoOFP (sv_2io (fh))); |
691 | : IoOFP (sv_2io (fh))); |
|
|
692 | req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
631 | req->offset = offset; |
693 | req->size = len; |
632 | req->length = length; |
|
|
633 | req->data = SvREFCNT_inc (data); |
694 | req->sv2 = SvREFCNT_inc (data); |
634 | req->dataptr = (char *)svptr + dataoffset; |
695 | req->ptr2 = (char *)svptr + dataoffset; |
|
|
696 | req->stroffset = dataoffset; |
635 | |
697 | |
636 | if (!SvREADONLY (data)) |
698 | if (!SvREADONLY (data)) |
637 | { |
699 | { |
638 | SvREADONLY_on (data); |
700 | SvREADONLY_on (data); |
639 | req->data2ptr = (void *)data; |
701 | req->flags |= FLAG_SV2_RO_OFF; |
640 | } |
702 | } |
641 | |
703 | |
642 | send_req (req); |
704 | REQ_SEND; |
643 | } |
705 | } |
644 | } |
706 | } |
645 | |
707 | |
646 | void |
708 | void |
|
|
709 | aio_readlink (SV8 *path, SV *callback=&PL_sv_undef) |
|
|
710 | PROTOTYPE: $$;$ |
|
|
711 | PPCODE: |
|
|
712 | { |
|
|
713 | SV *data; |
|
|
714 | dREQ; |
|
|
715 | |
|
|
716 | req->type = EIO_READLINK; |
|
|
717 | req->sv1 = newSVsv (path); |
|
|
718 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
719 | |
|
|
720 | REQ_SEND; |
|
|
721 | } |
|
|
722 | |
|
|
723 | void |
|
|
724 | aio_sendfile (SV *out_fh, SV *in_fh, SV *in_offset, UV length, SV *callback=&PL_sv_undef) |
|
|
725 | PROTOTYPE: $$$$;$ |
|
|
726 | PPCODE: |
|
|
727 | { |
|
|
728 | dREQ; |
|
|
729 | |
|
|
730 | req->type = EIO_SENDFILE; |
|
|
731 | req->sv1 = newSVsv (out_fh); |
|
|
732 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (out_fh))); |
|
|
733 | req->sv2 = newSVsv (in_fh); |
|
|
734 | req->int2 = PerlIO_fileno (IoIFP (sv_2io (in_fh))); |
|
|
735 | req->offs = SvVAL64 (in_offset); |
|
|
736 | req->size = length; |
|
|
737 | |
|
|
738 | REQ_SEND; |
|
|
739 | } |
|
|
740 | |
|
|
741 | void |
647 | aio_readahead(fh,offset,length,callback=&PL_sv_undef) |
742 | aio_readahead (SV *fh, SV *offset, IV length, SV *callback=&PL_sv_undef) |
648 | SV * fh |
|
|
649 | UV offset |
|
|
650 | IV length |
|
|
651 | SV * callback |
|
|
652 | PROTOTYPE: $$$;$ |
743 | PROTOTYPE: $$$;$ |
653 | CODE: |
744 | PPCODE: |
654 | { |
745 | { |
655 | dREQ; |
746 | dREQ; |
656 | |
747 | |
657 | req->type = REQ_READAHEAD; |
748 | req->type = EIO_READAHEAD; |
658 | req->fh = newSVsv (fh); |
749 | req->sv1 = newSVsv (fh); |
659 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); |
750 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh))); |
660 | req->offset = offset; |
751 | req->offs = SvVAL64 (offset); |
661 | req->length = length; |
752 | req->size = length; |
662 | |
753 | |
663 | send_req (req); |
754 | REQ_SEND; |
664 | } |
755 | } |
665 | |
756 | |
666 | void |
757 | void |
667 | aio_stat(fh_or_path,callback=&PL_sv_undef) |
758 | aio_stat (SV8 *fh_or_path, SV *callback=&PL_sv_undef) |
668 | SV * fh_or_path |
|
|
669 | SV * callback |
|
|
670 | ALIAS: |
759 | ALIAS: |
671 | aio_stat = REQ_STAT |
760 | aio_stat = EIO_STAT |
672 | aio_lstat = REQ_LSTAT |
761 | aio_lstat = EIO_LSTAT |
673 | CODE: |
762 | PPCODE: |
674 | { |
763 | { |
675 | dREQ; |
764 | dREQ; |
676 | |
765 | |
677 | New (0, req->statdata, 1, Stat_t); |
766 | req->sv1 = newSVsv (fh_or_path); |
678 | if (!req->statdata) |
|
|
679 | { |
|
|
680 | free_req (req); |
|
|
681 | croak ("out of memory during aio_req->statdata allocation"); |
|
|
682 | } |
|
|
683 | |
767 | |
684 | if (SvPOK (fh_or_path)) |
768 | if (SvPOK (req->sv1)) |
685 | { |
769 | { |
686 | req->type = ix; |
770 | req->type = ix; |
687 | req->data = newSVsv (fh_or_path); |
|
|
688 | req->dataptr = SvPVbyte_nolen (req->data); |
771 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
689 | } |
772 | } |
690 | else |
773 | else |
691 | { |
774 | { |
692 | req->type = REQ_FSTAT; |
775 | req->type = EIO_FSTAT; |
693 | req->fh = newSVsv (fh_or_path); |
|
|
694 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
776 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
777 | } |
|
|
778 | |
|
|
779 | REQ_SEND; |
|
|
780 | } |
|
|
781 | |
|
|
782 | void |
|
|
783 | aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef) |
|
|
784 | PPCODE: |
|
|
785 | { |
|
|
786 | dREQ; |
|
|
787 | |
|
|
788 | req->nv1 = SvOK (atime) ? SvNV (atime) : -1.; |
|
|
789 | req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.; |
|
|
790 | req->sv1 = newSVsv (fh_or_path); |
|
|
791 | |
|
|
792 | if (SvPOK (req->sv1)) |
695 | } |
793 | { |
|
|
794 | req->type = EIO_UTIME; |
|
|
795 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
796 | } |
|
|
797 | else |
|
|
798 | { |
|
|
799 | req->type = EIO_FUTIME; |
|
|
800 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
801 | } |
696 | |
802 | |
697 | send_req (req); |
803 | REQ_SEND; |
698 | } |
804 | } |
699 | |
805 | |
700 | void |
806 | void |
|
|
807 | aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef) |
|
|
808 | PPCODE: |
|
|
809 | { |
|
|
810 | dREQ; |
|
|
811 | |
|
|
812 | req->sv1 = newSVsv (fh_or_path); |
|
|
813 | req->offs = SvOK (offset) ? SvVAL64 (offset) : -1; |
|
|
814 | |
|
|
815 | if (SvPOK (req->sv1)) |
|
|
816 | { |
|
|
817 | req->type = EIO_TRUNCATE; |
|
|
818 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
819 | } |
|
|
820 | else |
|
|
821 | { |
|
|
822 | req->type = EIO_FTRUNCATE; |
|
|
823 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
824 | } |
|
|
825 | |
|
|
826 | REQ_SEND; |
|
|
827 | } |
|
|
828 | |
|
|
829 | void |
|
|
830 | aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef) |
|
|
831 | ALIAS: |
|
|
832 | aio_chmod = EIO_CHMOD |
|
|
833 | aio_mkdir = EIO_MKDIR |
|
|
834 | PPCODE: |
|
|
835 | { |
|
|
836 | dREQ; |
|
|
837 | |
|
|
838 | req->int2 = mode; |
|
|
839 | req->sv1 = newSVsv (fh_or_path); |
|
|
840 | |
|
|
841 | if (SvPOK (req->sv1)) |
|
|
842 | { |
|
|
843 | req->type = ix; |
|
|
844 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
845 | } |
|
|
846 | else |
|
|
847 | { |
|
|
848 | req->type = EIO_FCHMOD; |
|
|
849 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
850 | } |
|
|
851 | |
|
|
852 | REQ_SEND; |
|
|
853 | } |
|
|
854 | |
|
|
855 | void |
|
|
856 | aio_chown (SV8 *fh_or_path, SV *uid, SV *gid, SV *callback=&PL_sv_undef) |
|
|
857 | PPCODE: |
|
|
858 | { |
|
|
859 | dREQ; |
|
|
860 | |
|
|
861 | req->int2 = SvOK (uid) ? SvIV (uid) : -1; |
|
|
862 | req->int3 = SvOK (gid) ? SvIV (gid) : -1; |
|
|
863 | req->sv1 = newSVsv (fh_or_path); |
|
|
864 | |
|
|
865 | if (SvPOK (req->sv1)) |
|
|
866 | { |
|
|
867 | req->type = EIO_CHOWN; |
|
|
868 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
869 | } |
|
|
870 | else |
|
|
871 | { |
|
|
872 | req->type = EIO_FCHOWN; |
|
|
873 | req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
874 | } |
|
|
875 | |
|
|
876 | REQ_SEND; |
|
|
877 | } |
|
|
878 | |
|
|
879 | void |
701 | aio_unlink(pathname,callback=&PL_sv_undef) |
880 | aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef) |
702 | SV * pathname |
|
|
703 | SV * callback |
|
|
704 | ALIAS: |
881 | ALIAS: |
705 | aio_unlink = REQ_UNLINK |
882 | aio_unlink = EIO_UNLINK |
706 | aio_rmdir = REQ_RMDIR |
883 | aio_rmdir = EIO_RMDIR |
|
|
884 | aio_readdir = EIO_READDIR |
707 | CODE: |
885 | PPCODE: |
708 | { |
886 | { |
709 | dREQ; |
887 | dREQ; |
710 | |
888 | |
711 | req->type = ix; |
889 | req->type = ix; |
712 | req->data = newSVsv (pathname); |
890 | req->sv1 = newSVsv (pathname); |
713 | req->dataptr = SvPVbyte_nolen (req->data); |
891 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
892 | |
|
|
893 | REQ_SEND; |
|
|
894 | } |
|
|
895 | |
|
|
896 | void |
|
|
897 | aio_link (SV8 *oldpath, SV8 *newpath, SV *callback=&PL_sv_undef) |
|
|
898 | ALIAS: |
|
|
899 | aio_link = EIO_LINK |
|
|
900 | aio_symlink = EIO_SYMLINK |
|
|
901 | aio_rename = EIO_RENAME |
|
|
902 | PPCODE: |
|
|
903 | { |
|
|
904 | dREQ; |
714 | |
905 | |
715 | send_req (req); |
906 | req->type = ix; |
716 | } |
907 | req->sv1 = newSVsv (oldpath); |
717 | |
908 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
718 | void |
909 | req->sv2 = newSVsv (newpath); |
719 | aio_symlink(oldpath,newpath,callback=&PL_sv_undef) |
910 | req->ptr2 = SvPVbyte_nolen (req->sv2); |
720 | SV * oldpath |
|
|
721 | SV * newpath |
|
|
722 | SV * callback |
|
|
723 | CODE: |
|
|
724 | { |
|
|
725 | dREQ; |
|
|
726 | |
911 | |
727 | req->type = REQ_SYMLINK; |
912 | REQ_SEND; |
728 | req->fh = newSVsv (oldpath); |
913 | } |
729 | req->data2ptr = SvPVbyte_nolen (req->fh); |
914 | |
730 | req->data = newSVsv (newpath); |
915 | void |
731 | req->dataptr = SvPVbyte_nolen (req->data); |
916 | aio_mknod (SV8 *pathname, int mode, UV dev, SV *callback=&PL_sv_undef) |
|
|
917 | PPCODE: |
|
|
918 | { |
|
|
919 | dREQ; |
732 | |
920 | |
733 | send_req (req); |
921 | req->type = EIO_MKNOD; |
|
|
922 | req->sv1 = newSVsv (pathname); |
|
|
923 | req->ptr1 = SvPVbyte_nolen (req->sv1); |
|
|
924 | req->int2 = (mode_t)mode; |
|
|
925 | req->offs = dev; |
|
|
926 | |
|
|
927 | REQ_SEND; |
734 | } |
928 | } |
735 | |
929 | |
736 | void |
930 | void |
|
|
931 | aio_busy (double delay, SV *callback=&PL_sv_undef) |
|
|
932 | PPCODE: |
|
|
933 | { |
|
|
934 | dREQ; |
|
|
935 | |
|
|
936 | req->type = EIO_BUSY; |
|
|
937 | req->nv1 = delay < 0. ? 0. : delay; |
|
|
938 | |
|
|
939 | REQ_SEND; |
|
|
940 | } |
|
|
941 | |
|
|
942 | void |
|
|
943 | aio_group (SV *callback=&PL_sv_undef) |
|
|
944 | PROTOTYPE: ;$ |
|
|
945 | PPCODE: |
|
|
946 | { |
|
|
947 | dREQ; |
|
|
948 | |
|
|
949 | req->type = EIO_GROUP; |
|
|
950 | |
|
|
951 | req_submit (req); |
|
|
952 | XPUSHs (req_sv (req, AIO_GRP_KLASS)); |
|
|
953 | } |
|
|
954 | |
|
|
955 | void |
|
|
956 | aio_nop (SV *callback=&PL_sv_undef) |
|
|
957 | ALIAS: |
|
|
958 | aio_nop = EIO_NOP |
|
|
959 | aio_sync = EIO_SYNC |
|
|
960 | PPCODE: |
|
|
961 | { |
|
|
962 | dREQ; |
|
|
963 | |
|
|
964 | req->type = ix; |
|
|
965 | |
|
|
966 | REQ_SEND; |
|
|
967 | } |
|
|
968 | |
|
|
969 | int |
|
|
970 | aioreq_pri (int pri = 0) |
|
|
971 | PROTOTYPE: ;$ |
|
|
972 | CODE: |
|
|
973 | RETVAL = next_pri; |
|
|
974 | if (items > 0) |
|
|
975 | { |
|
|
976 | if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN; |
|
|
977 | if (pri > EIO_PRI_MAX) pri = EIO_PRI_MAX; |
|
|
978 | next_pri = pri; |
|
|
979 | } |
|
|
980 | OUTPUT: |
|
|
981 | RETVAL |
|
|
982 | |
|
|
983 | void |
|
|
984 | aioreq_nice (int nice = 0) |
|
|
985 | CODE: |
|
|
986 | nice = next_pri - nice; |
|
|
987 | if (nice < EIO_PRI_MIN) nice = EIO_PRI_MIN; |
|
|
988 | if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX; |
|
|
989 | next_pri = nice; |
|
|
990 | |
|
|
991 | void |
737 | flush() |
992 | flush () |
738 | PROTOTYPE: |
993 | PROTOTYPE: |
739 | CODE: |
994 | CODE: |
740 | while (nreqs) |
995 | while (eio_nreqs ()) |
741 | { |
996 | { |
742 | poll_wait (); |
997 | poll_wait (); |
743 | poll_cb (); |
998 | poll_cb (); |
744 | } |
999 | } |
745 | |
1000 | |
746 | void |
1001 | int |
747 | poll() |
1002 | poll() |
748 | PROTOTYPE: |
1003 | PROTOTYPE: |
749 | CODE: |
1004 | CODE: |
750 | if (nreqs) |
|
|
751 | { |
|
|
752 | poll_wait (); |
1005 | poll_wait (); |
753 | poll_cb (); |
1006 | RETVAL = poll_cb (); |
754 | } |
1007 | OUTPUT: |
|
|
1008 | RETVAL |
755 | |
1009 | |
756 | int |
1010 | int |
757 | poll_fileno() |
1011 | poll_fileno() |
758 | PROTOTYPE: |
1012 | PROTOTYPE: |
759 | CODE: |
1013 | CODE: |
… | |
… | |
771 | |
1025 | |
772 | void |
1026 | void |
773 | poll_wait() |
1027 | poll_wait() |
774 | PROTOTYPE: |
1028 | PROTOTYPE: |
775 | CODE: |
1029 | CODE: |
776 | if (nreqs) |
|
|
777 | poll_wait (); |
1030 | poll_wait (); |
778 | |
1031 | |
779 | int |
1032 | int |
780 | nreqs() |
1033 | nreqs() |
781 | PROTOTYPE: |
1034 | PROTOTYPE: |
782 | CODE: |
1035 | CODE: |
783 | RETVAL = nreqs; |
1036 | RETVAL = eio_nreqs (); |
784 | OUTPUT: |
1037 | OUTPUT: |
785 | RETVAL |
1038 | RETVAL |
786 | |
1039 | |
|
|
1040 | int |
|
|
1041 | nready() |
|
|
1042 | PROTOTYPE: |
|
|
1043 | CODE: |
|
|
1044 | RETVAL = eio_nready (); |
|
|
1045 | OUTPUT: |
|
|
1046 | RETVAL |
|
|
1047 | |
|
|
1048 | int |
|
|
1049 | npending() |
|
|
1050 | PROTOTYPE: |
|
|
1051 | CODE: |
|
|
1052 | RETVAL = eio_npending (); |
|
|
1053 | OUTPUT: |
|
|
1054 | RETVAL |
|
|
1055 | |
|
|
1056 | int |
|
|
1057 | nthreads() |
|
|
1058 | PROTOTYPE: |
|
|
1059 | CODE: |
|
|
1060 | RETVAL = eio_nthreads (); |
|
|
1061 | OUTPUT: |
|
|
1062 | RETVAL |
|
|
1063 | |
|
|
1064 | void _on_next_submit (SV *cb) |
|
|
1065 | CODE: |
|
|
1066 | SvREFCNT_dec (on_next_submit); |
|
|
1067 | on_next_submit = SvOK (cb) ? newSVsv (cb) : 0; |
|
|
1068 | |
|
|
1069 | PROTOTYPES: DISABLE |
|
|
1070 | |
|
|
1071 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
|
|
1072 | |
|
|
1073 | void |
|
|
1074 | cancel (aio_req_ornot req) |
|
|
1075 | CODE: |
|
|
1076 | eio_cancel (req); |
|
|
1077 | |
|
|
1078 | void |
|
|
1079 | cb (aio_req_ornot req, SV *callback=&PL_sv_undef) |
|
|
1080 | PPCODE: |
|
|
1081 | { |
|
|
1082 | if (GIMME_V != G_VOID) |
|
|
1083 | XPUSHs (req->callback ? sv_2mortal (newRV_inc (req->callback)) : &PL_sv_undef); |
|
|
1084 | |
|
|
1085 | if (items > 1) |
|
|
1086 | { |
|
|
1087 | SV *cb_cv = get_cb (callback); |
|
|
1088 | |
|
|
1089 | SvREFCNT_dec (req->callback); |
|
|
1090 | req->callback = SvREFCNT_inc (cb_cv); |
|
|
1091 | } |
|
|
1092 | } |
|
|
1093 | |
|
|
1094 | MODULE = IO::AIO PACKAGE = IO::AIO::GRP |
|
|
1095 | |
|
|
1096 | void |
|
|
1097 | add (aio_req grp, ...) |
|
|
1098 | PPCODE: |
|
|
1099 | { |
|
|
1100 | int i; |
|
|
1101 | |
|
|
1102 | if (grp->int1 == 2) |
|
|
1103 | croak ("cannot add requests to IO::AIO::GRP after the group finished"); |
|
|
1104 | |
|
|
1105 | for (i = 1; i < items; ++i ) |
|
|
1106 | { |
|
|
1107 | aio_req req; |
|
|
1108 | |
|
|
1109 | if (GIMME_V != G_VOID) |
|
|
1110 | XPUSHs (sv_2mortal (newSVsv (ST (i)))); |
|
|
1111 | |
|
|
1112 | req = SvAIO_REQ (ST (i)); |
|
|
1113 | |
|
|
1114 | if (req) |
|
|
1115 | eio_grp_add (grp, req); |
|
|
1116 | } |
|
|
1117 | } |
|
|
1118 | |
|
|
1119 | void |
|
|
1120 | cancel_subs (aio_req_ornot req) |
|
|
1121 | CODE: |
|
|
1122 | req_cancel_subs (req); |
|
|
1123 | |
|
|
1124 | void |
|
|
1125 | result (aio_req grp, ...) |
|
|
1126 | CODE: |
|
|
1127 | { |
|
|
1128 | int i; |
|
|
1129 | AV *av; |
|
|
1130 | |
|
|
1131 | grp->errorno = errno; |
|
|
1132 | |
|
|
1133 | av = newAV (); |
|
|
1134 | |
|
|
1135 | for (i = 1; i < items; ++i ) |
|
|
1136 | av_push (av, newSVsv (ST (i))); |
|
|
1137 | |
|
|
1138 | SvREFCNT_dec (grp->sv1); |
|
|
1139 | grp->sv1 = (SV *)av; |
|
|
1140 | } |
|
|
1141 | |
|
|
1142 | void |
|
|
1143 | errno (aio_req grp, int errorno = errno) |
|
|
1144 | CODE: |
|
|
1145 | grp->errorno = errorno; |
|
|
1146 | |
|
|
1147 | void |
|
|
1148 | limit (aio_req grp, int limit) |
|
|
1149 | CODE: |
|
|
1150 | eio_grp_limit (grp, limit); |
|
|
1151 | |
|
|
1152 | void |
|
|
1153 | feed (aio_req grp, SV *callback=&PL_sv_undef) |
|
|
1154 | CODE: |
|
|
1155 | { |
|
|
1156 | SvREFCNT_dec (grp->sv2); |
|
|
1157 | grp->sv2 = newSVsv (callback); |
|
|
1158 | grp->feed = aio_grp_feed; |
|
|
1159 | |
|
|
1160 | if (grp->int2 <= 0) |
|
|
1161 | grp->int2 = 2; |
|
|
1162 | |
|
|
1163 | eio_grp_limit (grp, grp->int2); |
|
|
1164 | } |
|
|
1165 | |