1 | #define PERL_NO_GET_CONTEXT |
|
|
2 | |
|
|
3 | #include "EXTERN.h" |
1 | #include "EXTERN.h" |
4 | #include "perl.h" |
2 | #include "perl.h" |
5 | #include "XSUB.h" |
3 | #include "XSUB.h" |
6 | |
4 | |
|
|
5 | #include "autoconf/config.h" |
|
|
6 | |
7 | #include <sys/types.h> |
7 | #include <sys/types.h> |
8 | #include <sys/stat.h> |
8 | #include <sys/stat.h> |
|
|
9 | |
9 | #include <unistd.h> |
10 | #include <unistd.h> |
10 | #include <fcntl.h> |
11 | #include <fcntl.h> |
11 | #include <signal.h> |
12 | #include <signal.h> |
12 | #include <sched.h> |
13 | #include <sched.h> |
13 | #include <endian.h> |
|
|
14 | |
14 | |
15 | #include <pthread.h> |
15 | #include <pthread.h> |
16 | #include <sys/syscall.h> |
|
|
17 | |
16 | |
18 | typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
17 | typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
19 | typedef void *OutputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
18 | typedef void *OutputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
20 | typedef void *InOutStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
19 | typedef void *InOutStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
21 | |
20 | |
… | |
… | |
42 | off_t offset; |
41 | off_t offset; |
43 | size_t length; |
42 | size_t length; |
44 | ssize_t result; |
43 | ssize_t result; |
45 | mode_t mode; /* open */ |
44 | mode_t mode; /* open */ |
46 | int errorno; |
45 | int errorno; |
47 | SV *data, *callback; |
46 | SV *data, *callback, *fh; |
48 | void *dataptr; |
47 | void *dataptr; |
49 | STRLEN dataoffset; |
48 | STRLEN dataoffset; |
50 | |
49 | |
51 | Stat_t *statdata; |
50 | Stat_t *statdata; |
52 | } aio_cb; |
51 | } aio_cb; |
53 | |
52 | |
54 | typedef aio_cb *aio_req; |
53 | typedef aio_cb *aio_req; |
55 | |
54 | |
56 | static int started; |
55 | static int started; |
57 | static int nreqs; |
56 | static volatile int nreqs; |
58 | static int max_outstanding = 1<<30; |
57 | static int max_outstanding = 1<<30; |
59 | static int respipe [2]; |
58 | static int respipe [2]; |
60 | |
59 | |
61 | static pthread_mutex_t reslock = PTHREAD_MUTEX_INITIALIZER; |
60 | static pthread_mutex_t reslock = PTHREAD_MUTEX_INITIALIZER; |
62 | static pthread_mutex_t reqlock = PTHREAD_MUTEX_INITIALIZER; |
61 | static pthread_mutex_t reqlock = PTHREAD_MUTEX_INITIALIZER; |
… | |
… | |
66 | static volatile aio_req ress, rese; /* queue start, queue end */ |
65 | static volatile aio_req ress, rese; /* queue start, queue end */ |
67 | |
66 | |
68 | static void |
67 | static void |
69 | poll_wait () |
68 | poll_wait () |
70 | { |
69 | { |
71 | if (!nreqs) |
70 | if (nreqs && !ress) |
72 | return; |
71 | { |
73 | |
|
|
74 | fd_set rfd; |
72 | fd_set rfd; |
75 | FD_ZERO(&rfd); |
73 | FD_ZERO(&rfd); |
76 | FD_SET(respipe [0], &rfd); |
74 | FD_SET(respipe [0], &rfd); |
77 | |
75 | |
78 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
76 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
|
|
77 | } |
79 | } |
78 | } |
80 | |
79 | |
81 | static int |
80 | static int |
82 | poll_cb (pTHX) |
81 | poll_cb () |
83 | { |
82 | { |
84 | dSP; |
83 | dSP; |
85 | int count = 0; |
84 | int count = 0; |
86 | aio_req req; |
85 | aio_req req, prv; |
87 | |
86 | |
|
|
87 | pthread_mutex_lock (&reslock); |
|
|
88 | |
88 | { |
89 | { |
89 | /* read and signals sent by the worker threads */ |
90 | /* read any signals sent by the worker threads */ |
90 | char buf [32]; |
91 | char buf [32]; |
91 | while (read (respipe [0], buf, 32) > 0) |
92 | while (read (respipe [0], buf, 32) > 0) |
92 | ; |
93 | ; |
93 | } |
94 | } |
94 | |
95 | |
95 | for (;;) |
96 | req = ress; |
|
|
97 | ress = rese = 0; |
|
|
98 | |
|
|
99 | pthread_mutex_unlock (&reslock); |
|
|
100 | |
|
|
101 | while (req) |
96 | { |
102 | { |
97 | pthread_mutex_lock (&reslock); |
|
|
98 | |
|
|
99 | req = ress; |
|
|
100 | |
|
|
101 | if (ress) |
|
|
102 | { |
|
|
103 | ress = ress->next; |
|
|
104 | if (!ress) rese = 0; |
|
|
105 | } |
|
|
106 | |
|
|
107 | pthread_mutex_unlock (&reslock); |
|
|
108 | |
|
|
109 | if (!req) |
|
|
110 | break; |
|
|
111 | |
|
|
112 | nreqs--; |
103 | nreqs--; |
113 | |
104 | |
114 | if (req->type == REQ_QUIT) |
105 | if (req->type == REQ_QUIT) |
115 | started--; |
106 | started--; |
116 | else |
107 | else |
… | |
… | |
123 | + req->result > 0 ? req->result : 0); |
114 | + req->result > 0 ? req->result : 0); |
124 | |
115 | |
125 | if (req->data) |
116 | if (req->data) |
126 | SvREFCNT_dec (req->data); |
117 | SvREFCNT_dec (req->data); |
127 | |
118 | |
|
|
119 | if (req->fh) |
|
|
120 | SvREFCNT_dec (req->fh); |
|
|
121 | |
128 | if (req->type == REQ_STAT || req->type == REQ_LSTAT || req->type == REQ_FSTAT) |
122 | if (req->type == REQ_STAT || req->type == REQ_LSTAT || req->type == REQ_FSTAT) |
129 | { |
123 | { |
130 | PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT; |
124 | PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT; |
131 | PL_laststatval = req->result; |
125 | PL_laststatval = req->result; |
132 | PL_statcache = *(req->statdata); |
126 | PL_statcache = *(req->statdata); |
133 | |
127 | |
134 | Safefree (req->statdata); |
128 | Safefree (req->statdata); |
135 | } |
129 | } |
136 | |
130 | |
|
|
131 | ENTER; |
137 | PUSHMARK (SP); |
132 | PUSHMARK (SP); |
138 | XPUSHs (sv_2mortal (newSViv (req->result))); |
133 | XPUSHs (sv_2mortal (newSViv (req->result))); |
139 | |
134 | |
140 | if (req->type == REQ_OPEN) |
135 | if (req->type == REQ_OPEN) |
141 | { |
136 | { |
… | |
… | |
144 | |
139 | |
145 | PUTBACK; |
140 | PUTBACK; |
146 | call_pv ("IO::AIO::_fd2fh", G_SCALAR | G_EVAL); |
141 | call_pv ("IO::AIO::_fd2fh", G_SCALAR | G_EVAL); |
147 | SPAGAIN; |
142 | SPAGAIN; |
148 | |
143 | |
149 | fh = POPs; |
144 | fh = SvREFCNT_inc (POPs); |
150 | |
145 | |
151 | PUSHMARK (SP); |
146 | PUSHMARK (SP); |
152 | XPUSHs (fh); |
147 | XPUSHs (sv_2mortal (fh)); |
153 | } |
148 | } |
154 | |
149 | |
|
|
150 | if (SvOK (req->callback)) |
|
|
151 | { |
155 | PUTBACK; |
152 | PUTBACK; |
156 | call_sv (req->callback, G_VOID | G_EVAL); |
153 | call_sv (req->callback, G_VOID | G_EVAL); |
157 | SPAGAIN; |
154 | SPAGAIN; |
|
|
155 | } |
|
|
156 | |
|
|
157 | LEAVE; |
158 | |
158 | |
159 | if (req->callback) |
159 | if (req->callback) |
160 | SvREFCNT_dec (req->callback); |
160 | SvREFCNT_dec (req->callback); |
161 | |
161 | |
162 | errno = errorno; |
162 | errno = errorno; |
163 | count++; |
163 | count++; |
164 | } |
164 | } |
165 | |
165 | |
|
|
166 | prv = req; |
|
|
167 | req = req->next; |
166 | Safefree (req); |
168 | Safefree (prv); |
|
|
169 | |
|
|
170 | /* TODO: croak on errors? */ |
167 | } |
171 | } |
168 | |
172 | |
169 | return count; |
173 | return count; |
170 | } |
174 | } |
171 | |
175 | |
… | |
… | |
226 | req->type = REQ_QUIT; |
230 | req->type = REQ_QUIT; |
227 | |
231 | |
228 | send_req (req); |
232 | send_req (req); |
229 | } |
233 | } |
230 | |
234 | |
231 | static void |
|
|
232 | read_write (pTHX_ |
|
|
233 | int dowrite, int fd, off_t offset, size_t length, |
|
|
234 | SV *data, STRLEN dataoffset, SV *callback) |
|
|
235 | { |
|
|
236 | aio_req req; |
|
|
237 | STRLEN svlen; |
|
|
238 | char *svptr = SvPV (data, svlen); |
|
|
239 | |
|
|
240 | SvUPGRADE (data, SVt_PV); |
|
|
241 | SvPOK_on (data); |
|
|
242 | |
|
|
243 | if (dataoffset < 0) |
|
|
244 | dataoffset += svlen; |
|
|
245 | |
|
|
246 | if (dataoffset < 0 || dataoffset > svlen) |
|
|
247 | croak ("data offset outside of string"); |
|
|
248 | |
|
|
249 | if (dowrite) |
|
|
250 | { |
|
|
251 | /* write: check length and adjust. */ |
|
|
252 | if (length < 0 || length + dataoffset > svlen) |
|
|
253 | length = svlen - dataoffset; |
|
|
254 | } |
|
|
255 | else |
|
|
256 | { |
|
|
257 | /* read: grow scalar as necessary */ |
|
|
258 | svptr = SvGROW (data, length + dataoffset); |
|
|
259 | } |
|
|
260 | |
|
|
261 | if (length < 0) |
|
|
262 | croak ("length must not be negative"); |
|
|
263 | |
|
|
264 | Newz (0, req, 1, aio_cb); |
|
|
265 | |
|
|
266 | if (!req) |
|
|
267 | croak ("out of memory during aio_req allocation"); |
|
|
268 | |
|
|
269 | req->type = dowrite ? REQ_WRITE : REQ_READ; |
|
|
270 | req->fd = fd; |
|
|
271 | req->offset = offset; |
|
|
272 | req->length = length; |
|
|
273 | req->data = SvREFCNT_inc (data); |
|
|
274 | req->dataptr = (char *)svptr + dataoffset; |
|
|
275 | req->callback = SvREFCNT_inc (callback); |
|
|
276 | |
|
|
277 | send_req (req); |
|
|
278 | } |
|
|
279 | |
|
|
280 | static void * |
235 | static void * |
281 | aio_proc (void *thr_arg) |
236 | aio_proc (void *thr_arg) |
282 | { |
237 | { |
283 | aio_req req; |
238 | aio_req req; |
284 | int type; |
239 | int type; |
… | |
… | |
309 | |
264 | |
310 | type = req->type; |
265 | type = req->type; |
311 | |
266 | |
312 | switch (type) |
267 | switch (type) |
313 | { |
268 | { |
|
|
269 | #if HAVE_PREADWRITE |
314 | case REQ_READ: req->result = pread64 (req->fd, req->dataptr, req->length, req->offset); break; |
270 | case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; |
315 | case REQ_WRITE: req->result = pwrite64 (req->fd, req->dataptr, req->length, req->offset); break; |
271 | case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; |
316 | #if SYS_readahead |
272 | #else |
|
|
273 | # error "pread/pwrite cannot be emulated, fix your os" |
|
|
274 | #endif |
|
|
275 | |
|
|
276 | #if HAVE_READAHEAD |
317 | case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; |
277 | case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; |
318 | #else |
278 | #else |
|
|
279 | // TODO: emulate |
319 | case REQ_READAHEAD: req->result = -1; errno = ENOSYS; break; |
280 | case REQ_READAHEAD: req->result = -1; errno = ENOSYS; break; |
320 | #endif |
281 | #endif |
321 | |
282 | |
322 | case REQ_STAT: req->result = stat (req->dataptr, req->statdata); break; |
283 | case REQ_STAT: req->result = stat (req->dataptr, req->statdata); break; |
323 | case REQ_LSTAT: req->result = lstat (req->dataptr, req->statdata); break; |
284 | case REQ_LSTAT: req->result = lstat (req->dataptr, req->statdata); break; |
… | |
… | |
325 | |
286 | |
326 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |
287 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |
327 | case REQ_CLOSE: req->result = close (req->fd); break; |
288 | case REQ_CLOSE: req->result = close (req->fd); break; |
328 | case REQ_UNLINK: req->result = unlink (req->dataptr); break; |
289 | case REQ_UNLINK: req->result = unlink (req->dataptr); break; |
329 | |
290 | |
|
|
291 | case REQ_FDATASYNC: |
|
|
292 | #if HAVE_FDATASYNC |
|
|
293 | req->result = fdatasync (req->fd); break; |
|
|
294 | #endif |
330 | case REQ_FSYNC: req->result = fsync (req->fd); break; |
295 | case REQ_FSYNC: req->result = fsync (req->fd); break; |
331 | case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; |
|
|
332 | |
296 | |
333 | case REQ_QUIT: |
297 | case REQ_QUIT: |
334 | break; |
298 | break; |
335 | |
299 | |
336 | default: |
300 | default: |
… | |
… | |
364 | return 0; |
328 | return 0; |
365 | } |
329 | } |
366 | |
330 | |
367 | MODULE = IO::AIO PACKAGE = IO::AIO |
331 | MODULE = IO::AIO PACKAGE = IO::AIO |
368 | |
332 | |
|
|
333 | PROTOTYPES: ENABLE |
|
|
334 | |
369 | BOOT: |
335 | BOOT: |
370 | { |
336 | { |
371 | if (pipe (respipe)) |
337 | if (pipe (respipe)) |
372 | croak ("unable to initialize result pipe"); |
338 | croak ("unable to initialize result pipe"); |
373 | |
339 | |
… | |
… | |
400 | } |
366 | } |
401 | |
367 | |
402 | while (started > nthreads) |
368 | while (started > nthreads) |
403 | { |
369 | { |
404 | poll_wait (); |
370 | poll_wait (); |
405 | poll_cb (aTHX); |
371 | poll_cb (); |
406 | } |
372 | } |
407 | } |
373 | } |
408 | |
374 | |
409 | int |
375 | int |
410 | max_outstanding(nreqs) |
376 | max_outstanding(nreqs) |
… | |
… | |
413 | CODE: |
379 | CODE: |
414 | RETVAL = max_outstanding; |
380 | RETVAL = max_outstanding; |
415 | max_outstanding = nreqs; |
381 | max_outstanding = nreqs; |
416 | |
382 | |
417 | void |
383 | void |
418 | aio_open(pathname,flags,mode,callback) |
384 | aio_open(pathname,flags,mode,callback=&PL_sv_undef) |
419 | SV * pathname |
385 | SV * pathname |
420 | int flags |
386 | int flags |
421 | int mode |
387 | int mode |
422 | SV * callback |
388 | SV * callback |
423 | PROTOTYPE: $$$$ |
389 | PROTOTYPE: $$$;$ |
424 | CODE: |
390 | CODE: |
425 | { |
391 | { |
426 | aio_req req; |
392 | aio_req req; |
427 | |
393 | |
428 | Newz (0, req, 1, aio_cb); |
394 | Newz (0, req, 1, aio_cb); |
… | |
… | |
439 | |
405 | |
440 | send_req (req); |
406 | send_req (req); |
441 | } |
407 | } |
442 | |
408 | |
443 | void |
409 | void |
444 | aio_close(fh,callback) |
410 | aio_close(fh,callback=&PL_sv_undef) |
445 | InputStream fh |
411 | SV * fh |
446 | SV * callback |
412 | SV * callback |
447 | PROTOTYPE: $$ |
413 | PROTOTYPE: $;$ |
448 | ALIAS: |
414 | ALIAS: |
449 | aio_close = REQ_CLOSE |
415 | aio_close = REQ_CLOSE |
450 | aio_fsync = REQ_FSYNC |
416 | aio_fsync = REQ_FSYNC |
451 | aio_fdatasync = REQ_FDATASYNC |
417 | aio_fdatasync = REQ_FDATASYNC |
452 | CODE: |
418 | CODE: |
… | |
… | |
457 | |
423 | |
458 | if (!req) |
424 | if (!req) |
459 | croak ("out of memory during aio_req allocation"); |
425 | croak ("out of memory during aio_req allocation"); |
460 | |
426 | |
461 | req->type = ix; |
427 | req->type = ix; |
|
|
428 | req->fh = newSVsv (fh); |
462 | req->fd = PerlIO_fileno (fh); |
429 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); |
463 | req->callback = SvREFCNT_inc (callback); |
430 | req->callback = SvREFCNT_inc (callback); |
464 | |
431 | |
465 | send_req (req); |
432 | send_req (req); |
466 | } |
433 | } |
467 | |
434 | |
468 | void |
435 | void |
469 | aio_read(fh,offset,length,data,dataoffset,callback) |
436 | aio_read(fh,offset,length,data,dataoffset,callback=&PL_sv_undef) |
470 | InputStream fh |
437 | SV * fh |
471 | UV offset |
438 | UV offset |
472 | IV length |
439 | IV length |
473 | SV * data |
440 | SV * data |
474 | IV dataoffset |
441 | IV dataoffset |
475 | SV * callback |
442 | SV * callback |
|
|
443 | ALIAS: |
|
|
444 | aio_read = REQ_READ |
|
|
445 | aio_write = REQ_WRITE |
476 | PROTOTYPE: $$$$$$ |
446 | PROTOTYPE: $$$$$;$ |
477 | CODE: |
447 | CODE: |
478 | read_write (aTHX_ 0, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); |
|
|
479 | |
|
|
480 | void |
|
|
481 | aio_write(fh,offset,length,data,dataoffset,callback) |
|
|
482 | OutputStream fh |
|
|
483 | UV offset |
|
|
484 | IV length |
|
|
485 | SV * data |
|
|
486 | IV dataoffset |
|
|
487 | SV * callback |
|
|
488 | PROTOTYPE: $$$$$$ |
|
|
489 | CODE: |
|
|
490 | read_write (aTHX_ 1, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); |
|
|
491 | |
|
|
492 | void |
|
|
493 | aio_readahead(fh,offset,length,callback) |
|
|
494 | InputStream fh |
|
|
495 | UV offset |
|
|
496 | IV length |
|
|
497 | SV * callback |
|
|
498 | PROTOTYPE: $$$$ |
|
|
499 | CODE: |
|
|
500 | { |
448 | { |
501 | aio_req req; |
449 | aio_req req; |
|
|
450 | STRLEN svlen; |
|
|
451 | char *svptr = SvPV (data, svlen); |
|
|
452 | |
|
|
453 | SvUPGRADE (data, SVt_PV); |
|
|
454 | SvPOK_on (data); |
|
|
455 | |
|
|
456 | if (dataoffset < 0) |
|
|
457 | dataoffset += svlen; |
|
|
458 | |
|
|
459 | if (dataoffset < 0 || dataoffset > svlen) |
|
|
460 | croak ("data offset outside of string"); |
|
|
461 | |
|
|
462 | if (ix == REQ_WRITE) |
|
|
463 | { |
|
|
464 | /* write: check length and adjust. */ |
|
|
465 | if (length < 0 || length + dataoffset > svlen) |
|
|
466 | length = svlen - dataoffset; |
|
|
467 | } |
|
|
468 | else |
|
|
469 | { |
|
|
470 | /* read: grow scalar as necessary */ |
|
|
471 | svptr = SvGROW (data, length + dataoffset); |
|
|
472 | } |
502 | |
473 | |
503 | if (length < 0) |
474 | if (length < 0) |
504 | croak ("length must not be negative"); |
475 | croak ("length must not be negative"); |
505 | |
476 | |
506 | Newz (0, req, 1, aio_cb); |
477 | Newz (0, req, 1, aio_cb); |
507 | |
478 | |
508 | if (!req) |
479 | if (!req) |
509 | croak ("out of memory during aio_req allocation"); |
480 | croak ("out of memory during aio_req allocation"); |
510 | |
481 | |
|
|
482 | req->type = ix; |
|
|
483 | req->fh = newSVsv (fh); |
|
|
484 | req->fd = PerlIO_fileno (ix == REQ_READ ? IoIFP (sv_2io (fh)) |
|
|
485 | : IoOFP (sv_2io (fh))); |
|
|
486 | req->offset = offset; |
|
|
487 | req->length = length; |
|
|
488 | req->data = SvREFCNT_inc (data); |
|
|
489 | req->dataptr = (char *)svptr + dataoffset; |
|
|
490 | req->callback = SvREFCNT_inc (callback); |
|
|
491 | |
|
|
492 | send_req (req); |
|
|
493 | } |
|
|
494 | |
|
|
495 | void |
|
|
496 | aio_readahead(fh,offset,length,callback=&PL_sv_undef) |
|
|
497 | SV * fh |
|
|
498 | UV offset |
|
|
499 | IV length |
|
|
500 | SV * callback |
|
|
501 | PROTOTYPE: $$$;$ |
|
|
502 | CODE: |
|
|
503 | { |
|
|
504 | aio_req req; |
|
|
505 | |
|
|
506 | if (length < 0) |
|
|
507 | croak ("length must not be negative"); |
|
|
508 | |
|
|
509 | Newz (0, req, 1, aio_cb); |
|
|
510 | |
|
|
511 | if (!req) |
|
|
512 | croak ("out of memory during aio_req allocation"); |
|
|
513 | |
511 | req->type = REQ_READAHEAD; |
514 | req->type = REQ_READAHEAD; |
|
|
515 | req->fh = newSVsv (fh); |
512 | req->fd = PerlIO_fileno (fh); |
516 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); |
513 | req->offset = offset; |
517 | req->offset = offset; |
514 | req->length = length; |
518 | req->length = length; |
515 | req->callback = SvREFCNT_inc (callback); |
519 | req->callback = SvREFCNT_inc (callback); |
516 | |
520 | |
517 | send_req (req); |
521 | send_req (req); |
518 | } |
522 | } |
519 | |
523 | |
520 | void |
524 | void |
521 | aio_stat(fh_or_path,callback) |
525 | aio_stat(fh_or_path,callback=&PL_sv_undef) |
522 | SV * fh_or_path |
526 | SV * fh_or_path |
523 | SV * callback |
527 | SV * callback |
524 | PROTOTYPE: $$ |
|
|
525 | ALIAS: |
528 | ALIAS: |
|
|
529 | aio_stat = REQ_STAT |
526 | aio_lstat = 1 |
530 | aio_lstat = REQ_LSTAT |
527 | CODE: |
531 | CODE: |
528 | { |
532 | { |
529 | aio_req req; |
533 | aio_req req; |
530 | |
534 | |
531 | Newz (0, req, 1, aio_cb); |
535 | Newz (0, req, 1, aio_cb); |
… | |
… | |
538 | if (!req->statdata) |
542 | if (!req->statdata) |
539 | croak ("out of memory during aio_req->statdata allocation"); |
543 | croak ("out of memory during aio_req->statdata allocation"); |
540 | |
544 | |
541 | if (SvPOK (fh_or_path)) |
545 | if (SvPOK (fh_or_path)) |
542 | { |
546 | { |
543 | req->type = ix ? REQ_LSTAT : REQ_STAT; |
547 | req->type = ix; |
544 | req->data = newSVsv (fh_or_path); |
548 | req->data = newSVsv (fh_or_path); |
545 | req->dataptr = SvPV_nolen (req->data); |
549 | req->dataptr = SvPV_nolen (req->data); |
546 | } |
550 | } |
547 | else |
551 | else |
548 | { |
552 | { |
549 | req->type = REQ_FSTAT; |
553 | req->type = REQ_FSTAT; |
|
|
554 | req->fh = newSVsv (fh_or_path); |
550 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
555 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
551 | } |
556 | } |
552 | |
557 | |
553 | req->callback = SvREFCNT_inc (callback); |
558 | req->callback = SvREFCNT_inc (callback); |
554 | |
559 | |
555 | send_req (req); |
560 | send_req (req); |
556 | } |
561 | } |
557 | |
562 | |
558 | void |
563 | void |
559 | aio_unlink(pathname,callback) |
564 | aio_unlink(pathname,callback=&PL_sv_undef) |
560 | SV * pathname |
565 | SV * pathname |
561 | SV * callback |
566 | SV * callback |
562 | PROTOTYPE: $$ |
|
|
563 | CODE: |
567 | CODE: |
564 | { |
568 | { |
565 | aio_req req; |
569 | aio_req req; |
566 | |
570 | |
567 | Newz (0, req, 1, aio_cb); |
571 | Newz (0, req, 1, aio_cb); |
… | |
… | |
575 | req->callback = SvREFCNT_inc (callback); |
579 | req->callback = SvREFCNT_inc (callback); |
576 | |
580 | |
577 | send_req (req); |
581 | send_req (req); |
578 | } |
582 | } |
579 | |
583 | |
|
|
584 | void |
|
|
585 | flush() |
|
|
586 | PROTOTYPE: |
|
|
587 | CODE: |
|
|
588 | while (nreqs) |
|
|
589 | { |
|
|
590 | poll_wait (); |
|
|
591 | poll_cb (); |
|
|
592 | } |
|
|
593 | |
|
|
594 | void |
|
|
595 | poll() |
|
|
596 | PROTOTYPE: |
|
|
597 | CODE: |
|
|
598 | if (nreqs) |
|
|
599 | { |
|
|
600 | poll_wait (); |
|
|
601 | poll_cb (); |
|
|
602 | } |
|
|
603 | |
580 | int |
604 | int |
581 | poll_fileno() |
605 | poll_fileno() |
582 | PROTOTYPE: |
606 | PROTOTYPE: |
583 | CODE: |
607 | CODE: |
584 | RETVAL = respipe [0]; |
608 | RETVAL = respipe [0]; |
… | |
… | |
587 | |
611 | |
588 | int |
612 | int |
589 | poll_cb(...) |
613 | poll_cb(...) |
590 | PROTOTYPE: |
614 | PROTOTYPE: |
591 | CODE: |
615 | CODE: |
592 | RETVAL = poll_cb (aTHX); |
616 | RETVAL = poll_cb (); |
593 | OUTPUT: |
617 | OUTPUT: |
594 | RETVAL |
618 | RETVAL |
595 | |
619 | |
596 | void |
620 | void |
597 | poll_wait() |
621 | poll_wait() |