|
|
1 | #define _REENTRANT 1 |
|
|
2 | #include <errno.h> |
|
|
3 | |
1 | #include "EXTERN.h" |
4 | #include "EXTERN.h" |
2 | #include "perl.h" |
5 | #include "perl.h" |
3 | #include "XSUB.h" |
6 | #include "XSUB.h" |
4 | |
7 | |
5 | #define _XOPEN_SOURCE 500 |
8 | #include "autoconf/config.h" |
6 | |
9 | |
|
|
10 | #include <pthread.h> |
|
|
11 | |
|
|
12 | #include <stddef.h> |
7 | #include <sys/types.h> |
13 | #include <sys/types.h> |
8 | #include <sys/stat.h> |
14 | #include <sys/stat.h> |
9 | |
15 | #include <limits.h> |
10 | #include <unistd.h> |
16 | #include <unistd.h> |
11 | #include <fcntl.h> |
17 | #include <fcntl.h> |
12 | #include <signal.h> |
18 | #include <signal.h> |
13 | #include <sched.h> |
19 | #include <sched.h> |
|
|
20 | |
|
|
21 | #if HAVE_SENDFILE |
14 | #if __linux |
22 | # if __linux |
|
|
23 | # include <sys/sendfile.h> |
|
|
24 | # elif __freebsd |
15 | #include <sys/syscall.h> |
25 | # include <sys/socket.h> |
|
|
26 | # include <sys/uio.h> |
|
|
27 | # elif __hpux |
|
|
28 | # include <sys/socket.h> |
|
|
29 | # elif __solaris /* not yet */ |
|
|
30 | # include <sys/sendfile.h> |
|
|
31 | # else |
|
|
32 | # error sendfile support requested but not available |
16 | #endif |
33 | # endif |
|
|
34 | #endif |
17 | |
35 | |
18 | #include <pthread.h> |
36 | /* used for struct dirent, AIX doesn't provide it */ |
19 | |
37 | #ifndef NAME_MAX |
20 | typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
38 | # define NAME_MAX 4096 |
21 | typedef void *OutputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
39 | #endif |
22 | typedef void *InOutStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
|
|
23 | |
40 | |
24 | #if __ia64 |
41 | #if __ia64 |
25 | # define STACKSIZE 65536 |
42 | # define STACKSIZE 65536 |
26 | #else |
43 | #else |
27 | # define STACKSIZE 4096 |
44 | # define STACKSIZE 8192 |
28 | #endif |
45 | #endif |
29 | |
46 | |
30 | enum { |
47 | enum { |
31 | REQ_QUIT, |
48 | REQ_QUIT, |
32 | REQ_OPEN, REQ_CLOSE, |
49 | REQ_OPEN, REQ_CLOSE, |
33 | REQ_READ, REQ_WRITE, REQ_READAHEAD, |
50 | REQ_READ, REQ_WRITE, REQ_READAHEAD, |
|
|
51 | REQ_SENDFILE, |
34 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, REQ_UNLINK, |
52 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, |
35 | REQ_FSYNC, REQ_FDATASYNC, |
53 | REQ_FSYNC, REQ_FDATASYNC, |
|
|
54 | REQ_UNLINK, REQ_RMDIR, |
|
|
55 | REQ_READDIR, |
|
|
56 | REQ_SYMLINK, |
36 | }; |
57 | }; |
37 | |
58 | |
38 | typedef struct aio_cb { |
59 | typedef struct aio_cb { |
39 | struct aio_cb *volatile next; |
60 | struct aio_cb *volatile next; |
40 | |
61 | |
41 | int type; |
62 | int type; |
42 | |
63 | |
|
|
64 | /* should receive a cleanup, with unions */ |
43 | int fd; |
65 | int fd, fd2; |
44 | off_t offset; |
66 | off_t offset; |
45 | size_t length; |
67 | size_t length; |
46 | ssize_t result; |
68 | ssize_t result; |
47 | mode_t mode; /* open */ |
69 | mode_t mode; /* open */ |
48 | int errorno; |
70 | int errorno; |
49 | SV *data, *callback; |
71 | SV *data, *callback; |
50 | void *dataptr; |
72 | SV *fh, *fh2; |
|
|
73 | void *dataptr, *data2ptr; |
51 | STRLEN dataoffset; |
74 | STRLEN dataoffset; |
52 | |
75 | |
53 | Stat_t *statdata; |
76 | Stat_t *statdata; |
54 | } aio_cb; |
77 | } aio_cb; |
55 | |
78 | |
56 | typedef aio_cb *aio_req; |
79 | typedef aio_cb *aio_req; |
57 | |
80 | |
58 | static int started; |
81 | static int started, wanted; |
59 | static int nreqs; |
82 | static volatile int nreqs; |
60 | static int max_outstanding = 1<<30; |
83 | static int max_outstanding = 1<<30; |
61 | static int respipe [2]; |
84 | static int respipe [2]; |
62 | |
85 | |
63 | static pthread_mutex_t reslock = PTHREAD_MUTEX_INITIALIZER; |
86 | static pthread_mutex_t reslock = PTHREAD_MUTEX_INITIALIZER; |
64 | static pthread_mutex_t reqlock = PTHREAD_MUTEX_INITIALIZER; |
87 | static pthread_mutex_t reqlock = PTHREAD_MUTEX_INITIALIZER; |
65 | static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; |
88 | static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; |
66 | |
89 | |
67 | static volatile aio_req reqs, reqe; /* queue start, queue end */ |
90 | static volatile aio_req reqs, reqe; /* queue start, queue end */ |
68 | static volatile aio_req ress, rese; /* queue start, queue end */ |
91 | static volatile aio_req ress, rese; /* queue start, queue end */ |
69 | |
92 | |
|
|
93 | static void free_req (aio_req req) |
|
|
94 | { |
|
|
95 | if (req->data) |
|
|
96 | SvREFCNT_dec (req->data); |
|
|
97 | |
|
|
98 | if (req->fh) |
|
|
99 | SvREFCNT_dec (req->fh); |
|
|
100 | |
|
|
101 | if (req->fh2) |
|
|
102 | SvREFCNT_dec (req->fh2); |
|
|
103 | |
|
|
104 | if (req->statdata) |
|
|
105 | Safefree (req->statdata); |
|
|
106 | |
|
|
107 | if (req->callback) |
|
|
108 | SvREFCNT_dec (req->callback); |
|
|
109 | |
|
|
110 | if (req->type == REQ_READDIR && req->result >= 0) |
|
|
111 | free (req->data2ptr); |
|
|
112 | |
|
|
113 | Safefree (req); |
|
|
114 | } |
|
|
115 | |
70 | static void |
116 | static void |
71 | poll_wait () |
117 | poll_wait () |
72 | { |
118 | { |
73 | if (!nreqs) |
119 | if (nreqs && !ress) |
74 | return; |
120 | { |
75 | |
|
|
76 | fd_set rfd; |
121 | fd_set rfd; |
77 | FD_ZERO(&rfd); |
122 | FD_ZERO(&rfd); |
78 | FD_SET(respipe [0], &rfd); |
123 | FD_SET(respipe [0], &rfd); |
79 | |
124 | |
80 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
125 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
|
|
126 | } |
81 | } |
127 | } |
82 | |
128 | |
83 | static int |
129 | static int |
84 | poll_cb () |
130 | poll_cb () |
85 | { |
131 | { |
86 | dSP; |
132 | dSP; |
87 | int count = 0; |
133 | int count = 0; |
|
|
134 | int do_croak = 0; |
88 | aio_req req; |
135 | aio_req req; |
89 | |
|
|
90 | { |
|
|
91 | /* read and signals sent by the worker threads */ |
|
|
92 | char buf [32]; |
|
|
93 | while (read (respipe [0], buf, 32) > 0) |
|
|
94 | ; |
|
|
95 | } |
|
|
96 | |
136 | |
97 | for (;;) |
137 | for (;;) |
98 | { |
138 | { |
99 | pthread_mutex_lock (&reslock); |
139 | pthread_mutex_lock (&reslock); |
100 | |
|
|
101 | req = ress; |
140 | req = ress; |
102 | |
141 | |
103 | if (ress) |
142 | if (req) |
104 | { |
143 | { |
105 | ress = ress->next; |
144 | ress = req->next; |
|
|
145 | |
106 | if (!ress) rese = 0; |
146 | if (!ress) |
|
|
147 | { |
|
|
148 | /* read any signals sent by the worker threads */ |
|
|
149 | char buf [32]; |
|
|
150 | while (read (respipe [0], buf, 32) == 32) |
|
|
151 | ; |
|
|
152 | |
|
|
153 | rese = 0; |
|
|
154 | } |
107 | } |
155 | } |
108 | |
156 | |
109 | pthread_mutex_unlock (&reslock); |
157 | pthread_mutex_unlock (&reslock); |
110 | |
158 | |
111 | if (!req) |
159 | if (!req) |
… | |
… | |
119 | { |
167 | { |
120 | int errorno = errno; |
168 | int errorno = errno; |
121 | errno = req->errorno; |
169 | errno = req->errorno; |
122 | |
170 | |
123 | if (req->type == REQ_READ) |
171 | if (req->type == REQ_READ) |
124 | SvCUR_set (req->data, req->dataoffset |
172 | SvCUR_set (req->data, req->dataoffset + (req->result > 0 ? req->result : 0)); |
125 | + req->result > 0 ? req->result : 0); |
|
|
126 | |
173 | |
|
|
174 | if (req->data2ptr && (req->type == REQ_READ || req->type == REQ_WRITE)) |
|
|
175 | SvREADONLY_off (req->data); |
|
|
176 | |
127 | if (req->data) |
177 | if (req->statdata) |
128 | SvREFCNT_dec (req->data); |
|
|
129 | |
|
|
130 | if (req->type == REQ_STAT || req->type == REQ_LSTAT || req->type == REQ_FSTAT) |
|
|
131 | { |
178 | { |
132 | PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT; |
179 | PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT; |
133 | PL_laststatval = req->result; |
180 | PL_laststatval = req->result; |
134 | PL_statcache = *(req->statdata); |
181 | PL_statcache = *(req->statdata); |
135 | |
|
|
136 | Safefree (req->statdata); |
|
|
137 | } |
182 | } |
138 | |
183 | |
|
|
184 | ENTER; |
139 | PUSHMARK (SP); |
185 | PUSHMARK (SP); |
140 | XPUSHs (sv_2mortal (newSViv (req->result))); |
|
|
141 | |
186 | |
142 | if (req->type == REQ_OPEN) |
187 | if (req->type == REQ_READDIR) |
143 | { |
188 | { |
|
|
189 | SV *rv = &PL_sv_undef; |
|
|
190 | |
|
|
191 | if (req->result >= 0) |
|
|
192 | { |
|
|
193 | char *buf = req->data2ptr; |
|
|
194 | AV *av = newAV (); |
|
|
195 | |
|
|
196 | while (req->result) |
|
|
197 | { |
|
|
198 | SV *sv = newSVpv (buf, 0); |
|
|
199 | |
|
|
200 | av_push (av, sv); |
|
|
201 | buf += SvCUR (sv) + 1; |
|
|
202 | req->result--; |
|
|
203 | } |
|
|
204 | |
|
|
205 | rv = sv_2mortal (newRV_noinc ((SV *)av)); |
|
|
206 | } |
|
|
207 | |
|
|
208 | XPUSHs (rv); |
|
|
209 | } |
|
|
210 | else |
|
|
211 | { |
|
|
212 | XPUSHs (sv_2mortal (newSViv (req->result))); |
|
|
213 | |
|
|
214 | if (req->type == REQ_OPEN) |
|
|
215 | { |
144 | /* convert fd to fh */ |
216 | /* convert fd to fh */ |
145 | SV *fh; |
217 | SV *fh; |
146 | |
218 | |
147 | PUTBACK; |
219 | PUTBACK; |
148 | call_pv ("IO::AIO::_fd2fh", G_SCALAR | G_EVAL); |
220 | call_pv ("IO::AIO::_fd2fh", G_SCALAR | G_EVAL); |
149 | SPAGAIN; |
221 | SPAGAIN; |
150 | |
222 | |
151 | fh = POPs; |
223 | fh = SvREFCNT_inc (POPs); |
152 | |
224 | |
153 | PUSHMARK (SP); |
225 | PUSHMARK (SP); |
154 | XPUSHs (fh); |
226 | XPUSHs (sv_2mortal (fh)); |
|
|
227 | } |
155 | } |
228 | } |
156 | |
229 | |
157 | if (SvOK (req->callback)) |
230 | if (SvOK (req->callback)) |
158 | { |
231 | { |
159 | PUTBACK; |
232 | PUTBACK; |
160 | call_sv (req->callback, G_VOID | G_EVAL); |
233 | call_sv (req->callback, G_VOID | G_EVAL); |
161 | SPAGAIN; |
234 | SPAGAIN; |
|
|
235 | |
|
|
236 | if (SvTRUE (ERRSV)) |
|
|
237 | { |
|
|
238 | free_req (req); |
|
|
239 | croak (0); |
|
|
240 | } |
162 | } |
241 | } |
|
|
242 | |
163 | |
243 | LEAVE; |
164 | if (req->callback) |
|
|
165 | SvREFCNT_dec (req->callback); |
|
|
166 | |
244 | |
167 | errno = errorno; |
245 | errno = errorno; |
168 | count++; |
246 | count++; |
169 | } |
247 | } |
170 | |
248 | |
171 | Safefree (req); |
249 | free_req (req); |
172 | } |
250 | } |
173 | |
251 | |
174 | return count; |
252 | return count; |
175 | } |
253 | } |
176 | |
254 | |
… | |
… | |
197 | } |
275 | } |
198 | |
276 | |
199 | static void |
277 | static void |
200 | send_req (aio_req req) |
278 | send_req (aio_req req) |
201 | { |
279 | { |
|
|
280 | while (started < wanted && nreqs >= started) |
|
|
281 | start_thread (); |
|
|
282 | |
202 | nreqs++; |
283 | nreqs++; |
203 | |
284 | |
204 | pthread_mutex_lock (&reqlock); |
285 | pthread_mutex_lock (&reqlock); |
205 | |
286 | |
206 | req->next = 0; |
287 | req->next = 0; |
… | |
… | |
214 | reqe = reqs = req; |
295 | reqe = reqs = req; |
215 | |
296 | |
216 | pthread_cond_signal (&reqwait); |
297 | pthread_cond_signal (&reqwait); |
217 | pthread_mutex_unlock (&reqlock); |
298 | pthread_mutex_unlock (&reqlock); |
218 | |
299 | |
219 | while (nreqs > max_outstanding) |
300 | if (nreqs > max_outstanding) |
|
|
301 | for (;;) |
|
|
302 | { |
|
|
303 | poll_cb (); |
|
|
304 | |
|
|
305 | if (nreqs <= max_outstanding) |
|
|
306 | break; |
|
|
307 | |
|
|
308 | poll_wait (); |
|
|
309 | } |
|
|
310 | } |
|
|
311 | |
|
|
312 | static void |
|
|
313 | end_thread (void) |
|
|
314 | { |
|
|
315 | aio_req req; |
|
|
316 | Newz (0, req, 1, aio_cb); |
|
|
317 | req->type = REQ_QUIT; |
|
|
318 | |
|
|
319 | send_req (req); |
|
|
320 | } |
|
|
321 | |
|
|
322 | static void min_parallel (int nthreads) |
|
|
323 | { |
|
|
324 | if (wanted < nthreads) |
|
|
325 | wanted = nthreads; |
|
|
326 | } |
|
|
327 | |
|
|
328 | static void max_parallel (int nthreads) |
|
|
329 | { |
|
|
330 | int cur = started; |
|
|
331 | |
|
|
332 | if (wanted > nthreads) |
|
|
333 | wanted = nthreads; |
|
|
334 | |
|
|
335 | while (cur > wanted) |
|
|
336 | { |
|
|
337 | end_thread (); |
|
|
338 | cur--; |
|
|
339 | } |
|
|
340 | |
|
|
341 | while (started > wanted) |
220 | { |
342 | { |
221 | poll_wait (); |
343 | poll_wait (); |
222 | poll_cb (); |
344 | poll_cb (); |
223 | } |
345 | } |
224 | } |
346 | } |
225 | |
347 | |
226 | static void |
348 | static void create_pipe () |
227 | end_thread (void) |
|
|
228 | { |
349 | { |
229 | aio_req req; |
350 | if (pipe (respipe)) |
230 | New (0, req, 1, aio_cb); |
351 | croak ("unable to initialize result pipe"); |
231 | req->type = REQ_QUIT; |
|
|
232 | |
352 | |
233 | send_req (req); |
353 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK)) |
234 | } |
354 | croak ("cannot set result pipe to nonblocking mode"); |
235 | |
355 | |
236 | static void |
356 | if (fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
237 | read_write (int dowrite, int fd, off_t offset, size_t length, |
357 | croak ("cannot set result pipe to nonblocking mode"); |
238 | SV *data, STRLEN dataoffset, SV *callback) |
358 | } |
239 | { |
|
|
240 | aio_req req; |
|
|
241 | STRLEN svlen; |
|
|
242 | char *svptr = SvPV (data, svlen); |
|
|
243 | |
359 | |
244 | SvUPGRADE (data, SVt_PV); |
360 | /*****************************************************************************/ |
245 | SvPOK_on (data); |
361 | /* work around various missing functions */ |
246 | |
362 | |
247 | if (dataoffset < 0) |
363 | #if !HAVE_PREADWRITE |
|
|
364 | # define pread aio_pread |
|
|
365 | # define pwrite aio_pwrite |
|
|
366 | |
|
|
367 | /* |
|
|
368 | * make our pread/pwrite safe against themselves, but not against |
|
|
369 | * normal read/write by using a mutex. slows down execution a lot, |
|
|
370 | * but that's your problem, not mine. |
|
|
371 | */ |
|
|
372 | static pthread_mutex_t preadwritelock = PTHREAD_MUTEX_INITIALIZER; |
|
|
373 | |
|
|
374 | static ssize_t |
|
|
375 | pread (int fd, void *buf, size_t count, off_t offset) |
|
|
376 | { |
|
|
377 | ssize_t res; |
|
|
378 | off_t ooffset; |
|
|
379 | |
|
|
380 | pthread_mutex_lock (&preadwritelock); |
|
|
381 | ooffset = lseek (fd, 0, SEEK_CUR); |
|
|
382 | lseek (fd, offset, SEEK_SET); |
|
|
383 | res = read (fd, buf, count); |
|
|
384 | lseek (fd, ooffset, SEEK_SET); |
|
|
385 | pthread_mutex_unlock (&preadwritelock); |
|
|
386 | |
|
|
387 | return res; |
|
|
388 | } |
|
|
389 | |
|
|
390 | static ssize_t |
|
|
391 | pwrite (int fd, void *buf, size_t count, off_t offset) |
|
|
392 | { |
|
|
393 | ssize_t res; |
|
|
394 | off_t ooffset; |
|
|
395 | |
|
|
396 | pthread_mutex_lock (&preadwritelock); |
|
|
397 | ooffset = lseek (fd, 0, SEEK_CUR); |
|
|
398 | lseek (fd, offset, SEEK_SET); |
|
|
399 | res = write (fd, buf, count); |
|
|
400 | lseek (fd, offset, SEEK_SET); |
|
|
401 | pthread_mutex_unlock (&preadwritelock); |
|
|
402 | |
|
|
403 | return res; |
|
|
404 | } |
|
|
405 | #endif |
|
|
406 | |
|
|
407 | #if !HAVE_FDATASYNC |
|
|
408 | # define fdatasync fsync |
|
|
409 | #endif |
|
|
410 | |
|
|
411 | #if !HAVE_READAHEAD |
|
|
412 | # define readahead aio_readahead |
|
|
413 | |
|
|
414 | static ssize_t |
|
|
415 | readahead (int fd, off_t offset, size_t count) |
|
|
416 | { |
|
|
417 | char readahead_buf[4096]; |
|
|
418 | |
|
|
419 | while (count > 0) |
|
|
420 | { |
|
|
421 | size_t len = count < sizeof (readahead_buf) ? count : sizeof (readahead_buf); |
|
|
422 | |
|
|
423 | pread (fd, readahead_buf, len, offset); |
248 | dataoffset += svlen; |
424 | offset += len; |
249 | |
425 | count -= len; |
250 | if (dataoffset < 0 || dataoffset > svlen) |
|
|
251 | croak ("data offset outside of string"); |
|
|
252 | |
|
|
253 | if (dowrite) |
|
|
254 | { |
426 | } |
255 | /* write: check length and adjust. */ |
427 | |
256 | if (length < 0 || length + dataoffset > svlen) |
428 | errno = 0; |
257 | length = svlen - dataoffset; |
429 | } |
|
|
430 | #endif |
|
|
431 | |
|
|
432 | #if !HAVE_READDIR_R |
|
|
433 | # define readdir_r aio_readdir_r |
|
|
434 | |
|
|
435 | static pthread_mutex_t readdirlock = PTHREAD_MUTEX_INITIALIZER; |
|
|
436 | |
|
|
437 | static int |
|
|
438 | readdir_r (DIR *dirp, struct dirent *ent, struct dirent **res) |
|
|
439 | { |
|
|
440 | struct dirent *e; |
|
|
441 | int errorno; |
|
|
442 | |
|
|
443 | pthread_mutex_lock (&readdirlock); |
|
|
444 | |
|
|
445 | e = readdir (dirp); |
|
|
446 | errorno = errno; |
|
|
447 | |
|
|
448 | if (e) |
|
|
449 | { |
|
|
450 | *res = ent; |
|
|
451 | strcpy (ent->d_name, e->d_name); |
258 | } |
452 | } |
259 | else |
453 | else |
|
|
454 | *res = 0; |
|
|
455 | |
|
|
456 | pthread_mutex_unlock (&readdirlock); |
|
|
457 | |
|
|
458 | errno = errorno; |
|
|
459 | return e ? 0 : -1; |
|
|
460 | } |
|
|
461 | #endif |
|
|
462 | |
|
|
463 | /* sendfile always needs emulation */ |
|
|
464 | static ssize_t |
|
|
465 | sendfile_ (int ofd, int ifd, off_t offset, size_t count) |
|
|
466 | { |
|
|
467 | ssize_t res; |
|
|
468 | |
|
|
469 | if (!count) |
|
|
470 | return 0; |
|
|
471 | |
|
|
472 | #if HAVE_SENDFILE |
|
|
473 | # if __linux |
|
|
474 | res = sendfile (ofd, ifd, &offset, count); |
|
|
475 | |
|
|
476 | # elif __freebsd |
|
|
477 | /* |
|
|
478 | * Of course, the freebsd sendfile is a dire hack with no thoughts |
|
|
479 | * wasted on making it similar to other I/O functions. |
|
|
480 | */ |
260 | { |
481 | { |
261 | /* read: grow scalar as necessary */ |
482 | off_t sbytes; |
262 | svptr = SvGROW (data, length + dataoffset); |
483 | res = sendfile (ifd, ofd, offset, count, 0, &sbytes, 0); |
|
|
484 | |
|
|
485 | if (res < 0 && sbytes) |
|
|
486 | /* maybe only on EAGAIN only: as usual, the manpage leaves you guessing */ |
|
|
487 | res = sbytes; |
|
|
488 | } |
|
|
489 | |
|
|
490 | # elif __hpux |
|
|
491 | res = sendfile (ofd, ifd, offset, count, 0, 0); |
|
|
492 | |
|
|
493 | # elif __solaris |
|
|
494 | { |
|
|
495 | struct sendfilevec vec; |
|
|
496 | size_t sbytes; |
|
|
497 | |
|
|
498 | vec.sfv_fd = ifd; |
|
|
499 | vec.sfv_flag = 0; |
|
|
500 | vec.sfv_off = offset; |
|
|
501 | vec.sfv_len = count; |
|
|
502 | |
|
|
503 | res = sendfilev (ofd, &vec, 1, &sbytes); |
|
|
504 | |
|
|
505 | if (res < 0 && sbytes) |
|
|
506 | res = sbytes; |
|
|
507 | } |
|
|
508 | |
|
|
509 | # endif |
|
|
510 | #else |
|
|
511 | res = -1; |
|
|
512 | errno = ENOSYS; |
|
|
513 | #endif |
|
|
514 | |
|
|
515 | if (res < 0 |
|
|
516 | && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK |
|
|
517 | #if __solaris |
|
|
518 | || errno == EAFNOSUPPORT || errno == EPROTOTYPE |
|
|
519 | #endif |
|
|
520 | ) |
|
|
521 | ) |
263 | } |
522 | { |
|
|
523 | /* emulate sendfile. this is a major pain in the ass */ |
|
|
524 | char buf[4096]; |
|
|
525 | res = 0; |
264 | |
526 | |
265 | if (length < 0) |
527 | while (count) |
266 | croak ("length must not be negative"); |
528 | { |
|
|
529 | ssize_t cnt; |
|
|
530 | |
|
|
531 | cnt = pread (ifd, buf, count > 4096 ? 4096 : count, offset); |
267 | |
532 | |
268 | Newz (0, req, 1, aio_cb); |
533 | if (cnt <= 0) |
|
|
534 | { |
|
|
535 | if (cnt && !res) res = -1; |
|
|
536 | break; |
|
|
537 | } |
269 | |
538 | |
|
|
539 | cnt = write (ofd, buf, cnt); |
|
|
540 | |
|
|
541 | if (cnt <= 0) |
|
|
542 | { |
|
|
543 | if (cnt && !res) res = -1; |
|
|
544 | break; |
|
|
545 | } |
|
|
546 | |
|
|
547 | offset += cnt; |
|
|
548 | res += cnt; |
|
|
549 | count -= cnt; |
|
|
550 | } |
|
|
551 | } |
|
|
552 | |
|
|
553 | return res; |
|
|
554 | } |
|
|
555 | |
|
|
556 | /* read a full directory */ |
|
|
557 | static int |
|
|
558 | scandir_ (const char *path, void **namesp) |
|
|
559 | { |
|
|
560 | DIR *dirp = opendir (path); |
|
|
561 | union |
|
|
562 | { |
|
|
563 | struct dirent d; |
|
|
564 | char b [offsetof (struct dirent, d_name) + NAME_MAX + 1]; |
|
|
565 | } u; |
|
|
566 | struct dirent *entp; |
|
|
567 | char *name, *names; |
|
|
568 | int memlen = 4096; |
|
|
569 | int memofs = 0; |
|
|
570 | int res = 0; |
|
|
571 | int errorno; |
|
|
572 | |
270 | if (!req) |
573 | if (!dirp) |
271 | croak ("out of memory during aio_req allocation"); |
574 | return -1; |
272 | |
575 | |
273 | req->type = dowrite ? REQ_WRITE : REQ_READ; |
576 | names = malloc (memlen); |
274 | req->fd = fd; |
|
|
275 | req->offset = offset; |
|
|
276 | req->length = length; |
|
|
277 | req->data = SvREFCNT_inc (data); |
|
|
278 | req->dataptr = (char *)svptr + dataoffset; |
|
|
279 | req->callback = SvREFCNT_inc (callback); |
|
|
280 | |
577 | |
281 | send_req (req); |
578 | for (;;) |
|
|
579 | { |
|
|
580 | errno = 0, readdir_r (dirp, &u.d, &entp); |
|
|
581 | |
|
|
582 | if (!entp) |
|
|
583 | break; |
|
|
584 | |
|
|
585 | name = entp->d_name; |
|
|
586 | |
|
|
587 | if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2]))) |
|
|
588 | { |
|
|
589 | int len = strlen (name) + 1; |
|
|
590 | |
|
|
591 | res++; |
|
|
592 | |
|
|
593 | while (memofs + len > memlen) |
|
|
594 | { |
|
|
595 | memlen *= 2; |
|
|
596 | names = realloc (names, memlen); |
|
|
597 | if (!names) |
|
|
598 | break; |
|
|
599 | } |
|
|
600 | |
|
|
601 | memcpy (names + memofs, name, len); |
|
|
602 | memofs += len; |
|
|
603 | } |
|
|
604 | } |
|
|
605 | |
|
|
606 | errorno = errno; |
|
|
607 | closedir (dirp); |
|
|
608 | |
|
|
609 | if (errorno) |
|
|
610 | { |
|
|
611 | free (names); |
|
|
612 | errno = errorno; |
|
|
613 | res = -1; |
|
|
614 | } |
|
|
615 | |
|
|
616 | *namesp = (void *)names; |
|
|
617 | return res; |
282 | } |
618 | } |
|
|
619 | |
|
|
620 | /*****************************************************************************/ |
283 | |
621 | |
284 | static void * |
622 | static void * |
285 | aio_proc (void *thr_arg) |
623 | aio_proc (void *thr_arg) |
286 | { |
624 | { |
287 | aio_req req; |
625 | aio_req req; |
… | |
… | |
315 | |
653 | |
316 | switch (type) |
654 | switch (type) |
317 | { |
655 | { |
318 | case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; |
656 | case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; |
319 | case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; |
657 | case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; |
320 | #if SYS_readahead |
658 | |
321 | case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; |
659 | case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; |
322 | #else |
660 | case REQ_SENDFILE: req->result = sendfile_ (req->fd, req->fd2, req->offset, req->length); break; |
323 | case REQ_READAHEAD: req->result = -1; errno = ENOSYS; break; |
|
|
324 | #endif |
|
|
325 | |
661 | |
326 | case REQ_STAT: req->result = stat (req->dataptr, req->statdata); break; |
662 | case REQ_STAT: req->result = stat (req->dataptr, req->statdata); break; |
327 | case REQ_LSTAT: req->result = lstat (req->dataptr, req->statdata); break; |
663 | case REQ_LSTAT: req->result = lstat (req->dataptr, req->statdata); break; |
328 | case REQ_FSTAT: req->result = fstat (req->fd , req->statdata); break; |
664 | case REQ_FSTAT: req->result = fstat (req->fd , req->statdata); break; |
329 | |
665 | |
330 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |
666 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |
331 | case REQ_CLOSE: req->result = close (req->fd); break; |
667 | case REQ_CLOSE: req->result = close (req->fd); break; |
332 | case REQ_UNLINK: req->result = unlink (req->dataptr); break; |
668 | case REQ_UNLINK: req->result = unlink (req->dataptr); break; |
|
|
669 | case REQ_RMDIR: req->result = rmdir (req->dataptr); break; |
|
|
670 | case REQ_SYMLINK: req->result = symlink (req->data2ptr, req->dataptr); break; |
333 | |
671 | |
|
|
672 | case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; |
334 | case REQ_FSYNC: req->result = fsync (req->fd); break; |
673 | case REQ_FSYNC: req->result = fsync (req->fd); break; |
335 | case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; |
674 | case REQ_READDIR: req->result = scandir_ (req->dataptr, &req->data2ptr); break; |
336 | |
675 | |
337 | case REQ_QUIT: |
676 | case REQ_QUIT: |
338 | break; |
677 | break; |
339 | |
678 | |
340 | default: |
679 | default: |
… | |
… | |
366 | while (type != REQ_QUIT); |
705 | while (type != REQ_QUIT); |
367 | |
706 | |
368 | return 0; |
707 | return 0; |
369 | } |
708 | } |
370 | |
709 | |
|
|
710 | /*****************************************************************************/ |
|
|
711 | |
|
|
712 | static void atfork_prepare (void) |
|
|
713 | { |
|
|
714 | pthread_mutex_lock (&reqlock); |
|
|
715 | pthread_mutex_lock (&reslock); |
|
|
716 | #if !HAVE_PREADWRITE |
|
|
717 | pthread_mutex_lock (&preadwritelock); |
|
|
718 | #endif |
|
|
719 | #if !HAVE_READDIR_R |
|
|
720 | pthread_mutex_lock (&readdirlock); |
|
|
721 | #endif |
|
|
722 | } |
|
|
723 | |
|
|
724 | static void atfork_parent (void) |
|
|
725 | { |
|
|
726 | #if !HAVE_READDIR_R |
|
|
727 | pthread_mutex_unlock (&readdirlock); |
|
|
728 | #endif |
|
|
729 | #if !HAVE_PREADWRITE |
|
|
730 | pthread_mutex_unlock (&preadwritelock); |
|
|
731 | #endif |
|
|
732 | pthread_mutex_unlock (&reslock); |
|
|
733 | pthread_mutex_unlock (&reqlock); |
|
|
734 | } |
|
|
735 | |
|
|
736 | static void atfork_child (void) |
|
|
737 | { |
|
|
738 | aio_req prv; |
|
|
739 | |
|
|
740 | started = 0; |
|
|
741 | |
|
|
742 | while (reqs) |
|
|
743 | { |
|
|
744 | prv = reqs; |
|
|
745 | reqs = prv->next; |
|
|
746 | free_req (prv); |
|
|
747 | } |
|
|
748 | |
|
|
749 | reqs = reqe = 0; |
|
|
750 | |
|
|
751 | while (ress) |
|
|
752 | { |
|
|
753 | prv = ress; |
|
|
754 | ress = prv->next; |
|
|
755 | free_req (prv); |
|
|
756 | } |
|
|
757 | |
|
|
758 | ress = rese = 0; |
|
|
759 | |
|
|
760 | close (respipe [0]); |
|
|
761 | close (respipe [1]); |
|
|
762 | create_pipe (); |
|
|
763 | |
|
|
764 | atfork_parent (); |
|
|
765 | } |
|
|
766 | |
|
|
767 | #define dREQ \ |
|
|
768 | aio_req req; \ |
|
|
769 | \ |
|
|
770 | if (SvOK (callback) && !SvROK (callback)) \ |
|
|
771 | croak ("clalback must be undef or of reference type"); \ |
|
|
772 | \ |
|
|
773 | Newz (0, req, 1, aio_cb); \ |
|
|
774 | if (!req) \ |
|
|
775 | croak ("out of memory during aio_req allocation"); \ |
|
|
776 | \ |
|
|
777 | req->callback = newSVsv (callback); |
|
|
778 | |
371 | MODULE = IO::AIO PACKAGE = IO::AIO |
779 | MODULE = IO::AIO PACKAGE = IO::AIO |
372 | |
780 | |
373 | PROTOTYPES: ENABLE |
781 | PROTOTYPES: ENABLE |
374 | |
782 | |
375 | BOOT: |
783 | BOOT: |
376 | { |
784 | { |
377 | if (pipe (respipe)) |
785 | create_pipe (); |
378 | croak ("unable to initialize result pipe"); |
786 | pthread_atfork (atfork_prepare, atfork_parent, atfork_child); |
379 | |
|
|
380 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK)) |
|
|
381 | croak ("cannot set result pipe to nonblocking mode"); |
|
|
382 | |
|
|
383 | if (fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
|
|
384 | croak ("cannot set result pipe to nonblocking mode"); |
|
|
385 | } |
787 | } |
386 | |
788 | |
387 | void |
789 | void |
388 | min_parallel(nthreads) |
790 | min_parallel(nthreads) |
389 | int nthreads |
791 | int nthreads |
390 | PROTOTYPE: $ |
792 | PROTOTYPE: $ |
391 | CODE: |
|
|
392 | while (nthreads > started) |
|
|
393 | start_thread (); |
|
|
394 | |
793 | |
395 | void |
794 | void |
396 | max_parallel(nthreads) |
795 | max_parallel(nthreads) |
397 | int nthreads |
796 | int nthreads |
398 | PROTOTYPE: $ |
797 | PROTOTYPE: $ |
399 | CODE: |
|
|
400 | { |
|
|
401 | int cur = started; |
|
|
402 | while (cur > nthreads) |
|
|
403 | { |
|
|
404 | end_thread (); |
|
|
405 | cur--; |
|
|
406 | } |
|
|
407 | |
|
|
408 | while (started > nthreads) |
|
|
409 | { |
|
|
410 | poll_wait (); |
|
|
411 | poll_cb (); |
|
|
412 | } |
|
|
413 | } |
|
|
414 | |
798 | |
415 | int |
799 | int |
416 | max_outstanding(nreqs) |
800 | max_outstanding(nreqs) |
417 | int nreqs |
801 | int nreqs |
418 | PROTOTYPE: $ |
802 | PROTOTYPE: $ |
… | |
… | |
427 | int mode |
811 | int mode |
428 | SV * callback |
812 | SV * callback |
429 | PROTOTYPE: $$$;$ |
813 | PROTOTYPE: $$$;$ |
430 | CODE: |
814 | CODE: |
431 | { |
815 | { |
432 | aio_req req; |
816 | dREQ; |
433 | |
|
|
434 | Newz (0, req, 1, aio_cb); |
|
|
435 | |
|
|
436 | if (!req) |
|
|
437 | croak ("out of memory during aio_req allocation"); |
|
|
438 | |
817 | |
439 | req->type = REQ_OPEN; |
818 | req->type = REQ_OPEN; |
440 | req->data = newSVsv (pathname); |
819 | req->data = newSVsv (pathname); |
441 | req->dataptr = SvPV_nolen (req->data); |
820 | req->dataptr = SvPVbyte_nolen (req->data); |
442 | req->fd = flags; |
821 | req->fd = flags; |
443 | req->mode = mode; |
822 | req->mode = mode; |
444 | req->callback = SvREFCNT_inc (callback); |
|
|
445 | |
823 | |
446 | send_req (req); |
824 | send_req (req); |
447 | } |
825 | } |
448 | |
826 | |
449 | void |
827 | void |
450 | aio_close(fh,callback=&PL_sv_undef) |
828 | aio_close(fh,callback=&PL_sv_undef) |
451 | InputStream fh |
829 | SV * fh |
452 | SV * callback |
830 | SV * callback |
453 | PROTOTYPE: $;$ |
831 | PROTOTYPE: $;$ |
454 | ALIAS: |
832 | ALIAS: |
455 | aio_close = REQ_CLOSE |
833 | aio_close = REQ_CLOSE |
456 | aio_fsync = REQ_FSYNC |
834 | aio_fsync = REQ_FSYNC |
457 | aio_fdatasync = REQ_FDATASYNC |
835 | aio_fdatasync = REQ_FDATASYNC |
458 | CODE: |
836 | CODE: |
459 | { |
837 | { |
460 | aio_req req; |
838 | dREQ; |
461 | |
|
|
462 | Newz (0, req, 1, aio_cb); |
|
|
463 | |
|
|
464 | if (!req) |
|
|
465 | croak ("out of memory during aio_req allocation"); |
|
|
466 | |
839 | |
467 | req->type = ix; |
840 | req->type = ix; |
|
|
841 | req->fh = newSVsv (fh); |
468 | req->fd = PerlIO_fileno (fh); |
842 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); |
469 | req->callback = SvREFCNT_inc (callback); |
|
|
470 | |
843 | |
471 | send_req (req); |
844 | send_req (req); |
472 | } |
845 | } |
473 | |
846 | |
474 | void |
847 | void |
475 | aio_read(fh,offset,length,data,dataoffset,callback=&PL_sv_undef) |
848 | aio_read(fh,offset,length,data,dataoffset,callback=&PL_sv_undef) |
476 | InputStream fh |
849 | SV * fh |
477 | UV offset |
850 | UV offset |
478 | IV length |
851 | UV length |
479 | SV * data |
852 | SV * data |
480 | IV dataoffset |
853 | UV dataoffset |
481 | SV * callback |
854 | SV * callback |
|
|
855 | ALIAS: |
|
|
856 | aio_read = REQ_READ |
|
|
857 | aio_write = REQ_WRITE |
482 | PROTOTYPE: $$$$$;$ |
858 | PROTOTYPE: $$$$$;$ |
483 | CODE: |
859 | CODE: |
484 | read_write (0, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); |
860 | { |
|
|
861 | aio_req req; |
|
|
862 | STRLEN svlen; |
|
|
863 | char *svptr = SvPVbyte (data, svlen); |
485 | |
864 | |
|
|
865 | SvUPGRADE (data, SVt_PV); |
|
|
866 | SvPOK_on (data); |
|
|
867 | |
|
|
868 | if (dataoffset < 0) |
|
|
869 | dataoffset += svlen; |
|
|
870 | |
|
|
871 | if (dataoffset < 0 || dataoffset > svlen) |
|
|
872 | croak ("data offset outside of string"); |
|
|
873 | |
|
|
874 | if (ix == REQ_WRITE) |
|
|
875 | { |
|
|
876 | /* write: check length and adjust. */ |
|
|
877 | if (length < 0 || length + dataoffset > svlen) |
|
|
878 | length = svlen - dataoffset; |
|
|
879 | } |
|
|
880 | else |
|
|
881 | { |
|
|
882 | /* read: grow scalar as necessary */ |
|
|
883 | svptr = SvGROW (data, length + dataoffset); |
|
|
884 | } |
|
|
885 | |
|
|
886 | if (length < 0) |
|
|
887 | croak ("length must not be negative"); |
|
|
888 | |
|
|
889 | { |
|
|
890 | dREQ; |
|
|
891 | |
|
|
892 | req->type = ix; |
|
|
893 | req->fh = newSVsv (fh); |
|
|
894 | req->fd = PerlIO_fileno (ix == REQ_READ ? IoIFP (sv_2io (fh)) |
|
|
895 | : IoOFP (sv_2io (fh))); |
|
|
896 | req->offset = offset; |
|
|
897 | req->length = length; |
|
|
898 | req->data = SvREFCNT_inc (data); |
|
|
899 | req->dataptr = (char *)svptr + dataoffset; |
|
|
900 | |
|
|
901 | if (!SvREADONLY (data)) |
|
|
902 | { |
|
|
903 | SvREADONLY_on (data); |
|
|
904 | req->data2ptr = (void *)data; |
|
|
905 | } |
|
|
906 | |
|
|
907 | send_req (req); |
|
|
908 | } |
|
|
909 | } |
|
|
910 | |
486 | void |
911 | void |
487 | aio_write(fh,offset,length,data,dataoffset,callback=&PL_sv_undef) |
912 | aio_sendfile(out_fh,in_fh,in_offset,length,callback=&PL_sv_undef) |
488 | OutputStream fh |
913 | SV * out_fh |
|
|
914 | SV * in_fh |
489 | UV offset |
915 | UV in_offset |
490 | IV length |
916 | UV length |
491 | SV * data |
|
|
492 | IV dataoffset |
|
|
493 | SV * callback |
917 | SV * callback |
494 | PROTOTYPE: $$$$$;$ |
918 | PROTOTYPE: $$$$;$ |
495 | CODE: |
919 | CODE: |
496 | read_write (1, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); |
920 | { |
|
|
921 | dREQ; |
|
|
922 | |
|
|
923 | req->type = REQ_SENDFILE; |
|
|
924 | req->fh = newSVsv (out_fh); |
|
|
925 | req->fd = PerlIO_fileno (IoIFP (sv_2io (out_fh))); |
|
|
926 | req->fh2 = newSVsv (in_fh); |
|
|
927 | req->fd2 = PerlIO_fileno (IoIFP (sv_2io (in_fh))); |
|
|
928 | req->offset = in_offset; |
|
|
929 | req->length = length; |
|
|
930 | |
|
|
931 | send_req (req); |
|
|
932 | } |
497 | |
933 | |
498 | void |
934 | void |
499 | aio_readahead(fh,offset,length,callback=&PL_sv_undef) |
935 | aio_readahead(fh,offset,length,callback=&PL_sv_undef) |
500 | InputStream fh |
936 | SV * fh |
501 | UV offset |
937 | UV offset |
502 | IV length |
938 | IV length |
503 | SV * callback |
939 | SV * callback |
504 | PROTOTYPE: $$$;$ |
940 | PROTOTYPE: $$$;$ |
505 | CODE: |
941 | CODE: |
506 | { |
942 | { |
507 | aio_req req; |
943 | dREQ; |
508 | |
|
|
509 | if (length < 0) |
|
|
510 | croak ("length must not be negative"); |
|
|
511 | |
|
|
512 | Newz (0, req, 1, aio_cb); |
|
|
513 | |
|
|
514 | if (!req) |
|
|
515 | croak ("out of memory during aio_req allocation"); |
|
|
516 | |
944 | |
517 | req->type = REQ_READAHEAD; |
945 | req->type = REQ_READAHEAD; |
|
|
946 | req->fh = newSVsv (fh); |
518 | req->fd = PerlIO_fileno (fh); |
947 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); |
519 | req->offset = offset; |
948 | req->offset = offset; |
520 | req->length = length; |
949 | req->length = length; |
521 | req->callback = SvREFCNT_inc (callback); |
|
|
522 | |
950 | |
523 | send_req (req); |
951 | send_req (req); |
524 | } |
952 | } |
525 | |
953 | |
526 | void |
954 | void |
… | |
… | |
530 | ALIAS: |
958 | ALIAS: |
531 | aio_stat = REQ_STAT |
959 | aio_stat = REQ_STAT |
532 | aio_lstat = REQ_LSTAT |
960 | aio_lstat = REQ_LSTAT |
533 | CODE: |
961 | CODE: |
534 | { |
962 | { |
535 | aio_req req; |
963 | dREQ; |
536 | |
|
|
537 | Newz (0, req, 1, aio_cb); |
|
|
538 | |
|
|
539 | if (!req) |
|
|
540 | croak ("out of memory during aio_req allocation"); |
|
|
541 | |
964 | |
542 | New (0, req->statdata, 1, Stat_t); |
965 | New (0, req->statdata, 1, Stat_t); |
543 | |
|
|
544 | if (!req->statdata) |
966 | if (!req->statdata) |
|
|
967 | { |
|
|
968 | free_req (req); |
545 | croak ("out of memory during aio_req->statdata allocation"); |
969 | croak ("out of memory during aio_req->statdata allocation"); |
|
|
970 | } |
546 | |
971 | |
547 | if (SvPOK (fh_or_path)) |
972 | if (SvPOK (fh_or_path)) |
548 | { |
973 | { |
549 | req->type = ix; |
974 | req->type = ix; |
550 | req->data = newSVsv (fh_or_path); |
975 | req->data = newSVsv (fh_or_path); |
551 | req->dataptr = SvPV_nolen (req->data); |
976 | req->dataptr = SvPVbyte_nolen (req->data); |
552 | } |
977 | } |
553 | else |
978 | else |
554 | { |
979 | { |
555 | req->type = REQ_FSTAT; |
980 | req->type = REQ_FSTAT; |
|
|
981 | req->fh = newSVsv (fh_or_path); |
556 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
982 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
557 | } |
983 | } |
558 | |
|
|
559 | req->callback = SvREFCNT_inc (callback); |
|
|
560 | |
984 | |
561 | send_req (req); |
985 | send_req (req); |
562 | } |
986 | } |
563 | |
987 | |
564 | void |
988 | void |
565 | aio_unlink(pathname,callback=&PL_sv_undef) |
989 | aio_unlink(pathname,callback=&PL_sv_undef) |
566 | SV * pathname |
990 | SV * pathname |
567 | SV * callback |
991 | SV * callback |
|
|
992 | ALIAS: |
|
|
993 | aio_unlink = REQ_UNLINK |
|
|
994 | aio_rmdir = REQ_RMDIR |
568 | CODE: |
995 | CODE: |
569 | { |
996 | { |
570 | aio_req req; |
997 | dREQ; |
571 | |
998 | |
572 | Newz (0, req, 1, aio_cb); |
999 | req->type = ix; |
|
|
1000 | req->data = newSVsv (pathname); |
|
|
1001 | req->dataptr = SvPVbyte_nolen (req->data); |
573 | |
1002 | |
574 | if (!req) |
1003 | send_req (req); |
575 | croak ("out of memory during aio_req allocation"); |
1004 | } |
|
|
1005 | |
|
|
1006 | void |
|
|
1007 | aio_symlink(oldpath,newpath,callback=&PL_sv_undef) |
|
|
1008 | SV * oldpath |
|
|
1009 | SV * newpath |
|
|
1010 | SV * callback |
|
|
1011 | CODE: |
|
|
1012 | { |
|
|
1013 | dREQ; |
576 | |
1014 | |
577 | req->type = REQ_UNLINK; |
1015 | req->type = REQ_SYMLINK; |
|
|
1016 | req->fh = newSVsv (oldpath); |
|
|
1017 | req->data2ptr = SvPVbyte_nolen (req->fh); |
|
|
1018 | req->data = newSVsv (newpath); |
|
|
1019 | req->dataptr = SvPVbyte_nolen (req->data); |
|
|
1020 | |
|
|
1021 | send_req (req); |
|
|
1022 | } |
|
|
1023 | |
|
|
1024 | void |
|
|
1025 | aio_readdir(pathname,callback=&PL_sv_undef) |
|
|
1026 | SV * pathname |
|
|
1027 | SV * callback |
|
|
1028 | CODE: |
|
|
1029 | { |
|
|
1030 | dREQ; |
|
|
1031 | |
|
|
1032 | req->type = REQ_READDIR; |
578 | req->data = newSVsv (pathname); |
1033 | req->data = newSVsv (pathname); |
579 | req->dataptr = SvPV_nolen (req->data); |
1034 | req->dataptr = SvPVbyte_nolen (req->data); |
580 | req->callback = SvREFCNT_inc (callback); |
|
|
581 | |
1035 | |
582 | send_req (req); |
1036 | send_req (req); |
583 | } |
1037 | } |
584 | |
1038 | |
585 | void |
1039 | void |