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