1 | #include "EXTERN.h" |
1 | #include "EXTERN.h" |
2 | #include "perl.h" |
2 | #include "perl.h" |
3 | #include "XSUB.h" |
3 | #include "XSUB.h" |
4 | |
4 | |
|
|
5 | #include "autoconf/config.h" |
|
|
6 | |
5 | #include <sys/types.h> |
7 | #include <sys/types.h> |
6 | #include <sys/stat.h> |
8 | #include <sys/stat.h> |
|
|
9 | |
7 | #include <unistd.h> |
10 | #include <unistd.h> |
8 | #include <fcntl.h> |
11 | #include <fcntl.h> |
9 | #include <signal.h> |
12 | #include <signal.h> |
10 | #include <sched.h> |
13 | #include <sched.h> |
11 | #include <endian.h> |
|
|
12 | |
14 | |
13 | #include <pthread.h> |
15 | #include <pthread.h> |
14 | #include <sys/syscall.h> |
|
|
15 | |
16 | |
16 | 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 ;) */ |
17 | 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 ;) */ |
18 | 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 ;) */ |
19 | |
20 | |
… | |
… | |
40 | off_t offset; |
41 | off_t offset; |
41 | size_t length; |
42 | size_t length; |
42 | ssize_t result; |
43 | ssize_t result; |
43 | mode_t mode; /* open */ |
44 | mode_t mode; /* open */ |
44 | int errorno; |
45 | int errorno; |
45 | SV *data, *callback; |
46 | SV *data, *callback, *fh; |
46 | void *dataptr; |
47 | void *dataptr; |
47 | STRLEN dataoffset; |
48 | STRLEN dataoffset; |
48 | |
49 | |
49 | Stat_t *statdata; |
50 | Stat_t *statdata; |
50 | } aio_cb; |
51 | } aio_cb; |
51 | |
52 | |
52 | typedef aio_cb *aio_req; |
53 | typedef aio_cb *aio_req; |
53 | |
54 | |
54 | static int started; |
55 | static int started; |
55 | static int nreqs; |
56 | static volatile int nreqs; |
56 | static int max_outstanding = 1<<30; |
57 | static int max_outstanding = 1<<30; |
57 | static int respipe [2]; |
58 | static int respipe [2]; |
58 | |
59 | |
59 | static pthread_mutex_t reslock = PTHREAD_MUTEX_INITIALIZER; |
60 | static pthread_mutex_t reslock = PTHREAD_MUTEX_INITIALIZER; |
60 | static pthread_mutex_t reqlock = PTHREAD_MUTEX_INITIALIZER; |
61 | static pthread_mutex_t reqlock = PTHREAD_MUTEX_INITIALIZER; |
… | |
… | |
64 | static volatile aio_req ress, rese; /* queue start, queue end */ |
65 | static volatile aio_req ress, rese; /* queue start, queue end */ |
65 | |
66 | |
66 | static void |
67 | static void |
67 | poll_wait () |
68 | poll_wait () |
68 | { |
69 | { |
69 | if (!nreqs) |
70 | if (nreqs && !ress) |
70 | return; |
71 | { |
71 | |
|
|
72 | fd_set rfd; |
72 | fd_set rfd; |
73 | FD_ZERO(&rfd); |
73 | FD_ZERO(&rfd); |
74 | FD_SET(respipe [0], &rfd); |
74 | FD_SET(respipe [0], &rfd); |
75 | |
75 | |
76 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
76 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
|
|
77 | } |
77 | } |
78 | } |
78 | |
79 | |
79 | static int |
80 | static int |
80 | poll_cb () |
81 | poll_cb () |
81 | { |
82 | { |
82 | dSP; |
83 | dSP; |
83 | int count = 0; |
84 | int count = 0; |
84 | aio_req req; |
85 | aio_req req, prv; |
85 | |
86 | |
|
|
87 | pthread_mutex_lock (&reslock); |
|
|
88 | |
86 | { |
89 | { |
87 | /* read and signals sent by the worker threads */ |
90 | /* read any signals sent by the worker threads */ |
88 | char buf [32]; |
91 | char buf [32]; |
89 | while (read (respipe [0], buf, 32) > 0) |
92 | while (read (respipe [0], buf, 32) > 0) |
90 | ; |
93 | ; |
91 | } |
94 | } |
92 | |
95 | |
93 | for (;;) |
96 | req = ress; |
|
|
97 | ress = rese = 0; |
|
|
98 | |
|
|
99 | pthread_mutex_unlock (&reslock); |
|
|
100 | |
|
|
101 | while (req) |
94 | { |
102 | { |
95 | pthread_mutex_lock (&reslock); |
|
|
96 | |
|
|
97 | req = ress; |
|
|
98 | |
|
|
99 | if (ress) |
|
|
100 | { |
|
|
101 | ress = ress->next; |
|
|
102 | if (!ress) rese = 0; |
|
|
103 | } |
|
|
104 | |
|
|
105 | pthread_mutex_unlock (&reslock); |
|
|
106 | |
|
|
107 | if (!req) |
|
|
108 | break; |
|
|
109 | |
|
|
110 | nreqs--; |
103 | nreqs--; |
111 | |
104 | |
112 | if (req->type == REQ_QUIT) |
105 | if (req->type == REQ_QUIT) |
113 | started--; |
106 | started--; |
114 | else |
107 | else |
… | |
… | |
121 | + req->result > 0 ? req->result : 0); |
114 | + req->result > 0 ? req->result : 0); |
122 | |
115 | |
123 | if (req->data) |
116 | if (req->data) |
124 | SvREFCNT_dec (req->data); |
117 | SvREFCNT_dec (req->data); |
125 | |
118 | |
|
|
119 | if (req->fh) |
|
|
120 | SvREFCNT_dec (req->fh); |
|
|
121 | |
126 | 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) |
127 | { |
123 | { |
128 | PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT; |
124 | PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT; |
129 | PL_laststatval = req->result; |
125 | PL_laststatval = req->result; |
130 | PL_statcache = *(req->statdata); |
126 | PL_statcache = *(req->statdata); |
131 | |
127 | |
132 | Safefree (req->statdata); |
128 | Safefree (req->statdata); |
133 | } |
129 | } |
134 | |
130 | |
|
|
131 | ENTER; |
135 | PUSHMARK (SP); |
132 | PUSHMARK (SP); |
136 | XPUSHs (sv_2mortal (newSViv (req->result))); |
133 | XPUSHs (sv_2mortal (newSViv (req->result))); |
137 | |
134 | |
138 | if (req->type == REQ_OPEN) |
135 | if (req->type == REQ_OPEN) |
139 | { |
136 | { |
… | |
… | |
142 | |
139 | |
143 | PUTBACK; |
140 | PUTBACK; |
144 | call_pv ("IO::AIO::_fd2fh", G_SCALAR | G_EVAL); |
141 | call_pv ("IO::AIO::_fd2fh", G_SCALAR | G_EVAL); |
145 | SPAGAIN; |
142 | SPAGAIN; |
146 | |
143 | |
147 | fh = POPs; |
144 | fh = SvREFCNT_inc (POPs); |
148 | |
145 | |
149 | PUSHMARK (SP); |
146 | PUSHMARK (SP); |
150 | XPUSHs (fh); |
147 | XPUSHs (sv_2mortal (fh)); |
151 | } |
148 | } |
152 | |
149 | |
|
|
150 | if (SvOK (req->callback)) |
|
|
151 | { |
153 | PUTBACK; |
152 | PUTBACK; |
154 | call_sv (req->callback, G_VOID | G_EVAL); |
153 | call_sv (req->callback, G_VOID | G_EVAL); |
155 | SPAGAIN; |
154 | SPAGAIN; |
|
|
155 | } |
|
|
156 | |
|
|
157 | LEAVE; |
156 | |
158 | |
157 | if (req->callback) |
159 | if (req->callback) |
158 | SvREFCNT_dec (req->callback); |
160 | SvREFCNT_dec (req->callback); |
159 | |
161 | |
160 | errno = errorno; |
162 | errno = errorno; |
161 | count++; |
163 | count++; |
162 | } |
164 | } |
163 | |
165 | |
|
|
166 | prv = req; |
|
|
167 | req = req->next; |
164 | Safefree (req); |
168 | Safefree (prv); |
|
|
169 | |
|
|
170 | /* TODO: croak on errors? */ |
165 | } |
171 | } |
166 | |
172 | |
167 | return count; |
173 | return count; |
168 | } |
174 | } |
169 | |
175 | |
… | |
… | |
224 | req->type = REQ_QUIT; |
230 | req->type = REQ_QUIT; |
225 | |
231 | |
226 | send_req (req); |
232 | send_req (req); |
227 | } |
233 | } |
228 | |
234 | |
229 | static void |
235 | /* work around various missing functions */ |
230 | read_write (int dowrite, int fd, off_t offset, size_t length, |
|
|
231 | SV *data, STRLEN dataoffset, SV *callback) |
|
|
232 | { |
|
|
233 | aio_req req; |
|
|
234 | STRLEN svlen; |
|
|
235 | char *svptr = SvPV (data, svlen); |
|
|
236 | |
236 | |
237 | SvUPGRADE (data, SVt_PV); |
237 | #if !HAVE_PREADWRITE |
238 | SvPOK_on (data); |
238 | # define pread aio_pread |
|
|
239 | # define pwrite aio_pwrite |
239 | |
240 | |
240 | if (dataoffset < 0) |
241 | /* |
241 | dataoffset += svlen; |
242 | * make our pread/pwrite safe against themselves, but not against |
|
|
243 | * normal read/write by using a mutex. slows down execution a lot, |
|
|
244 | * but that's your problem, not mine. |
|
|
245 | */ |
|
|
246 | static pthread_mutex_t iolock = PTHREAD_MUTEX_INITIALIZER; |
242 | |
247 | |
243 | if (dataoffset < 0 || dataoffset > svlen) |
248 | static ssize_t |
244 | croak ("data offset outside of string"); |
249 | pread (int fd, void *buf, size_t count, off_t offset) |
|
|
250 | { |
|
|
251 | ssize_t res; |
|
|
252 | off_t ooffset; |
245 | |
253 | |
246 | if (dowrite) |
254 | pthread_mutex_lock (&iolock); |
|
|
255 | ooffset = lseek (fd, 0, SEEK_CUR); |
|
|
256 | lseek (fd, offset, SEEK_SET); |
|
|
257 | res = read (fd, buf, count); |
|
|
258 | lseek (fd, ooffset, SEEK_SET); |
|
|
259 | pthread_mutex_unlock (&iolock); |
|
|
260 | |
|
|
261 | return res; |
|
|
262 | } |
|
|
263 | |
|
|
264 | static ssize_t |
|
|
265 | pwrite (int fd, void *buf, size_t count, off_t offset) |
|
|
266 | { |
|
|
267 | ssize_t res; |
|
|
268 | off_t ooffset; |
|
|
269 | |
|
|
270 | pthread_mutex_lock (&iolock); |
|
|
271 | ooffset = lseek (fd, 0, SEEK_CUR); |
|
|
272 | lseek (fd, offset, SEEK_SET); |
|
|
273 | res = write (fd, buf, count); |
|
|
274 | lseek (fd, offset, SEEK_SET); |
|
|
275 | pthread_mutex_unlock (&iolock); |
|
|
276 | |
|
|
277 | return res; |
|
|
278 | } |
|
|
279 | #endif |
|
|
280 | |
|
|
281 | #if !HAVE_FDATASYNC |
|
|
282 | # define fdatasync fsync |
|
|
283 | #endif |
|
|
284 | |
|
|
285 | #if !HAVE_READAHEAD |
|
|
286 | # define readahead aio_readahead |
|
|
287 | |
|
|
288 | static char readahead_buf[4096]; |
|
|
289 | |
|
|
290 | static ssize_t |
|
|
291 | readahead (int fd, off_t offset, size_t count) |
|
|
292 | { |
|
|
293 | while (count > 0) |
247 | { |
294 | { |
248 | /* write: check length and adjust. */ |
295 | size_t len = count < sizeof (readahead_buf) ? count : sizeof (readahead_buf); |
249 | if (length < 0 || length + dataoffset > svlen) |
296 | |
250 | length = svlen - dataoffset; |
297 | pread (fd, readahead_buf, len, offset); |
|
|
298 | offset += len; |
|
|
299 | count -= len; |
251 | } |
300 | } |
252 | else |
|
|
253 | { |
|
|
254 | /* read: grow scalar as necessary */ |
|
|
255 | svptr = SvGROW (data, length + dataoffset); |
|
|
256 | } |
|
|
257 | |
301 | |
258 | if (length < 0) |
302 | errno = 0; |
259 | croak ("length must not be negative"); |
|
|
260 | |
|
|
261 | Newz (0, req, 1, aio_cb); |
|
|
262 | |
|
|
263 | if (!req) |
|
|
264 | croak ("out of memory during aio_req allocation"); |
|
|
265 | |
|
|
266 | req->type = dowrite ? REQ_WRITE : REQ_READ; |
|
|
267 | req->fd = fd; |
|
|
268 | req->offset = offset; |
|
|
269 | req->length = length; |
|
|
270 | req->data = SvREFCNT_inc (data); |
|
|
271 | req->dataptr = (char *)svptr + dataoffset; |
|
|
272 | req->callback = SvREFCNT_inc (callback); |
|
|
273 | |
|
|
274 | send_req (req); |
|
|
275 | } |
303 | } |
|
|
304 | #endif |
276 | |
305 | |
277 | static void * |
306 | static void * |
278 | aio_proc (void *thr_arg) |
307 | aio_proc (void *thr_arg) |
279 | { |
308 | { |
280 | aio_req req; |
309 | aio_req req; |
… | |
… | |
306 | |
335 | |
307 | type = req->type; |
336 | type = req->type; |
308 | |
337 | |
309 | switch (type) |
338 | switch (type) |
310 | { |
339 | { |
311 | case REQ_READ: req->result = pread64 (req->fd, req->dataptr, req->length, req->offset); break; |
340 | case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; |
312 | case REQ_WRITE: req->result = pwrite64 (req->fd, req->dataptr, req->length, req->offset); break; |
341 | case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; |
313 | #if SYS_readahead |
342 | |
314 | case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; |
343 | case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; |
315 | #else |
|
|
316 | case REQ_READAHEAD: req->result = -1; errno = ENOSYS; break; |
|
|
317 | #endif |
|
|
318 | |
344 | |
319 | case REQ_STAT: req->result = stat (req->dataptr, req->statdata); break; |
345 | case REQ_STAT: req->result = stat (req->dataptr, req->statdata); break; |
320 | case REQ_LSTAT: req->result = lstat (req->dataptr, req->statdata); break; |
346 | case REQ_LSTAT: req->result = lstat (req->dataptr, req->statdata); break; |
321 | case REQ_FSTAT: req->result = fstat (req->fd , req->statdata); break; |
347 | case REQ_FSTAT: req->result = fstat (req->fd , req->statdata); break; |
322 | |
348 | |
323 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |
349 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |
324 | case REQ_CLOSE: req->result = close (req->fd); break; |
350 | case REQ_CLOSE: req->result = close (req->fd); break; |
325 | case REQ_UNLINK: req->result = unlink (req->dataptr); break; |
351 | case REQ_UNLINK: req->result = unlink (req->dataptr); break; |
326 | |
352 | |
|
|
353 | case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; |
327 | case REQ_FSYNC: req->result = fsync (req->fd); break; |
354 | case REQ_FSYNC: req->result = fsync (req->fd); break; |
328 | case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; |
|
|
329 | |
355 | |
330 | case REQ_QUIT: |
356 | case REQ_QUIT: |
331 | break; |
357 | break; |
332 | |
358 | |
333 | default: |
359 | default: |
… | |
… | |
361 | return 0; |
387 | return 0; |
362 | } |
388 | } |
363 | |
389 | |
364 | MODULE = IO::AIO PACKAGE = IO::AIO |
390 | MODULE = IO::AIO PACKAGE = IO::AIO |
365 | |
391 | |
|
|
392 | PROTOTYPES: ENABLE |
|
|
393 | |
366 | BOOT: |
394 | BOOT: |
367 | { |
395 | { |
368 | if (pipe (respipe)) |
396 | if (pipe (respipe)) |
369 | croak ("unable to initialize result pipe"); |
397 | croak ("unable to initialize result pipe"); |
370 | |
398 | |
… | |
… | |
410 | CODE: |
438 | CODE: |
411 | RETVAL = max_outstanding; |
439 | RETVAL = max_outstanding; |
412 | max_outstanding = nreqs; |
440 | max_outstanding = nreqs; |
413 | |
441 | |
414 | void |
442 | void |
415 | aio_open(pathname,flags,mode,callback) |
443 | aio_open(pathname,flags,mode,callback=&PL_sv_undef) |
416 | SV * pathname |
444 | SV * pathname |
417 | int flags |
445 | int flags |
418 | int mode |
446 | int mode |
419 | SV * callback |
447 | SV * callback |
420 | PROTOTYPE: $$$$ |
448 | PROTOTYPE: $$$;$ |
421 | CODE: |
449 | CODE: |
422 | { |
450 | { |
423 | aio_req req; |
451 | aio_req req; |
424 | |
452 | |
425 | Newz (0, req, 1, aio_cb); |
453 | Newz (0, req, 1, aio_cb); |
… | |
… | |
436 | |
464 | |
437 | send_req (req); |
465 | send_req (req); |
438 | } |
466 | } |
439 | |
467 | |
440 | void |
468 | void |
441 | aio_close(fh,callback) |
469 | aio_close(fh,callback=&PL_sv_undef) |
442 | InputStream fh |
470 | SV * fh |
443 | SV * callback |
471 | SV * callback |
444 | PROTOTYPE: $$ |
472 | PROTOTYPE: $;$ |
445 | ALIAS: |
473 | ALIAS: |
446 | aio_close = REQ_CLOSE |
474 | aio_close = REQ_CLOSE |
447 | aio_fsync = REQ_FSYNC |
475 | aio_fsync = REQ_FSYNC |
448 | aio_fdatasync = REQ_FDATASYNC |
476 | aio_fdatasync = REQ_FDATASYNC |
449 | CODE: |
477 | CODE: |
… | |
… | |
454 | |
482 | |
455 | if (!req) |
483 | if (!req) |
456 | croak ("out of memory during aio_req allocation"); |
484 | croak ("out of memory during aio_req allocation"); |
457 | |
485 | |
458 | req->type = ix; |
486 | req->type = ix; |
|
|
487 | req->fh = newSVsv (fh); |
459 | req->fd = PerlIO_fileno (fh); |
488 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); |
460 | req->callback = SvREFCNT_inc (callback); |
489 | req->callback = SvREFCNT_inc (callback); |
461 | |
490 | |
462 | send_req (req); |
491 | send_req (req); |
463 | } |
492 | } |
464 | |
493 | |
465 | void |
494 | void |
466 | aio_read(fh,offset,length,data,dataoffset,callback) |
495 | aio_read(fh,offset,length,data,dataoffset,callback=&PL_sv_undef) |
467 | InputStream fh |
496 | SV * fh |
468 | UV offset |
497 | UV offset |
469 | IV length |
498 | IV length |
470 | SV * data |
499 | SV * data |
471 | IV dataoffset |
500 | IV dataoffset |
472 | SV * callback |
501 | SV * callback |
|
|
502 | ALIAS: |
|
|
503 | aio_read = REQ_READ |
|
|
504 | aio_write = REQ_WRITE |
473 | PROTOTYPE: $$$$$$ |
505 | PROTOTYPE: $$$$$;$ |
474 | CODE: |
506 | CODE: |
475 | read_write (0, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); |
|
|
476 | |
|
|
477 | void |
|
|
478 | aio_write(fh,offset,length,data,dataoffset,callback) |
|
|
479 | OutputStream fh |
|
|
480 | UV offset |
|
|
481 | IV length |
|
|
482 | SV * data |
|
|
483 | IV dataoffset |
|
|
484 | SV * callback |
|
|
485 | PROTOTYPE: $$$$$$ |
|
|
486 | CODE: |
|
|
487 | read_write (1, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); |
|
|
488 | |
|
|
489 | void |
|
|
490 | aio_readahead(fh,offset,length,callback) |
|
|
491 | InputStream fh |
|
|
492 | UV offset |
|
|
493 | IV length |
|
|
494 | SV * callback |
|
|
495 | PROTOTYPE: $$$$ |
|
|
496 | CODE: |
|
|
497 | { |
507 | { |
498 | aio_req req; |
508 | aio_req req; |
|
|
509 | STRLEN svlen; |
|
|
510 | char *svptr = SvPV (data, svlen); |
|
|
511 | |
|
|
512 | SvUPGRADE (data, SVt_PV); |
|
|
513 | SvPOK_on (data); |
|
|
514 | |
|
|
515 | if (dataoffset < 0) |
|
|
516 | dataoffset += svlen; |
|
|
517 | |
|
|
518 | if (dataoffset < 0 || dataoffset > svlen) |
|
|
519 | croak ("data offset outside of string"); |
|
|
520 | |
|
|
521 | if (ix == REQ_WRITE) |
|
|
522 | { |
|
|
523 | /* write: check length and adjust. */ |
|
|
524 | if (length < 0 || length + dataoffset > svlen) |
|
|
525 | length = svlen - dataoffset; |
|
|
526 | } |
|
|
527 | else |
|
|
528 | { |
|
|
529 | /* read: grow scalar as necessary */ |
|
|
530 | svptr = SvGROW (data, length + dataoffset); |
|
|
531 | } |
499 | |
532 | |
500 | if (length < 0) |
533 | if (length < 0) |
501 | croak ("length must not be negative"); |
534 | croak ("length must not be negative"); |
502 | |
535 | |
503 | Newz (0, req, 1, aio_cb); |
536 | Newz (0, req, 1, aio_cb); |
504 | |
537 | |
505 | if (!req) |
538 | if (!req) |
506 | croak ("out of memory during aio_req allocation"); |
539 | croak ("out of memory during aio_req allocation"); |
507 | |
540 | |
|
|
541 | req->type = ix; |
|
|
542 | req->fh = newSVsv (fh); |
|
|
543 | req->fd = PerlIO_fileno (ix == REQ_READ ? IoIFP (sv_2io (fh)) |
|
|
544 | : IoOFP (sv_2io (fh))); |
|
|
545 | req->offset = offset; |
|
|
546 | req->length = length; |
|
|
547 | req->data = SvREFCNT_inc (data); |
|
|
548 | req->dataptr = (char *)svptr + dataoffset; |
|
|
549 | req->callback = SvREFCNT_inc (callback); |
|
|
550 | |
|
|
551 | send_req (req); |
|
|
552 | } |
|
|
553 | |
|
|
554 | void |
|
|
555 | aio_readahead(fh,offset,length,callback=&PL_sv_undef) |
|
|
556 | SV * fh |
|
|
557 | UV offset |
|
|
558 | IV length |
|
|
559 | SV * callback |
|
|
560 | PROTOTYPE: $$$;$ |
|
|
561 | CODE: |
|
|
562 | { |
|
|
563 | aio_req req; |
|
|
564 | |
|
|
565 | if (length < 0) |
|
|
566 | croak ("length must not be negative"); |
|
|
567 | |
|
|
568 | Newz (0, req, 1, aio_cb); |
|
|
569 | |
|
|
570 | if (!req) |
|
|
571 | croak ("out of memory during aio_req allocation"); |
|
|
572 | |
508 | req->type = REQ_READAHEAD; |
573 | req->type = REQ_READAHEAD; |
|
|
574 | req->fh = newSVsv (fh); |
509 | req->fd = PerlIO_fileno (fh); |
575 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); |
510 | req->offset = offset; |
576 | req->offset = offset; |
511 | req->length = length; |
577 | req->length = length; |
512 | req->callback = SvREFCNT_inc (callback); |
578 | req->callback = SvREFCNT_inc (callback); |
513 | |
579 | |
514 | send_req (req); |
580 | send_req (req); |
515 | } |
581 | } |
516 | |
582 | |
517 | void |
583 | void |
518 | aio_stat(fh_or_path,callback) |
584 | aio_stat(fh_or_path,callback=&PL_sv_undef) |
519 | SV * fh_or_path |
585 | SV * fh_or_path |
520 | SV * callback |
586 | SV * callback |
521 | PROTOTYPE: $$ |
|
|
522 | ALIAS: |
587 | ALIAS: |
|
|
588 | aio_stat = REQ_STAT |
523 | aio_lstat = 1 |
589 | aio_lstat = REQ_LSTAT |
524 | CODE: |
590 | CODE: |
525 | { |
591 | { |
526 | aio_req req; |
592 | aio_req req; |
527 | |
593 | |
528 | Newz (0, req, 1, aio_cb); |
594 | Newz (0, req, 1, aio_cb); |
… | |
… | |
535 | if (!req->statdata) |
601 | if (!req->statdata) |
536 | croak ("out of memory during aio_req->statdata allocation"); |
602 | croak ("out of memory during aio_req->statdata allocation"); |
537 | |
603 | |
538 | if (SvPOK (fh_or_path)) |
604 | if (SvPOK (fh_or_path)) |
539 | { |
605 | { |
540 | req->type = ix ? REQ_LSTAT : REQ_STAT; |
606 | req->type = ix; |
541 | req->data = newSVsv (fh_or_path); |
607 | req->data = newSVsv (fh_or_path); |
542 | req->dataptr = SvPV_nolen (req->data); |
608 | req->dataptr = SvPV_nolen (req->data); |
543 | } |
609 | } |
544 | else |
610 | else |
545 | { |
611 | { |
546 | req->type = REQ_FSTAT; |
612 | req->type = REQ_FSTAT; |
|
|
613 | req->fh = newSVsv (fh_or_path); |
547 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
614 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
548 | } |
615 | } |
549 | |
616 | |
550 | req->callback = SvREFCNT_inc (callback); |
617 | req->callback = SvREFCNT_inc (callback); |
551 | |
618 | |
552 | send_req (req); |
619 | send_req (req); |
553 | } |
620 | } |
554 | |
621 | |
555 | void |
622 | void |
556 | aio_unlink(pathname,callback) |
623 | aio_unlink(pathname,callback=&PL_sv_undef) |
557 | SV * pathname |
624 | SV * pathname |
558 | SV * callback |
625 | SV * callback |
559 | PROTOTYPE: $$ |
|
|
560 | CODE: |
626 | CODE: |
561 | { |
627 | { |
562 | aio_req req; |
628 | aio_req req; |
563 | |
629 | |
564 | Newz (0, req, 1, aio_cb); |
630 | Newz (0, req, 1, aio_cb); |
… | |
… | |
582 | { |
648 | { |
583 | poll_wait (); |
649 | poll_wait (); |
584 | poll_cb (); |
650 | poll_cb (); |
585 | } |
651 | } |
586 | |
652 | |
|
|
653 | void |
|
|
654 | poll() |
|
|
655 | PROTOTYPE: |
|
|
656 | CODE: |
|
|
657 | if (nreqs) |
|
|
658 | { |
|
|
659 | poll_wait (); |
|
|
660 | poll_cb (); |
|
|
661 | } |
|
|
662 | |
587 | int |
663 | int |
588 | poll_fileno() |
664 | poll_fileno() |
589 | PROTOTYPE: |
665 | PROTOTYPE: |
590 | CODE: |
666 | CODE: |
591 | RETVAL = respipe [0]; |
667 | RETVAL = respipe [0]; |