|
|
1 | #define PERL_NO_GET_CONTEXT |
|
|
2 | |
1 | #include "EXTERN.h" |
3 | #include "EXTERN.h" |
2 | #include "perl.h" |
4 | #include "perl.h" |
3 | #include "XSUB.h" |
5 | #include "XSUB.h" |
4 | |
6 | |
5 | #include <sys/types.h> |
7 | #include <sys/types.h> |
|
|
8 | #include <sys/stat.h> |
6 | #include <unistd.h> |
9 | #include <unistd.h> |
|
|
10 | #include <fcntl.h> |
|
|
11 | #include <signal.h> |
7 | #include <sched.h> |
12 | #include <sched.h> |
|
|
13 | #include <endian.h> |
8 | |
14 | |
9 | #define STACKSIZE 128 /* yeah */ |
15 | typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
|
|
16 | typedef void *OutputStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
|
|
17 | typedef void *InOutStream; /* hack, but 5.6.1 is simply toooo old ;) */ |
10 | |
18 | |
11 | #define REQ_QUIT 0 |
19 | #if __i386 || __amd64 |
12 | #define REQ_READ 1 |
20 | # define STACKSIZE ( 256 * sizeof (long)) |
13 | #define REQ_WRITE 2 |
21 | #elif __ia64 |
|
|
22 | # define STACKSIZE (8192 * sizeof (long)) |
|
|
23 | #else |
|
|
24 | # define STACKSIZE ( 512 * sizeof (long)) |
|
|
25 | #endif |
|
|
26 | |
|
|
27 | enum { |
|
|
28 | REQ_QUIT, |
|
|
29 | REQ_OPEN, REQ_CLOSE, |
|
|
30 | REQ_READ, REQ_WRITE, REQ_READAHEAD, |
|
|
31 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, REQ_UNLINK, |
|
|
32 | REQ_FSYNC, REQ_FDATASYNC, |
|
|
33 | }; |
14 | |
34 | |
15 | typedef struct { |
35 | typedef struct { |
16 | char stack[STACKSIZE]; |
36 | char stack[STACKSIZE]; |
17 | } aio_thread; |
37 | } aio_thread; |
18 | |
38 | |
19 | typedef struct { |
39 | typedef struct aio_cb { |
|
|
40 | struct aio_cb *next; |
|
|
41 | |
20 | int type; |
42 | int type; |
21 | aio_thread *thread; |
43 | aio_thread *thread; |
22 | |
44 | |
23 | /* read/write */ |
|
|
24 | int fd; |
45 | int fd; |
25 | off_t offset; |
46 | off_t offset; |
26 | size_t length; |
47 | size_t length; |
27 | ssize_t result; |
48 | ssize_t result; |
|
|
49 | mode_t mode; /* open */ |
28 | int errorno; |
50 | int errorno; |
29 | |
51 | SV *data, *callback; |
30 | SV *data; |
|
|
31 | void *dataptr; |
52 | void *dataptr; |
32 | STRLEN dataoffset; |
53 | STRLEN dataoffset; |
|
|
54 | |
|
|
55 | Stat_t *statdata; |
33 | } aio_cb; |
56 | } aio_cb; |
34 | |
57 | |
35 | typedef aio_cb *aio_req; |
58 | typedef aio_cb *aio_req; |
36 | |
59 | |
37 | static int started; |
60 | static int started; |
|
|
61 | static int nreqs; |
38 | static int reqpipe[2], respipe[2]; |
62 | static int reqpipe[2], respipe[2]; |
39 | |
63 | |
|
|
64 | static aio_req qs, qe; /* queue start, queue end */ |
|
|
65 | |
40 | static int aio_proc(void *arg); |
66 | static int aio_proc(void *arg); |
41 | |
67 | |
42 | static void |
68 | static void |
43 | start_thread(void) |
69 | start_thread (void) |
44 | { |
70 | { |
45 | aio_thread *thr; |
71 | aio_thread *thr; |
46 | |
72 | |
47 | New (0, thr, 1, aio_thread); |
73 | New (0, thr, 1, aio_thread); |
48 | |
74 | |
49 | if (clone (aio_proc, |
75 | if (clone (aio_proc, |
50 | &(thr->stack[STACKSIZE]), |
76 | &(thr->stack[STACKSIZE - 16]), |
51 | CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND, |
77 | CLONE_VM|CLONE_FS|CLONE_FILES, |
52 | thr) >= 0) |
78 | thr) >= 0) |
53 | started++; |
79 | started++; |
54 | else |
80 | else |
55 | Safefree (thr); |
81 | Safefree (thr); |
56 | } |
82 | } |
57 | |
83 | |
58 | static void |
84 | static void |
59 | end_thread(void) |
85 | send_reqs (void) |
60 | { |
86 | { |
61 | aio_req req = 0; |
87 | /* this write is atomic */ |
62 | write (reqpipe[1], &req, sizeof (aio_req)); |
88 | while (qs && write (reqpipe[1], &qs, sizeof qs) == sizeof qs) |
63 | started--; |
89 | { |
|
|
90 | qs = qs->next; |
|
|
91 | if (!qs) qe = 0; |
|
|
92 | } |
64 | } |
93 | } |
65 | |
94 | |
66 | static void |
95 | static void |
67 | set_errno(int errorno) |
96 | send_req (aio_req req) |
68 | { |
97 | { |
|
|
98 | nreqs++; |
|
|
99 | req->next = 0; |
|
|
100 | |
|
|
101 | if (qe) |
|
|
102 | { |
|
|
103 | qe->next = req; |
|
|
104 | qe = req; |
|
|
105 | } |
|
|
106 | else |
|
|
107 | qe = qs = req; |
|
|
108 | |
|
|
109 | send_reqs (); |
|
|
110 | } |
|
|
111 | |
|
|
112 | static void |
|
|
113 | end_thread (void) |
|
|
114 | { |
|
|
115 | aio_req req; |
|
|
116 | New (0, req, 1, aio_cb); |
|
|
117 | req->type = REQ_QUIT; |
|
|
118 | |
|
|
119 | send_req (req); |
|
|
120 | } |
|
|
121 | |
|
|
122 | static void |
|
|
123 | read_write (pTHX_ |
|
|
124 | int dowrite, int fd, off_t offset, size_t length, |
|
|
125 | SV *data, STRLEN dataoffset, SV *callback) |
|
|
126 | { |
|
|
127 | aio_req req; |
|
|
128 | STRLEN svlen; |
|
|
129 | char *svptr = SvPV (data, svlen); |
|
|
130 | |
|
|
131 | SvUPGRADE (data, SVt_PV); |
|
|
132 | SvPOK_on (data); |
|
|
133 | |
|
|
134 | if (dataoffset < 0) |
|
|
135 | dataoffset += svlen; |
|
|
136 | |
|
|
137 | if (dataoffset < 0 || dataoffset > svlen) |
|
|
138 | croak ("data offset outside of string"); |
|
|
139 | |
|
|
140 | if (dowrite) |
|
|
141 | { |
|
|
142 | /* write: check length and adjust. */ |
|
|
143 | if (length < 0 || length + dataoffset > svlen) |
|
|
144 | length = svlen - dataoffset; |
|
|
145 | } |
|
|
146 | else |
|
|
147 | { |
|
|
148 | /* read: grow scalar as necessary */ |
|
|
149 | svptr = SvGROW (data, length + dataoffset); |
|
|
150 | } |
|
|
151 | |
|
|
152 | if (length < 0) |
|
|
153 | croak ("length must not be negative"); |
|
|
154 | |
|
|
155 | Newz (0, req, 1, aio_cb); |
|
|
156 | |
|
|
157 | if (!req) |
|
|
158 | croak ("out of memory during aio_req allocation"); |
|
|
159 | |
|
|
160 | req->type = dowrite ? REQ_WRITE : REQ_READ; |
|
|
161 | req->fd = fd; |
|
|
162 | req->offset = offset; |
|
|
163 | req->length = length; |
|
|
164 | req->data = SvREFCNT_inc (data); |
|
|
165 | req->dataptr = (char *)svptr + dataoffset; |
|
|
166 | req->callback = SvREFCNT_inc (callback); |
|
|
167 | |
|
|
168 | send_req (req); |
|
|
169 | } |
|
|
170 | |
|
|
171 | static void |
|
|
172 | poll_wait () |
|
|
173 | { |
|
|
174 | if (!nreqs) |
|
|
175 | return; |
|
|
176 | |
|
|
177 | fd_set rfd; |
|
|
178 | FD_ZERO(&rfd); |
|
|
179 | FD_SET(respipe[0], &rfd); |
|
|
180 | |
|
|
181 | select (respipe[0] + 1, &rfd, 0, 0, 0); |
|
|
182 | } |
|
|
183 | |
|
|
184 | static int |
|
|
185 | poll_cb (pTHX) |
|
|
186 | { |
|
|
187 | dSP; |
|
|
188 | int count = 0; |
|
|
189 | aio_req req; |
|
|
190 | |
|
|
191 | while (read (respipe[0], (void *)&req, sizeof (req)) == sizeof (req)) |
|
|
192 | { |
|
|
193 | nreqs--; |
|
|
194 | |
|
|
195 | if (req->type == REQ_QUIT) |
|
|
196 | { |
|
|
197 | Safefree (req->thread); |
|
|
198 | started--; |
|
|
199 | } |
|
|
200 | else |
|
|
201 | { |
|
|
202 | int errorno = errno; |
|
|
203 | errno = req->errorno; |
|
|
204 | |
|
|
205 | if (req->type == REQ_READ) |
|
|
206 | SvCUR_set (req->data, req->dataoffset |
|
|
207 | + req->result > 0 ? req->result : 0); |
|
|
208 | |
|
|
209 | if (req->data) |
|
|
210 | SvREFCNT_dec (req->data); |
|
|
211 | |
|
|
212 | if (req->type == REQ_STAT || req->type == REQ_LSTAT || req->type == REQ_FSTAT) |
|
|
213 | { |
|
|
214 | PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT; |
|
|
215 | PL_laststatval = req->result; |
|
|
216 | PL_statcache = *(req->statdata); |
|
|
217 | |
|
|
218 | Safefree (req->statdata); |
|
|
219 | } |
|
|
220 | |
|
|
221 | PUSHMARK (SP); |
|
|
222 | XPUSHs (sv_2mortal (newSViv (req->result))); |
|
|
223 | PUTBACK; |
|
|
224 | call_sv (req->callback, G_VOID); |
|
|
225 | SPAGAIN; |
|
|
226 | |
|
|
227 | if (req->callback) |
|
|
228 | SvREFCNT_dec (req->callback); |
|
|
229 | |
69 | errno = errorno; |
230 | errno = errorno; |
|
|
231 | count++; |
|
|
232 | } |
|
|
233 | |
|
|
234 | Safefree (req); |
|
|
235 | } |
|
|
236 | |
|
|
237 | if (qs) |
|
|
238 | send_reqs (); |
|
|
239 | |
|
|
240 | return count; |
70 | } |
241 | } |
|
|
242 | |
|
|
243 | static sigset_t fullsigset; |
71 | |
244 | |
72 | #undef errno |
245 | #undef errno |
|
|
246 | #include <linux/unistd.h> |
|
|
247 | #include <linux/types.h> |
|
|
248 | #include <sys/prctl.h> |
|
|
249 | |
|
|
250 | #if __alpha || __ia64 || __hppa || __v850__ |
|
|
251 | # define stat kernelstat |
|
|
252 | # define stat64 kernelstat64 |
73 | #include <asm/unistd.h> |
253 | # include <asm/stat.h> |
|
|
254 | # undef stat |
|
|
255 | # undef stat64 |
|
|
256 | #else |
|
|
257 | # define kernelstat stat |
|
|
258 | # define kernelstat64 stat64 |
|
|
259 | #endif |
|
|
260 | |
|
|
261 | #define COPY_STATDATA \ |
|
|
262 | req->statdata->st_dev = statdata.st_dev; \ |
|
|
263 | req->statdata->st_ino = statdata.st_ino; \ |
|
|
264 | req->statdata->st_mode = statdata.st_mode; \ |
|
|
265 | req->statdata->st_nlink = statdata.st_nlink; \ |
|
|
266 | req->statdata->st_uid = statdata.st_uid; \ |
|
|
267 | req->statdata->st_gid = statdata.st_gid; \ |
|
|
268 | req->statdata->st_rdev = statdata.st_rdev; \ |
|
|
269 | req->statdata->st_size = statdata.st_size; \ |
|
|
270 | req->statdata->st_atime = statdata.st_atime; \ |
|
|
271 | req->statdata->st_mtime = statdata.st_mtime; \ |
|
|
272 | req->statdata->st_ctime = statdata.st_ctime; \ |
|
|
273 | req->statdata->st_blksize = statdata.st_blksize; \ |
|
|
274 | req->statdata->st_blocks = statdata.st_blocks; \ |
74 | |
275 | |
75 | static int |
276 | static int |
76 | aio_proc(void *thr_arg) |
277 | aio_proc (void *thr_arg) |
77 | { |
278 | { |
78 | aio_thread *thr = thr_arg; |
279 | aio_thread *thr = thr_arg; |
79 | int sig; |
280 | aio_req req; |
80 | int errno; |
281 | int errno; |
81 | aio_req req; |
|
|
82 | |
282 | |
|
|
283 | /* this is very much kernel-specific :(:(:( */ |
83 | /* we rely on gcc's ability to create closures. */ |
284 | /* we rely on gcc's ability to create closures. */ |
84 | _syscall3(int,lseek,int,fd,off_t,offset,int,whence); |
285 | _syscall3(__kernel_size_t, read , unsigned int, fd, char *, buf, __kernel_size_t, count) |
85 | _syscall3(int,read,int,fd,char *,buf,off_t,count); |
286 | _syscall3(__kernel_size_t, write, unsigned int, fd, char *, buf, __kernel_size_t, count) |
86 | _syscall3(int,write,int,fd,char *,buf,off_t,count); |
|
|
87 | |
287 | |
88 | /* first get rid of any signals */ |
288 | _syscall3(long, open, char *, pathname, int, flags, int, mode) |
89 | for (sig = 1; sig < _NSIG; sig++) |
289 | _syscall1(long, close, unsigned int, fd) |
90 | if (sig != SIGTERM) |
290 | _syscall1(long, unlink, char *, filename); |
91 | signal (sig, SIG_IGN); |
291 | _syscall1(long, fsync, unsigned int, fd); |
92 | |
292 | |
|
|
293 | #ifndef __NR_fdatasync |
|
|
294 | # define __NR_fdatasync __NR_fsync |
|
|
295 | #endif |
|
|
296 | _syscall1(long, fdatasync, unsigned int, fd); |
|
|
297 | |
|
|
298 | #if BYTE_ORDER == LITTLE_ENDIAN |
|
|
299 | # define LOFF_ARG(off) (off & 0xffffffff), (off >> 32) |
|
|
300 | #elif BYTE_ORDER == BIG_ENDIAN |
|
|
301 | # define LOFF_ARG(off) (off >> 32), (off & 0xffffffff) |
|
|
302 | #endif |
|
|
303 | |
|
|
304 | #ifndef __NR_pread64 |
|
|
305 | # define __NR_pread64 __NR_pread |
|
|
306 | # define __NR_pwrite64 __NR_write |
|
|
307 | #endif |
|
|
308 | _syscall5(__kernel_ssize_t, pread64 , unsigned int, fd, char *, buf, |
|
|
309 | __kernel_size_t, count, unsigned int, offset_lh, unsigned int, offset_hl) |
|
|
310 | _syscall5(__kernel_ssize_t, pwrite64, unsigned int, fd, char *, buf, |
|
|
311 | __kernel_size_t, count, unsigned int, offset_lh, unsigned int, offset_hl) |
|
|
312 | _syscall4(long, readahead, unsigned int, fd, unsigned int, offset_lh, unsigned int, offset_hl, __kernel_size_t, count); |
|
|
313 | |
|
|
314 | #if __NR_stat64 |
|
|
315 | _syscall2(long, stat64 , const char *, filename, struct kernelstat64 *, buf) |
|
|
316 | _syscall2(long, lstat64, const char *, filename, struct kernelstat64 *, buf) |
|
|
317 | _syscall2(long, fstat64, int , fd , struct kernelstat64 *, buf) |
|
|
318 | #elif __NR_stat |
|
|
319 | _syscall2(long, stat , const char *, filename, struct kernelstat *, buf) |
|
|
320 | _syscall2(long, lstat, const char *, filename, struct kernelstat *, buf) |
|
|
321 | _syscall2(long, fstat, int , fd , struct kernelstat *, buf) |
|
|
322 | #else |
|
|
323 | # error "neither stat64 nor stat defined" |
|
|
324 | #endif |
|
|
325 | |
|
|
326 | /* the following two calls might clobber errno */ |
|
|
327 | sigprocmask (SIG_SETMASK, &fullsigset, 0); |
|
|
328 | prctl (PR_SET_PDEATHSIG, SIGKILL); |
|
|
329 | |
93 | /* then loop */ |
330 | /* then loop */ |
94 | while (read (reqpipe[0], (void *)&req, sizeof (req)) == sizeof (req)) |
331 | while (read (reqpipe[0], (void *)&req, sizeof (req)) == sizeof (req)) |
95 | { |
332 | { |
96 | req->thread = thr; |
333 | req->thread = thr; |
|
|
334 | errno = 0; /* strictly unnecessary */ |
97 | |
335 | |
98 | if (req->type == REQ_READ || req->type == REQ_WRITE) |
336 | switch (req->type) |
99 | { |
337 | { |
|
|
338 | case REQ_READ: req->result = pread64 (req->fd, req->dataptr, req->length, LOFF_ARG (req->offset)); break; |
|
|
339 | case REQ_WRITE: req->result = pwrite64 (req->fd, req->dataptr, req->length, LOFF_ARG (req->offset)); break; |
|
|
340 | case REQ_READAHEAD: req->result = readahead (req->fd, LOFF_ARG (req->offset), req->length); break; |
|
|
341 | |
|
|
342 | #if __NR_stat64 |
|
|
343 | struct kernelstat64 statdata; |
|
|
344 | case REQ_STAT: req->result = stat64 (req->dataptr, &statdata); COPY_STATDATA; break; |
|
|
345 | case REQ_LSTAT: req->result = lstat64 (req->dataptr, &statdata); COPY_STATDATA; break; |
|
|
346 | case REQ_FSTAT: req->result = fstat64 (req->fd , &statdata); COPY_STATDATA; break; |
|
|
347 | #else |
|
|
348 | struct kernelstat statdata; |
|
|
349 | case REQ_STAT: req->result = stat (req->dataptr, &statdata); COPY_STATDATA; break; |
|
|
350 | case REQ_LSTAT: req->result = lstat (req->dataptr, &statdata); COPY_STATDATA; break; |
|
|
351 | case REQ_FSTAT: req->result = fstat (req->fd , &statdata); COPY_STATDATA; break; |
|
|
352 | #endif |
|
|
353 | |
|
|
354 | case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; |
|
|
355 | case REQ_CLOSE: req->result = close (req->fd); break; |
|
|
356 | case REQ_UNLINK: req->result = unlink (req->dataptr); break; |
|
|
357 | |
|
|
358 | case REQ_FSYNC: req->result = fsync (req->fd); break; |
|
|
359 | case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; |
|
|
360 | |
|
|
361 | case REQ_QUIT: |
|
|
362 | write (respipe[1], (void *)&req, sizeof (req)); |
100 | errno = 0; |
363 | return 0; |
101 | |
364 | |
102 | if (lseek (req->fd, req->offset, SEEK_SET) == req->offset) |
365 | default: |
|
|
366 | req->result = ENOSYS; |
103 | { |
367 | break; |
104 | if (req->type == REQ_READ) |
|
|
105 | req->result = read (req->fd, req->dataptr, req->length); |
|
|
106 | else |
|
|
107 | req->result = write(req->fd, req->dataptr, req->length); |
|
|
108 | } |
|
|
109 | |
|
|
110 | req->errorno = errno; |
|
|
111 | } |
368 | } |
112 | else |
|
|
113 | { |
|
|
114 | write (respipe[1], (void *)&req, sizeof (req)); |
|
|
115 | break; |
|
|
116 | } |
|
|
117 | |
369 | |
|
|
370 | req->errorno = errno; |
118 | write (respipe[1], (void *)&req, sizeof (req)); |
371 | write (respipe[1], (void *)&req, sizeof (req)); |
119 | } |
372 | } |
120 | |
373 | |
121 | return 0; |
374 | return 0; |
122 | } |
375 | } |
123 | |
376 | |
124 | MODULE = Linux::AIO PACKAGE = Linux::AIO |
377 | MODULE = Linux::AIO PACKAGE = Linux::AIO |
125 | |
378 | |
126 | BOOT: |
379 | BOOT: |
127 | { |
380 | { |
|
|
381 | sigfillset (&fullsigset); |
|
|
382 | sigdelset (&fullsigset, SIGTERM); |
|
|
383 | sigdelset (&fullsigset, SIGQUIT); |
|
|
384 | sigdelset (&fullsigset, SIGABRT); |
|
|
385 | sigdelset (&fullsigset, SIGINT); |
|
|
386 | |
128 | if (pipe (reqpipe) || pipe (respipe)) |
387 | if (pipe (reqpipe) || pipe (respipe)) |
129 | croak ("unable to initialize request or result pipe"); |
388 | croak ("unable to initialize request or result pipe"); |
|
|
389 | |
|
|
390 | if (fcntl (reqpipe[1], F_SETFL, O_NONBLOCK)) |
|
|
391 | croak ("cannot set result pipe to nonblocking mode"); |
|
|
392 | |
|
|
393 | if (fcntl (respipe[0], F_SETFL, O_NONBLOCK)) |
|
|
394 | croak ("cannot set result pipe to nonblocking mode"); |
130 | } |
395 | } |
131 | |
396 | |
132 | void |
397 | void |
133 | min_parallel(nthreads) |
398 | min_parallel(nthreads) |
134 | int nthreads |
399 | int nthreads |
|
|
400 | PROTOTYPE: $ |
135 | CODE: |
401 | CODE: |
136 | while (nthreads > started) |
402 | while (nthreads > started) |
137 | start_thread (); |
403 | start_thread (); |
138 | |
404 | |
139 | void |
405 | void |
140 | max_parallel(nthreads) |
406 | max_parallel(nthreads) |
141 | int nthreads |
407 | int nthreads |
|
|
408 | PROTOTYPE: $ |
142 | CODE: |
409 | CODE: |
|
|
410 | { |
|
|
411 | int cur = started; |
|
|
412 | while (cur > nthreads) |
|
|
413 | { |
|
|
414 | end_thread (); |
|
|
415 | cur--; |
|
|
416 | } |
|
|
417 | |
143 | while (started > nthreads) |
418 | while (started > nthreads) |
|
|
419 | { |
|
|
420 | poll_wait (); |
|
|
421 | poll_cb (aTHX); |
|
|
422 | } |
|
|
423 | } |
|
|
424 | |
|
|
425 | void |
|
|
426 | aio_open(pathname,flags,mode,callback) |
|
|
427 | SV * pathname |
|
|
428 | int flags |
|
|
429 | int mode |
|
|
430 | SV * callback |
|
|
431 | PROTOTYPE: $$$$ |
|
|
432 | CODE: |
|
|
433 | { |
|
|
434 | aio_req req; |
|
|
435 | |
|
|
436 | Newz (0, req, 1, aio_cb); |
|
|
437 | |
|
|
438 | if (!req) |
|
|
439 | croak ("out of memory during aio_req allocation"); |
|
|
440 | |
|
|
441 | req->type = REQ_OPEN; |
|
|
442 | req->data = newSVsv (pathname); |
|
|
443 | req->dataptr = SvPV_nolen (req->data); |
|
|
444 | req->fd = flags; |
|
|
445 | req->mode = mode; |
|
|
446 | req->callback = SvREFCNT_inc (callback); |
|
|
447 | |
144 | end_thread (); |
448 | send_req (req); |
|
|
449 | } |
145 | |
450 | |
146 | void |
451 | void |
|
|
452 | aio_close(fh,callback) |
|
|
453 | InputStream fh |
|
|
454 | SV * callback |
|
|
455 | PROTOTYPE: $$ |
|
|
456 | ALIAS: |
|
|
457 | aio_close = REQ_CLOSE |
|
|
458 | aio_fsync = REQ_FSYNC |
|
|
459 | aio_fdatasync = REQ_FDATASYNC |
|
|
460 | CODE: |
|
|
461 | { |
|
|
462 | aio_req req; |
|
|
463 | |
|
|
464 | Newz (0, req, 1, aio_cb); |
|
|
465 | |
|
|
466 | if (!req) |
|
|
467 | croak ("out of memory during aio_req allocation"); |
|
|
468 | |
|
|
469 | req->type = ix; |
|
|
470 | req->fd = PerlIO_fileno (fh); |
|
|
471 | req->callback = SvREFCNT_inc (callback); |
|
|
472 | |
|
|
473 | send_req (req); |
|
|
474 | } |
|
|
475 | |
|
|
476 | void |
147 | read(fh,offset,length,data,dataoffset,callback) |
477 | aio_read(fh,offset,length,data,dataoffset,callback) |
|
|
478 | InputStream fh |
|
|
479 | UV offset |
|
|
480 | IV length |
|
|
481 | SV * data |
|
|
482 | IV dataoffset |
|
|
483 | SV * callback |
|
|
484 | PROTOTYPE: $$$$$$ |
|
|
485 | CODE: |
|
|
486 | read_write (aTHX_ 0, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); |
|
|
487 | |
|
|
488 | void |
|
|
489 | aio_write(fh,offset,length,data,dataoffset,callback) |
|
|
490 | OutputStream fh |
|
|
491 | UV offset |
|
|
492 | IV length |
|
|
493 | SV * data |
|
|
494 | IV dataoffset |
|
|
495 | SV * callback |
|
|
496 | PROTOTYPE: $$$$$$ |
|
|
497 | CODE: |
|
|
498 | read_write (aTHX_ 1, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); |
|
|
499 | |
|
|
500 | void |
|
|
501 | aio_readahead(fh,offset,length,callback) |
|
|
502 | InputStream fh |
|
|
503 | UV offset |
|
|
504 | IV length |
|
|
505 | SV * callback |
|
|
506 | PROTOTYPE: $$$$ |
|
|
507 | CODE: |
|
|
508 | { |
|
|
509 | aio_req req; |
|
|
510 | |
|
|
511 | if (length < 0) |
|
|
512 | croak ("length must not be negative"); |
|
|
513 | |
|
|
514 | Newz (0, req, 1, aio_cb); |
|
|
515 | |
|
|
516 | if (!req) |
|
|
517 | croak ("out of memory during aio_req allocation"); |
|
|
518 | |
|
|
519 | req->type = REQ_READAHEAD; |
|
|
520 | req->fd = PerlIO_fileno (fh); |
|
|
521 | req->offset = offset; |
|
|
522 | req->length = length; |
|
|
523 | req->callback = SvREFCNT_inc (callback); |
|
|
524 | |
|
|
525 | send_req (req); |
|
|
526 | } |
|
|
527 | |
|
|
528 | void |
|
|
529 | aio_stat(fh_or_path,callback) |
|
|
530 | SV * fh_or_path |
|
|
531 | SV * callback |
|
|
532 | PROTOTYPE: $$ |
|
|
533 | ALIAS: |
|
|
534 | aio_lstat = 1 |
148 | CODE: |
535 | CODE: |
|
|
536 | { |
|
|
537 | aio_req req; |
|
|
538 | |
|
|
539 | Newz (0, req, 1, aio_cb); |
|
|
540 | |
|
|
541 | if (!req) |
|
|
542 | croak ("out of memory during aio_req allocation"); |
|
|
543 | |
|
|
544 | New (0, req->statdata, 1, Stat_t); |
|
|
545 | |
|
|
546 | if (!req->statdata) |
|
|
547 | croak ("out of memory during aio_req->statdata allocation"); |
|
|
548 | |
|
|
549 | if (SvPOK (fh_or_path)) |
|
|
550 | { |
|
|
551 | req->type = ix ? REQ_LSTAT : REQ_STAT; |
|
|
552 | req->data = newSVsv (fh_or_path); |
|
|
553 | req->dataptr = SvPV_nolen (req->data); |
|
|
554 | } |
|
|
555 | else |
|
|
556 | { |
|
|
557 | req->type = REQ_FSTAT; |
|
|
558 | req->fd = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); |
|
|
559 | } |
|
|
560 | |
|
|
561 | req->callback = SvREFCNT_inc (callback); |
|
|
562 | |
|
|
563 | send_req (req); |
|
|
564 | } |
|
|
565 | |
|
|
566 | void |
|
|
567 | aio_unlink(pathname,callback) |
|
|
568 | SV * pathname |
|
|
569 | SV * callback |
|
|
570 | PROTOTYPE: $$ |
|
|
571 | CODE: |
|
|
572 | { |
|
|
573 | aio_req req; |
|
|
574 | |
|
|
575 | Newz (0, req, 1, aio_cb); |
|
|
576 | |
|
|
577 | if (!req) |
|
|
578 | croak ("out of memory during aio_req allocation"); |
|
|
579 | |
|
|
580 | req->type = REQ_UNLINK; |
|
|
581 | req->data = newSVsv (pathname); |
|
|
582 | req->dataptr = SvPV_nolen (req->data); |
|
|
583 | req->callback = SvREFCNT_inc (callback); |
|
|
584 | |
|
|
585 | send_req (req); |
|
|
586 | } |
|
|
587 | |
|
|
588 | int |
|
|
589 | poll_fileno() |
|
|
590 | PROTOTYPE: |
|
|
591 | CODE: |
|
|
592 | RETVAL = respipe[0]; |
|
|
593 | OUTPUT: |
|
|
594 | RETVAL |
|
|
595 | |
|
|
596 | int |
|
|
597 | poll_cb(...) |
|
|
598 | PROTOTYPE: |
|
|
599 | CODE: |
|
|
600 | RETVAL = poll_cb (aTHX); |
|
|
601 | OUTPUT: |
|
|
602 | RETVAL |
|
|
603 | |
|
|
604 | void |
|
|
605 | poll_wait() |
|
|
606 | PROTOTYPE: |
|
|
607 | CODE: |
|
|
608 | poll_wait (); |
|
|
609 | |
|
|
610 | int |
|
|
611 | nreqs() |
|
|
612 | PROTOTYPE: |
|
|
613 | CODE: |
|
|
614 | RETVAL = nreqs; |
|
|
615 | OUTPUT: |
|
|
616 | RETVAL |
|
|
617 | |