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