… | |
… | |
8 | #include "autoconf/config.h" |
8 | #include "autoconf/config.h" |
9 | |
9 | |
10 | #include <pthread.h> |
10 | #include <pthread.h> |
11 | |
11 | |
12 | #include <stddef.h> |
12 | #include <stddef.h> |
|
|
13 | #include <errno.h> |
|
|
14 | #include <sys/time.h> |
|
|
15 | #include <sys/select.h> |
13 | #include <sys/types.h> |
16 | #include <sys/types.h> |
14 | #include <sys/stat.h> |
17 | #include <sys/stat.h> |
15 | #include <limits.h> |
18 | #include <limits.h> |
16 | #include <unistd.h> |
19 | #include <unistd.h> |
17 | #include <fcntl.h> |
20 | #include <fcntl.h> |
… | |
… | |
31 | # else |
34 | # else |
32 | # error sendfile support requested but not available |
35 | # error sendfile support requested but not available |
33 | # endif |
36 | # endif |
34 | #endif |
37 | #endif |
35 | |
38 | |
|
|
39 | /* used for struct dirent, AIX doesn't provide it */ |
|
|
40 | #ifndef NAME_MAX |
|
|
41 | # define NAME_MAX 4096 |
|
|
42 | #endif |
|
|
43 | |
36 | #if __ia64 |
44 | #if __ia64 |
37 | # define STACKSIZE 65536 |
45 | # define STACKSIZE 65536 |
38 | #else |
46 | #else |
39 | # define STACKSIZE 8192 |
47 | # define STACKSIZE 8192 |
40 | #endif |
48 | #endif |
… | |
… | |
44 | REQ_OPEN, REQ_CLOSE, |
52 | REQ_OPEN, REQ_CLOSE, |
45 | REQ_READ, REQ_WRITE, REQ_READAHEAD, |
53 | REQ_READ, REQ_WRITE, REQ_READAHEAD, |
46 | REQ_SENDFILE, |
54 | REQ_SENDFILE, |
47 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, |
55 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, |
48 | REQ_FSYNC, REQ_FDATASYNC, |
56 | REQ_FSYNC, REQ_FDATASYNC, |
49 | REQ_UNLINK, REQ_RMDIR, |
57 | REQ_UNLINK, REQ_RMDIR, REQ_RENAME, |
50 | REQ_READDIR, |
58 | REQ_READDIR, |
51 | REQ_SYMLINK, |
59 | REQ_LINK, REQ_SYMLINK, |
|
|
60 | REQ_SLEEP, |
|
|
61 | REQ_GROUP, |
52 | }; |
62 | }; |
53 | |
63 | |
|
|
64 | #define AIO_REQ_KLASS "IO::AIO::REQ" |
|
|
65 | #define AIO_GRP_KLASS "IO::AIO::GRP" |
|
|
66 | |
54 | typedef struct aio_cb { |
67 | typedef struct aio_cb |
|
|
68 | { |
|
|
69 | struct aio_cb *grp, *grp_prev, *grp_next; |
|
|
70 | |
55 | struct aio_cb *volatile next; |
71 | struct aio_cb *volatile next; |
56 | |
72 | |
57 | int type; |
73 | SV *self; /* the perl counterpart of this request, if any */ |
58 | |
74 | |
59 | /* should receive a cleanup, with unions */ |
75 | SV *data, *callback; |
60 | int fd, fd2; |
76 | SV *fh, *fh2; |
|
|
77 | void *dataptr, *data2ptr; |
|
|
78 | Stat_t *statdata; |
61 | off_t offset; |
79 | off_t offset; |
62 | size_t length; |
80 | size_t length; |
63 | ssize_t result; |
81 | ssize_t result; |
|
|
82 | |
|
|
83 | int type; |
|
|
84 | int fd, fd2; |
|
|
85 | int errorno; |
|
|
86 | STRLEN dataoffset; |
64 | mode_t mode; /* open */ |
87 | mode_t mode; /* open */ |
65 | int errorno; |
88 | unsigned char cancelled; |
66 | SV *data, *callback; |
|
|
67 | SV *fh, *fh2; |
|
|
68 | void *dataptr, *data2ptr; |
|
|
69 | STRLEN dataoffset; |
|
|
70 | |
|
|
71 | Stat_t *statdata; |
|
|
72 | } aio_cb; |
89 | } aio_cb; |
73 | |
90 | |
74 | typedef aio_cb *aio_req; |
91 | typedef aio_cb *aio_req; |
|
|
92 | typedef aio_cb *aio_req_ornot; |
|
|
93 | typedef aio_cb *aio_group; |
75 | |
94 | |
76 | static int started, wanted; |
95 | static int started, wanted; |
77 | static volatile int nreqs; |
96 | static volatile int nreqs; |
78 | static int max_outstanding = 1<<30; |
97 | static int max_outstanding = 1<<30; |
79 | static int respipe [2]; |
98 | static int respipe [2]; |
… | |
… | |
83 | static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; |
102 | static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; |
84 | |
103 | |
85 | static volatile aio_req reqs, reqe; /* queue start, queue end */ |
104 | static volatile aio_req reqs, reqe; /* queue start, queue end */ |
86 | static volatile aio_req ress, rese; /* queue start, queue end */ |
105 | static volatile aio_req ress, rese; /* queue start, queue end */ |
87 | |
106 | |
88 | static void free_req (aio_req req) |
107 | static void req_free (aio_req req); |
89 | { |
|
|
90 | if (req->data) |
|
|
91 | SvREFCNT_dec (req->data); |
|
|
92 | |
108 | |
93 | if (req->fh) |
109 | /* must be called at most once */ |
94 | SvREFCNT_dec (req->fh); |
110 | static SV *req_sv (aio_req req, const char *klass) |
|
|
111 | { |
|
|
112 | req->self = (SV *)newHV (); |
|
|
113 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
95 | |
114 | |
96 | if (req->fh2) |
115 | return sv_2mortal (sv_bless (newRV_inc (req->self), gv_stashpv (klass, 1))); |
97 | SvREFCNT_dec (req->fh2); |
|
|
98 | |
|
|
99 | if (req->statdata) |
|
|
100 | Safefree (req->statdata); |
|
|
101 | |
|
|
102 | if (req->callback) |
|
|
103 | SvREFCNT_dec (req->callback); |
|
|
104 | |
|
|
105 | if (req->type == REQ_READDIR && req->result >= 0) |
|
|
106 | free (req->data2ptr); |
|
|
107 | |
|
|
108 | Safefree (req); |
|
|
109 | } |
116 | } |
110 | |
117 | |
111 | static void |
118 | static aio_req SvAIO_REQ (SV *sv) |
112 | poll_wait () |
119 | { |
|
|
120 | if (!sv_derived_from (sv, AIO_REQ_KLASS) || !SvROK (sv)) |
|
|
121 | croak ("object of class " AIO_REQ_KLASS " expected"); |
|
|
122 | |
|
|
123 | MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
|
|
124 | |
|
|
125 | return mg ? (aio_req)mg->mg_ptr : 0; |
|
|
126 | } |
|
|
127 | |
|
|
128 | static void poll_wait () |
113 | { |
129 | { |
114 | if (nreqs && !ress) |
130 | if (nreqs && !ress) |
115 | { |
131 | { |
116 | fd_set rfd; |
132 | fd_set rfd; |
117 | FD_ZERO(&rfd); |
133 | FD_ZERO(&rfd); |
… | |
… | |
119 | |
135 | |
120 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
136 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
121 | } |
137 | } |
122 | } |
138 | } |
123 | |
139 | |
124 | static int |
140 | static void req_invoke (aio_req req) |
125 | poll_cb () |
141 | { |
|
|
142 | dSP; |
|
|
143 | int errorno = errno; |
|
|
144 | |
|
|
145 | if (req->cancelled || !SvOK (req->callback)) |
|
|
146 | return; |
|
|
147 | |
|
|
148 | errno = req->errorno; |
|
|
149 | |
|
|
150 | ENTER; |
|
|
151 | PUSHMARK (SP); |
|
|
152 | |
|
|
153 | switch (req->type) |
|
|
154 | { |
|
|
155 | case REQ_READDIR: |
|
|
156 | { |
|
|
157 | SV *rv = &PL_sv_undef; |
|
|
158 | |
|
|
159 | if (req->result >= 0) |
|
|
160 | { |
|
|
161 | char *buf = req->data2ptr; |
|
|
162 | AV *av = newAV (); |
|
|
163 | |
|
|
164 | while (req->result) |
|
|
165 | { |
|
|
166 | SV *sv = newSVpv (buf, 0); |
|
|
167 | |
|
|
168 | av_push (av, sv); |
|
|
169 | buf += SvCUR (sv) + 1; |
|
|
170 | req->result--; |
|
|
171 | } |
|
|
172 | |
|
|
173 | rv = sv_2mortal (newRV_noinc ((SV *)av)); |
|
|
174 | } |
|
|
175 | |
|
|
176 | XPUSHs (rv); |
|
|
177 | } |
|
|
178 | break; |
|
|
179 | |
|
|
180 | case REQ_OPEN: |
|
|
181 | { |
|
|
182 | /* convert fd to fh */ |
|
|
183 | SV *fh; |
|
|
184 | |
|
|
185 | XPUSHs (sv_2mortal (newSViv (req->result))); |
|
|
186 | PUTBACK; |
|
|
187 | call_pv ("IO::AIO::_fd2fh", G_SCALAR | G_EVAL); |
|
|
188 | SPAGAIN; |
|
|
189 | |
|
|
190 | fh = SvREFCNT_inc (POPs); |
|
|
191 | |
|
|
192 | PUSHMARK (SP); |
|
|
193 | XPUSHs (sv_2mortal (fh)); |
|
|
194 | } |
|
|
195 | break; |
|
|
196 | |
|
|
197 | case REQ_SLEEP: |
|
|
198 | case REQ_GROUP: |
|
|
199 | break; |
|
|
200 | |
|
|
201 | default: |
|
|
202 | XPUSHs (sv_2mortal (newSViv (req->result))); |
|
|
203 | break; |
|
|
204 | } |
|
|
205 | |
|
|
206 | |
|
|
207 | PUTBACK; |
|
|
208 | call_sv (req->callback, G_VOID | G_EVAL); |
|
|
209 | SPAGAIN; |
|
|
210 | |
|
|
211 | if (SvTRUE (ERRSV)) |
|
|
212 | { |
|
|
213 | req_free (req); |
|
|
214 | croak (0); |
|
|
215 | } |
|
|
216 | |
|
|
217 | LEAVE; |
|
|
218 | |
|
|
219 | errno = errorno; |
|
|
220 | } |
|
|
221 | |
|
|
222 | static void req_free (aio_req req) |
|
|
223 | { |
|
|
224 | if (req->grp) |
|
|
225 | { |
|
|
226 | aio_req grp = req->grp; |
|
|
227 | |
|
|
228 | /* unlink request */ |
|
|
229 | req->grp_next->grp_prev = req->grp_prev; |
|
|
230 | req->grp_prev->grp_next = req->grp_next; |
|
|
231 | |
|
|
232 | if (grp->grp_next == grp) |
|
|
233 | { |
|
|
234 | req_invoke (grp); |
|
|
235 | req_free (grp); |
|
|
236 | } |
|
|
237 | } |
|
|
238 | |
|
|
239 | if (req->self) |
|
|
240 | { |
|
|
241 | sv_unmagic (req->self, PERL_MAGIC_ext); |
|
|
242 | SvREFCNT_dec (req->self); |
|
|
243 | } |
|
|
244 | |
|
|
245 | if (req->data) |
|
|
246 | SvREFCNT_dec (req->data); |
|
|
247 | |
|
|
248 | if (req->fh) |
|
|
249 | SvREFCNT_dec (req->fh); |
|
|
250 | |
|
|
251 | if (req->fh2) |
|
|
252 | SvREFCNT_dec (req->fh2); |
|
|
253 | |
|
|
254 | if (req->statdata) |
|
|
255 | Safefree (req->statdata); |
|
|
256 | |
|
|
257 | if (req->callback) |
|
|
258 | SvREFCNT_dec (req->callback); |
|
|
259 | |
|
|
260 | if (req->type == REQ_READDIR && req->result >= 0) |
|
|
261 | free (req->data2ptr); |
|
|
262 | |
|
|
263 | Safefree (req); |
|
|
264 | } |
|
|
265 | |
|
|
266 | static void req_cancel (aio_req req) |
|
|
267 | { |
|
|
268 | req->cancelled = 1; |
|
|
269 | |
|
|
270 | if (req->type == REQ_GROUP) |
|
|
271 | { |
|
|
272 | aio_req sub; |
|
|
273 | |
|
|
274 | for (sub = req->grp_next; sub != req; sub = sub->grp_next) |
|
|
275 | req_cancel (sub); |
|
|
276 | } |
|
|
277 | } |
|
|
278 | |
|
|
279 | static int poll_cb () |
126 | { |
280 | { |
127 | dSP; |
281 | dSP; |
128 | int count = 0; |
282 | int count = 0; |
129 | int do_croak = 0; |
283 | int do_croak = 0; |
130 | aio_req req; |
284 | aio_req req; |
… | |
… | |
156 | |
310 | |
157 | nreqs--; |
311 | nreqs--; |
158 | |
312 | |
159 | if (req->type == REQ_QUIT) |
313 | if (req->type == REQ_QUIT) |
160 | started--; |
314 | started--; |
|
|
315 | else if (req->type == REQ_GROUP && req->grp_next != req) |
|
|
316 | continue; |
161 | else |
317 | else |
162 | { |
318 | { |
163 | int errorno = errno; |
|
|
164 | errno = req->errorno; |
|
|
165 | |
|
|
166 | if (req->type == REQ_READ) |
319 | if (req->type == REQ_READ) |
167 | SvCUR_set (req->data, req->dataoffset + (req->result > 0 ? req->result : 0)); |
320 | SvCUR_set (req->data, req->dataoffset + (req->result > 0 ? req->result : 0)); |
168 | |
321 | |
169 | if (req->data2ptr && (req->type == REQ_READ || req->type == REQ_WRITE)) |
322 | if (req->data2ptr && (req->type == REQ_READ || req->type == REQ_WRITE)) |
170 | SvREADONLY_off (req->data); |
323 | SvREADONLY_off (req->data); |
… | |
… | |
174 | PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT; |
327 | PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT; |
175 | PL_laststatval = req->result; |
328 | PL_laststatval = req->result; |
176 | PL_statcache = *(req->statdata); |
329 | PL_statcache = *(req->statdata); |
177 | } |
330 | } |
178 | |
331 | |
179 | ENTER; |
332 | req_invoke (req); |
180 | PUSHMARK (SP); |
|
|
181 | |
333 | |
182 | if (req->type == REQ_READDIR) |
|
|
183 | { |
|
|
184 | SV *rv = &PL_sv_undef; |
|
|
185 | |
|
|
186 | if (req->result >= 0) |
|
|
187 | { |
|
|
188 | char *buf = req->data2ptr; |
|
|
189 | AV *av = newAV (); |
|
|
190 | |
|
|
191 | while (req->result) |
|
|
192 | { |
|
|
193 | SV *sv = newSVpv (buf, 0); |
|
|
194 | |
|
|
195 | av_push (av, sv); |
|
|
196 | buf += SvCUR (sv) + 1; |
|
|
197 | req->result--; |
|
|
198 | } |
|
|
199 | |
|
|
200 | rv = sv_2mortal (newRV_noinc ((SV *)av)); |
|
|
201 | } |
|
|
202 | |
|
|
203 | XPUSHs (rv); |
|
|
204 | } |
|
|
205 | else |
|
|
206 | { |
|
|
207 | XPUSHs (sv_2mortal (newSViv (req->result))); |
|
|
208 | |
|
|
209 | if (req->type == REQ_OPEN) |
|
|
210 | { |
|
|
211 | /* convert fd to fh */ |
|
|
212 | SV *fh; |
|
|
213 | |
|
|
214 | PUTBACK; |
|
|
215 | call_pv ("IO::AIO::_fd2fh", G_SCALAR | G_EVAL); |
|
|
216 | SPAGAIN; |
|
|
217 | |
|
|
218 | fh = SvREFCNT_inc (POPs); |
|
|
219 | |
|
|
220 | PUSHMARK (SP); |
|
|
221 | XPUSHs (sv_2mortal (fh)); |
|
|
222 | } |
|
|
223 | } |
|
|
224 | |
|
|
225 | if (SvOK (req->callback)) |
|
|
226 | { |
|
|
227 | PUTBACK; |
|
|
228 | call_sv (req->callback, G_VOID | G_EVAL); |
|
|
229 | SPAGAIN; |
|
|
230 | |
|
|
231 | if (SvTRUE (ERRSV)) |
|
|
232 | { |
|
|
233 | free_req (req); |
|
|
234 | croak (0); |
|
|
235 | } |
|
|
236 | } |
|
|
237 | |
|
|
238 | LEAVE; |
|
|
239 | |
|
|
240 | errno = errorno; |
|
|
241 | count++; |
334 | count++; |
242 | } |
335 | } |
243 | |
336 | |
244 | free_req (req); |
337 | req_free (req); |
245 | } |
338 | } |
246 | |
339 | |
247 | return count; |
340 | return count; |
248 | } |
341 | } |
249 | |
342 | |
250 | static void *aio_proc(void *arg); |
343 | static void *aio_proc(void *arg); |
251 | |
344 | |
252 | static void |
|
|
253 | start_thread (void) |
345 | static void start_thread (void) |
254 | { |
346 | { |
255 | sigset_t fullsigset, oldsigset; |
347 | sigset_t fullsigset, oldsigset; |
256 | pthread_t tid; |
348 | pthread_t tid; |
257 | pthread_attr_t attr; |
349 | pthread_attr_t attr; |
258 | |
350 | |
… | |
… | |
267 | started++; |
359 | started++; |
268 | |
360 | |
269 | sigprocmask (SIG_SETMASK, &oldsigset, 0); |
361 | sigprocmask (SIG_SETMASK, &oldsigset, 0); |
270 | } |
362 | } |
271 | |
363 | |
272 | static void |
364 | static void req_send (aio_req req) |
273 | send_req (aio_req req) |
|
|
274 | { |
365 | { |
275 | while (started < wanted && nreqs >= started) |
366 | while (started < wanted && nreqs >= started) |
276 | start_thread (); |
367 | start_thread (); |
277 | |
368 | |
278 | nreqs++; |
369 | nreqs++; |
… | |
… | |
302 | |
393 | |
303 | poll_wait (); |
394 | poll_wait (); |
304 | } |
395 | } |
305 | } |
396 | } |
306 | |
397 | |
307 | static void |
398 | static void end_thread (void) |
308 | end_thread (void) |
|
|
309 | { |
399 | { |
310 | aio_req req; |
400 | aio_req req; |
311 | Newz (0, req, 1, aio_cb); |
401 | Newz (0, req, 1, aio_cb); |
312 | req->type = REQ_QUIT; |
402 | req->type = REQ_QUIT; |
313 | |
403 | |
314 | send_req (req); |
404 | req_send (req); |
315 | } |
405 | } |
316 | |
406 | |
317 | static void min_parallel (int nthreads) |
407 | static void min_parallel (int nthreads) |
318 | { |
408 | { |
319 | if (wanted < nthreads) |
409 | if (wanted < nthreads) |
… | |
… | |
364 | * normal read/write by using a mutex. slows down execution a lot, |
454 | * normal read/write by using a mutex. slows down execution a lot, |
365 | * but that's your problem, not mine. |
455 | * but that's your problem, not mine. |
366 | */ |
456 | */ |
367 | static pthread_mutex_t preadwritelock = PTHREAD_MUTEX_INITIALIZER; |
457 | static pthread_mutex_t preadwritelock = PTHREAD_MUTEX_INITIALIZER; |
368 | |
458 | |
369 | static ssize_t |
459 | static ssize_t pread (int fd, void *buf, size_t count, off_t offset) |
370 | pread (int fd, void *buf, size_t count, off_t offset) |
|
|
371 | { |
460 | { |
372 | ssize_t res; |
461 | ssize_t res; |
373 | off_t ooffset; |
462 | off_t ooffset; |
374 | |
463 | |
375 | pthread_mutex_lock (&preadwritelock); |
464 | pthread_mutex_lock (&preadwritelock); |
… | |
… | |
380 | pthread_mutex_unlock (&preadwritelock); |
469 | pthread_mutex_unlock (&preadwritelock); |
381 | |
470 | |
382 | return res; |
471 | return res; |
383 | } |
472 | } |
384 | |
473 | |
385 | static ssize_t |
|
|
386 | pwrite (int fd, void *buf, size_t count, off_t offset) |
474 | static ssize_t pwrite (int fd, void *buf, size_t count, off_t offset) |
387 | { |
475 | { |
388 | ssize_t res; |
476 | ssize_t res; |
389 | off_t ooffset; |
477 | off_t ooffset; |
390 | |
478 | |
391 | pthread_mutex_lock (&preadwritelock); |
479 | pthread_mutex_lock (&preadwritelock); |
… | |
… | |
404 | #endif |
492 | #endif |
405 | |
493 | |
406 | #if !HAVE_READAHEAD |
494 | #if !HAVE_READAHEAD |
407 | # define readahead aio_readahead |
495 | # define readahead aio_readahead |
408 | |
496 | |
409 | static ssize_t |
|
|
410 | readahead (int fd, off_t offset, size_t count) |
497 | static ssize_t readahead (int fd, off_t offset, size_t count) |
411 | { |
498 | { |
412 | char readahead_buf[4096]; |
499 | char readahead_buf[4096]; |
413 | |
500 | |
414 | while (count > 0) |
501 | while (count > 0) |
415 | { |
502 | { |
… | |
… | |
427 | #if !HAVE_READDIR_R |
514 | #if !HAVE_READDIR_R |
428 | # define readdir_r aio_readdir_r |
515 | # define readdir_r aio_readdir_r |
429 | |
516 | |
430 | static pthread_mutex_t readdirlock = PTHREAD_MUTEX_INITIALIZER; |
517 | static pthread_mutex_t readdirlock = PTHREAD_MUTEX_INITIALIZER; |
431 | |
518 | |
432 | static int |
|
|
433 | readdir_r (DIR *dirp, struct dirent *ent, struct dirent **res) |
519 | static int readdir_r (DIR *dirp, struct dirent *ent, struct dirent **res) |
434 | { |
520 | { |
435 | struct dirent *e; |
521 | struct dirent *e; |
436 | int errorno; |
522 | int errorno; |
437 | |
523 | |
438 | pthread_mutex_lock (&readdirlock); |
524 | pthread_mutex_lock (&readdirlock); |
… | |
… | |
454 | return e ? 0 : -1; |
540 | return e ? 0 : -1; |
455 | } |
541 | } |
456 | #endif |
542 | #endif |
457 | |
543 | |
458 | /* sendfile always needs emulation */ |
544 | /* sendfile always needs emulation */ |
459 | static ssize_t |
|
|
460 | sendfile_ (int ofd, int ifd, off_t offset, size_t count) |
545 | static ssize_t sendfile_ (int ofd, int ifd, off_t offset, size_t count) |
461 | { |
546 | { |
462 | ssize_t res; |
547 | ssize_t res; |
463 | |
548 | |
464 | if (!count) |
549 | if (!count) |
465 | return 0; |
550 | return 0; |
… | |
… | |
499 | |
584 | |
500 | if (res < 0 && sbytes) |
585 | if (res < 0 && sbytes) |
501 | res = sbytes; |
586 | res = sbytes; |
502 | } |
587 | } |
503 | |
588 | |
|
|
589 | # endif |
504 | # else |
590 | #else |
505 | res = -1; |
591 | res = -1; |
506 | errno = ENOSYS; |
592 | errno = ENOSYS; |
507 | # endif |
|
|
508 | #endif |
593 | #endif |
509 | |
594 | |
510 | if (res < 0 |
595 | if (res < 0 |
511 | && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK |
596 | && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK |
512 | #if __solaris |
597 | #if __solaris |
… | |
… | |
517 | { |
602 | { |
518 | /* emulate sendfile. this is a major pain in the ass */ |
603 | /* emulate sendfile. this is a major pain in the ass */ |
519 | char buf[4096]; |
604 | char buf[4096]; |
520 | res = 0; |
605 | res = 0; |
521 | |
606 | |
522 | for (;;) |
607 | while (count) |
523 | { |
608 | { |
524 | ssize_t cnt; |
609 | ssize_t cnt; |
525 | |
610 | |
526 | cnt = pread (ifd, buf, 4096, offset); |
611 | cnt = pread (ifd, buf, count > 4096 ? 4096 : count, offset); |
527 | |
612 | |
528 | if (cnt <= 0) |
613 | if (cnt <= 0) |
529 | { |
614 | { |
530 | if (cnt && !res) res = -1; |
615 | if (cnt && !res) res = -1; |
531 | break; |
616 | break; |
… | |
… | |
539 | break; |
624 | break; |
540 | } |
625 | } |
541 | |
626 | |
542 | offset += cnt; |
627 | offset += cnt; |
543 | res += cnt; |
628 | res += cnt; |
|
|
629 | count -= cnt; |
544 | } |
630 | } |
545 | } |
631 | } |
546 | |
632 | |
547 | return res; |
633 | return res; |
548 | } |
634 | } |
549 | |
635 | |
550 | /* read a full directory */ |
636 | /* read a full directory */ |
551 | static int |
|
|
552 | scandir_ (const char *path, void **namesp) |
637 | static int scandir_ (const char *path, void **namesp) |
553 | { |
638 | { |
554 | DIR *dirp = opendir (path); |
639 | DIR *dirp = opendir (path); |
555 | union |
640 | union |
556 | { |
641 | { |
557 | struct dirent d; |
642 | struct dirent d; |
… | |
… | |
611 | return res; |
696 | return res; |
612 | } |
697 | } |
613 | |
698 | |
614 | /*****************************************************************************/ |
699 | /*****************************************************************************/ |
615 | |
700 | |
616 | static void * |
|
|
617 | aio_proc (void *thr_arg) |
701 | static void *aio_proc (void *thr_arg) |
618 | { |
702 | { |
619 | aio_req req; |
703 | aio_req req; |
620 | int type; |
704 | int type; |
621 | |
705 | |
622 | do |
706 | do |
… | |
… | |
641 | |
725 | |
642 | pthread_mutex_unlock (&reqlock); |
726 | pthread_mutex_unlock (&reqlock); |
643 | |
727 | |
644 | errno = 0; /* strictly unnecessary */ |
728 | errno = 0; /* strictly unnecessary */ |
645 | |
729 | |
646 | type = req->type; |
730 | if (!req->cancelled) |
647 | |
|
|
648 | switch (type) |
731 | switch (req->type) |
649 | { |
732 | { |
650 | case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; |
733 | case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; |
651 | case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; |
734 | case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; |
652 | |
735 | |
653 | case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; |
736 | case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; |
654 | case REQ_SENDFILE: req->result = sendfile_ (req->fd, req->fd2, req->offset, req->length); break; |
737 | case REQ_SENDFILE: req->result = sendfile_ (req->fd, req->fd2, req->offset, req->length); break; |
655 | |
738 | |
656 | case REQ_STAT: req->result = stat (req->dataptr, req->statdata); break; |
739 | case REQ_STAT: req->result = stat (req->dataptr, req->statdata); break; |
657 | case REQ_LSTAT: req->result = lstat (req->dataptr, req->statdata); break; |
740 | case REQ_LSTAT: req->result = lstat (req->dataptr, req->statdata); break; |
658 | case REQ_FSTAT: req->result = fstat (req->fd , req->statdata); break; |
741 | case REQ_FSTAT: req->result = fstat (req->fd , req->statdata); break; |
659 | |
742 | |
660 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |
743 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |
661 | case REQ_CLOSE: req->result = close (req->fd); break; |
744 | case REQ_CLOSE: req->result = close (req->fd); break; |
662 | case REQ_UNLINK: req->result = unlink (req->dataptr); break; |
745 | case REQ_UNLINK: req->result = unlink (req->dataptr); break; |
663 | case REQ_RMDIR: req->result = rmdir (req->dataptr); break; |
746 | case REQ_RMDIR: req->result = rmdir (req->dataptr); break; |
|
|
747 | case REQ_RENAME: req->result = rename (req->data2ptr, req->dataptr); break; |
|
|
748 | case REQ_LINK: req->result = link (req->data2ptr, req->dataptr); break; |
664 | case REQ_SYMLINK: req->result = symlink (req->data2ptr, req->dataptr); break; |
749 | case REQ_SYMLINK: req->result = symlink (req->data2ptr, req->dataptr); break; |
665 | |
750 | |
666 | case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; |
751 | case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; |
667 | case REQ_FSYNC: req->result = fsync (req->fd); break; |
752 | case REQ_FSYNC: req->result = fsync (req->fd); break; |
668 | case REQ_READDIR: req->result = scandir_ (req->dataptr, &req->data2ptr); break; |
753 | case REQ_READDIR: req->result = scandir_ (req->dataptr, &req->data2ptr); break; |
669 | |
754 | |
|
|
755 | case REQ_SLEEP: |
|
|
756 | { |
|
|
757 | struct timeval tv; |
|
|
758 | |
|
|
759 | tv.tv_sec = req->fd; |
|
|
760 | tv.tv_usec = req->fd2; |
|
|
761 | |
|
|
762 | req->result = select (0, 0, 0, 0, &tv); |
|
|
763 | } |
|
|
764 | |
670 | case REQ_QUIT: |
765 | case REQ_QUIT: |
671 | break; |
766 | break; |
672 | |
767 | |
673 | default: |
768 | default: |
674 | req->result = ENOSYS; |
769 | req->result = ENOSYS; |
675 | break; |
770 | break; |
676 | } |
771 | } |
677 | |
772 | |
678 | req->errorno = errno; |
773 | req->errorno = errno; |
679 | |
774 | |
680 | pthread_mutex_lock (&reslock); |
775 | pthread_mutex_lock (&reslock); |
681 | |
776 | |
… | |
… | |
735 | |
830 | |
736 | while (reqs) |
831 | while (reqs) |
737 | { |
832 | { |
738 | prv = reqs; |
833 | prv = reqs; |
739 | reqs = prv->next; |
834 | reqs = prv->next; |
740 | free_req (prv); |
835 | req_free (prv); |
741 | } |
836 | } |
742 | |
837 | |
743 | reqs = reqe = 0; |
838 | reqs = reqe = 0; |
744 | |
839 | |
745 | while (ress) |
840 | while (ress) |
746 | { |
841 | { |
747 | prv = ress; |
842 | prv = ress; |
748 | ress = prv->next; |
843 | ress = prv->next; |
749 | free_req (prv); |
844 | req_free (prv); |
750 | } |
845 | } |
751 | |
846 | |
752 | ress = rese = 0; |
847 | ress = rese = 0; |
753 | |
848 | |
754 | close (respipe [0]); |
849 | close (respipe [0]); |
… | |
… | |
760 | |
855 | |
761 | #define dREQ \ |
856 | #define dREQ \ |
762 | aio_req req; \ |
857 | aio_req req; \ |
763 | \ |
858 | \ |
764 | if (SvOK (callback) && !SvROK (callback)) \ |
859 | if (SvOK (callback) && !SvROK (callback)) \ |
765 | croak ("clalback must be undef or of reference type"); \ |
860 | croak ("callback must be undef or of reference type"); \ |
766 | \ |
861 | \ |
767 | Newz (0, req, 1, aio_cb); \ |
862 | Newz (0, req, 1, aio_cb); \ |
768 | if (!req) \ |
863 | if (!req) \ |
769 | croak ("out of memory during aio_req allocation"); \ |
864 | croak ("out of memory during aio_req allocation"); \ |
770 | \ |
865 | \ |
771 | req->callback = newSVsv (callback); |
866 | req->callback = newSVsv (callback) |
|
|
867 | |
|
|
868 | #define REQ_SEND \ |
|
|
869 | req_send (req); \ |
|
|
870 | \ |
|
|
871 | if (GIMME_V != G_VOID) \ |
|
|
872 | XPUSHs (req_sv (req, AIO_REQ_KLASS)); |
772 | |
873 | |
773 | MODULE = IO::AIO PACKAGE = IO::AIO |
874 | MODULE = IO::AIO PACKAGE = IO::AIO |
774 | |
875 | |
775 | PROTOTYPES: ENABLE |
876 | PROTOTYPES: ENABLE |
776 | |
877 | |
777 | BOOT: |
878 | BOOT: |
778 | { |
879 | { |
|
|
880 | HV *stash = gv_stashpv ("IO::AIO", 1); |
|
|
881 | newCONSTSUB (stash, "EXDEV", newSViv (EXDEV)); |
|
|
882 | newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY)); |
|
|
883 | newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY)); |
|
|
884 | |
779 | create_pipe (); |
885 | create_pipe (); |
780 | pthread_atfork (atfork_prepare, atfork_parent, atfork_child); |
886 | pthread_atfork (atfork_prepare, atfork_parent, atfork_child); |
781 | } |
887 | } |
782 | |
888 | |
783 | void |
889 | void |
784 | min_parallel(nthreads) |
890 | min_parallel (nthreads) |
785 | int nthreads |
891 | int nthreads |
786 | PROTOTYPE: $ |
892 | PROTOTYPE: $ |
787 | |
893 | |
788 | void |
894 | void |
789 | max_parallel(nthreads) |
895 | max_parallel (nthreads) |
790 | int nthreads |
896 | int nthreads |
791 | PROTOTYPE: $ |
897 | PROTOTYPE: $ |
792 | |
898 | |
793 | int |
899 | int |
794 | max_outstanding(nreqs) |
900 | max_outstanding (nreqs) |
795 | int nreqs |
901 | int nreqs |
796 | PROTOTYPE: $ |
902 | PROTOTYPE: $ |
797 | CODE: |
903 | CODE: |
798 | RETVAL = max_outstanding; |
904 | RETVAL = max_outstanding; |
799 | max_outstanding = nreqs; |
905 | max_outstanding = nreqs; |
800 | |
906 | |
801 | void |
907 | void |
802 | aio_open(pathname,flags,mode,callback=&PL_sv_undef) |
908 | aio_open (pathname,flags,mode,callback=&PL_sv_undef) |
803 | SV * pathname |
909 | SV * pathname |
804 | int flags |
910 | int flags |
805 | int mode |
911 | int mode |
806 | SV * callback |
912 | SV * callback |
807 | PROTOTYPE: $$$;$ |
913 | PROTOTYPE: $$$;$ |
808 | CODE: |
914 | PPCODE: |
809 | { |
915 | { |
810 | dREQ; |
916 | dREQ; |
811 | |
917 | |
812 | req->type = REQ_OPEN; |
918 | req->type = REQ_OPEN; |
813 | req->data = newSVsv (pathname); |
919 | req->data = newSVsv (pathname); |
814 | req->dataptr = SvPVbyte_nolen (req->data); |
920 | req->dataptr = SvPVbyte_nolen (req->data); |
815 | req->fd = flags; |
921 | req->fd = flags; |
816 | req->mode = mode; |
922 | req->mode = mode; |
817 | |
923 | |
818 | send_req (req); |
924 | REQ_SEND; |
819 | } |
925 | } |
820 | |
926 | |
821 | void |
927 | void |
822 | aio_close(fh,callback=&PL_sv_undef) |
928 | aio_close (fh,callback=&PL_sv_undef) |
823 | SV * fh |
929 | SV * fh |
824 | SV * callback |
930 | SV * callback |
825 | PROTOTYPE: $;$ |
931 | PROTOTYPE: $;$ |
826 | ALIAS: |
932 | ALIAS: |
827 | aio_close = REQ_CLOSE |
933 | aio_close = REQ_CLOSE |
828 | aio_fsync = REQ_FSYNC |
934 | aio_fsync = REQ_FSYNC |
829 | aio_fdatasync = REQ_FDATASYNC |
935 | aio_fdatasync = REQ_FDATASYNC |
830 | CODE: |
936 | PPCODE: |
831 | { |
937 | { |
832 | dREQ; |
938 | dREQ; |
833 | |
939 | |
834 | req->type = ix; |
940 | req->type = ix; |
835 | req->fh = newSVsv (fh); |
941 | req->fh = newSVsv (fh); |
836 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); |
942 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); |
837 | |
943 | |
838 | send_req (req); |
944 | REQ_SEND (req); |
839 | } |
945 | } |
840 | |
946 | |
841 | void |
947 | void |
842 | aio_read(fh,offset,length,data,dataoffset,callback=&PL_sv_undef) |
948 | aio_read (fh,offset,length,data,dataoffset,callback=&PL_sv_undef) |
843 | SV * fh |
949 | SV * fh |
844 | UV offset |
950 | UV offset |
845 | UV length |
951 | UV length |
846 | SV * data |
952 | SV * data |
847 | UV dataoffset |
953 | UV dataoffset |
848 | SV * callback |
954 | SV * callback |
849 | ALIAS: |
955 | ALIAS: |
850 | aio_read = REQ_READ |
956 | aio_read = REQ_READ |
851 | aio_write = REQ_WRITE |
957 | aio_write = REQ_WRITE |
852 | PROTOTYPE: $$$$$;$ |
958 | PROTOTYPE: $$$$$;$ |
853 | CODE: |
959 | PPCODE: |
854 | { |
960 | { |
855 | aio_req req; |
961 | aio_req req; |
856 | STRLEN svlen; |
962 | STRLEN svlen; |
857 | char *svptr = SvPVbyte (data, svlen); |
963 | char *svptr = SvPVbyte (data, svlen); |
858 | |
964 | |
… | |
… | |
896 | { |
1002 | { |
897 | SvREADONLY_on (data); |
1003 | SvREADONLY_on (data); |
898 | req->data2ptr = (void *)data; |
1004 | req->data2ptr = (void *)data; |
899 | } |
1005 | } |
900 | |
1006 | |
901 | send_req (req); |
1007 | REQ_SEND; |
902 | } |
1008 | } |
903 | } |
1009 | } |
904 | |
1010 | |
905 | void |
1011 | void |
906 | aio_sendfile(out_fh,in_fh,in_offset,length,callback=&PL_sv_undef) |
1012 | aio_sendfile (out_fh,in_fh,in_offset,length,callback=&PL_sv_undef) |
907 | SV * out_fh |
1013 | SV * out_fh |
908 | SV * in_fh |
1014 | SV * in_fh |
909 | UV in_offset |
1015 | UV in_offset |
910 | UV length |
1016 | UV length |
911 | SV * callback |
1017 | SV * callback |
912 | PROTOTYPE: $$$$;$ |
1018 | PROTOTYPE: $$$$;$ |
913 | CODE: |
1019 | PPCODE: |
914 | { |
1020 | { |
915 | dREQ; |
1021 | dREQ; |
916 | |
1022 | |
917 | req->type = REQ_SENDFILE; |
1023 | req->type = REQ_SENDFILE; |
918 | req->fh = newSVsv (out_fh); |
1024 | req->fh = newSVsv (out_fh); |
… | |
… | |
920 | req->fh2 = newSVsv (in_fh); |
1026 | req->fh2 = newSVsv (in_fh); |
921 | req->fd2 = PerlIO_fileno (IoIFP (sv_2io (in_fh))); |
1027 | req->fd2 = PerlIO_fileno (IoIFP (sv_2io (in_fh))); |
922 | req->offset = in_offset; |
1028 | req->offset = in_offset; |
923 | req->length = length; |
1029 | req->length = length; |
924 | |
1030 | |
925 | send_req (req); |
1031 | REQ_SEND; |
926 | } |
1032 | } |
927 | |
1033 | |
928 | void |
1034 | void |
929 | aio_readahead(fh,offset,length,callback=&PL_sv_undef) |
1035 | aio_readahead (fh,offset,length,callback=&PL_sv_undef) |
930 | SV * fh |
1036 | SV * fh |
931 | UV offset |
1037 | UV offset |
932 | IV length |
1038 | IV length |
933 | SV * callback |
1039 | SV * callback |
934 | PROTOTYPE: $$$;$ |
1040 | PROTOTYPE: $$$;$ |
935 | CODE: |
1041 | PPCODE: |
936 | { |
1042 | { |
937 | dREQ; |
1043 | dREQ; |
938 | |
1044 | |
939 | req->type = REQ_READAHEAD; |
1045 | req->type = REQ_READAHEAD; |
940 | req->fh = newSVsv (fh); |
1046 | req->fh = newSVsv (fh); |
941 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); |
1047 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); |
942 | req->offset = offset; |
1048 | req->offset = offset; |
943 | req->length = length; |
1049 | req->length = length; |
944 | |
1050 | |
945 | send_req (req); |
1051 | REQ_SEND; |
946 | } |
1052 | } |
947 | |
1053 | |
948 | void |
1054 | void |
949 | aio_stat(fh_or_path,callback=&PL_sv_undef) |
1055 | aio_stat (fh_or_path,callback=&PL_sv_undef) |
950 | SV * fh_or_path |
1056 | SV * fh_or_path |
951 | SV * callback |
1057 | SV * callback |
952 | ALIAS: |
1058 | ALIAS: |
953 | aio_stat = REQ_STAT |
1059 | aio_stat = REQ_STAT |
954 | aio_lstat = REQ_LSTAT |
1060 | aio_lstat = REQ_LSTAT |
955 | CODE: |
1061 | PPCODE: |
956 | { |
1062 | { |
957 | dREQ; |
1063 | dREQ; |
958 | |
1064 | |
959 | New (0, req->statdata, 1, Stat_t); |
1065 | New (0, req->statdata, 1, Stat_t); |
960 | if (!req->statdata) |
1066 | if (!req->statdata) |
961 | { |
1067 | { |
962 | free_req (req); |
1068 | req_free (req); |
963 | croak ("out of memory during aio_req->statdata allocation"); |
1069 | croak ("out of memory during aio_req->statdata allocation"); |
964 | } |
1070 | } |
965 | |
1071 | |
966 | if (SvPOK (fh_or_path)) |
1072 | if (SvPOK (fh_or_path)) |
967 | { |
1073 | { |
… | |
… | |
974 | req->type = REQ_FSTAT; |
1080 | req->type = REQ_FSTAT; |
975 | req->fh = newSVsv (fh_or_path); |
1081 | req->fh = newSVsv (fh_or_path); |
976 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
1082 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
977 | } |
1083 | } |
978 | |
1084 | |
979 | send_req (req); |
1085 | REQ_SEND; |
980 | } |
1086 | } |
981 | |
1087 | |
982 | void |
1088 | void |
983 | aio_unlink(pathname,callback=&PL_sv_undef) |
1089 | aio_unlink (pathname,callback=&PL_sv_undef) |
984 | SV * pathname |
1090 | SV * pathname |
985 | SV * callback |
1091 | SV * callback |
986 | ALIAS: |
1092 | ALIAS: |
987 | aio_unlink = REQ_UNLINK |
1093 | aio_unlink = REQ_UNLINK |
988 | aio_rmdir = REQ_RMDIR |
1094 | aio_rmdir = REQ_RMDIR |
|
|
1095 | aio_readdir = REQ_READDIR |
989 | CODE: |
1096 | PPCODE: |
990 | { |
1097 | { |
991 | dREQ; |
1098 | dREQ; |
992 | |
1099 | |
993 | req->type = ix; |
1100 | req->type = ix; |
994 | req->data = newSVsv (pathname); |
1101 | req->data = newSVsv (pathname); |
995 | req->dataptr = SvPVbyte_nolen (req->data); |
1102 | req->dataptr = SvPVbyte_nolen (req->data); |
996 | |
1103 | |
997 | send_req (req); |
1104 | REQ_SEND; |
998 | } |
1105 | } |
999 | |
1106 | |
1000 | void |
1107 | void |
1001 | aio_symlink(oldpath,newpath,callback=&PL_sv_undef) |
1108 | aio_link (oldpath,newpath,callback=&PL_sv_undef) |
1002 | SV * oldpath |
1109 | SV * oldpath |
1003 | SV * newpath |
1110 | SV * newpath |
1004 | SV * callback |
1111 | SV * callback |
|
|
1112 | ALIAS: |
|
|
1113 | aio_link = REQ_LINK |
|
|
1114 | aio_symlink = REQ_SYMLINK |
|
|
1115 | aio_rename = REQ_RENAME |
1005 | CODE: |
1116 | PPCODE: |
1006 | { |
1117 | { |
1007 | dREQ; |
1118 | dREQ; |
1008 | |
1119 | |
1009 | req->type = REQ_SYMLINK; |
1120 | req->type = ix; |
1010 | req->fh = newSVsv (oldpath); |
1121 | req->fh = newSVsv (oldpath); |
1011 | req->data2ptr = SvPVbyte_nolen (req->fh); |
1122 | req->data2ptr = SvPVbyte_nolen (req->fh); |
1012 | req->data = newSVsv (newpath); |
1123 | req->data = newSVsv (newpath); |
1013 | req->dataptr = SvPVbyte_nolen (req->data); |
1124 | req->dataptr = SvPVbyte_nolen (req->data); |
1014 | |
1125 | |
1015 | send_req (req); |
1126 | REQ_SEND; |
1016 | } |
1127 | } |
1017 | |
1128 | |
1018 | void |
1129 | void |
1019 | aio_readdir(pathname,callback=&PL_sv_undef) |
1130 | aio_sleep (delay,callback=&PL_sv_undef) |
1020 | SV * pathname |
1131 | double delay |
1021 | SV * callback |
1132 | SV * callback |
1022 | CODE: |
1133 | PPCODE: |
1023 | { |
1134 | { |
1024 | dREQ; |
1135 | dREQ; |
1025 | |
1136 | |
1026 | req->type = REQ_READDIR; |
1137 | req->type = REQ_SLEEP; |
1027 | req->data = newSVsv (pathname); |
1138 | req->fd = delay < 0. ? 0 : delay; |
1028 | req->dataptr = SvPVbyte_nolen (req->data); |
1139 | req->fd2 = delay < 0. ? 0 : 1000. * (delay - req->fd); |
1029 | |
|
|
1030 | send_req (req); |
|
|
1031 | } |
|
|
1032 | |
1140 | |
|
|
1141 | REQ_SEND; |
|
|
1142 | } |
|
|
1143 | |
1033 | void |
1144 | void |
|
|
1145 | aio_group (callback=&PL_sv_undef) |
|
|
1146 | SV * callback |
|
|
1147 | PROTOTYPE: ;& |
|
|
1148 | PPCODE: |
|
|
1149 | { |
|
|
1150 | dREQ; |
|
|
1151 | req->type = REQ_GROUP; |
|
|
1152 | req->grp_next = req; |
|
|
1153 | req->grp_prev = req; |
|
|
1154 | |
|
|
1155 | req_send (req); |
|
|
1156 | XPUSHs (req_sv (req, AIO_GRP_KLASS)); |
|
|
1157 | } |
|
|
1158 | |
|
|
1159 | void |
1034 | flush() |
1160 | flush () |
1035 | PROTOTYPE: |
1161 | PROTOTYPE: |
1036 | CODE: |
1162 | CODE: |
1037 | while (nreqs) |
1163 | while (nreqs) |
1038 | { |
1164 | { |
1039 | poll_wait (); |
1165 | poll_wait (); |
… | |
… | |
1079 | CODE: |
1205 | CODE: |
1080 | RETVAL = nreqs; |
1206 | RETVAL = nreqs; |
1081 | OUTPUT: |
1207 | OUTPUT: |
1082 | RETVAL |
1208 | RETVAL |
1083 | |
1209 | |
|
|
1210 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
|
|
1211 | |
|
|
1212 | void |
|
|
1213 | cancel (aio_req_ornot req) |
|
|
1214 | PROTOTYPE: |
|
|
1215 | CODE: |
|
|
1216 | req_cancel (req); |
|
|
1217 | |
|
|
1218 | MODULE = IO::AIO PACKAGE = IO::AIO::GRP |
|
|
1219 | |
|
|
1220 | void |
|
|
1221 | add (aio_req grp, ...) |
|
|
1222 | PROTOTYPE: $;@ |
|
|
1223 | PPCODE: |
|
|
1224 | { |
|
|
1225 | int i; |
|
|
1226 | |
|
|
1227 | for (i = 1; i < items; ++i ) |
|
|
1228 | { |
|
|
1229 | aio_req req = SvAIO_REQ (ST (i)); |
|
|
1230 | |
|
|
1231 | req->grp_prev = grp; |
|
|
1232 | req->grp_next = grp->grp_next; |
|
|
1233 | grp->grp_next->grp_prev = req; |
|
|
1234 | grp->grp_next = req; |
|
|
1235 | |
|
|
1236 | req->grp = grp; |
|
|
1237 | |
|
|
1238 | if (GIMME_V != G_VOID) |
|
|
1239 | XPUSHs (sv_2mortal (newSVsv (ST (i)))); |
|
|
1240 | } |
|
|
1241 | } |
|
|
1242 | |