… | |
… | |
8 | #include <signal.h> |
8 | #include <signal.h> |
9 | #include <sched.h> |
9 | #include <sched.h> |
10 | |
10 | |
11 | #define STACKSIZE 1024 /* yeah */ |
11 | #define STACKSIZE 1024 /* yeah */ |
12 | |
12 | |
13 | enum { REQ_QUIT, REQ_READ, REQ_WRITE, REQ_OPEN }; |
13 | enum { REQ_QUIT, REQ_READ, REQ_WRITE, REQ_OPEN, REQ_CLOSE }; |
14 | |
14 | |
15 | typedef struct { |
15 | typedef struct { |
16 | char stack[STACKSIZE]; |
16 | char stack[STACKSIZE]; |
17 | } aio_thread; |
17 | } aio_thread; |
18 | |
18 | |
… | |
… | |
177 | /* we rely on gcc's ability to create closures. */ |
177 | /* we rely on gcc's ability to create closures. */ |
178 | _syscall3(int,lseek,int,fd,off_t,offset,int,whence); |
178 | _syscall3(int,lseek,int,fd,off_t,offset,int,whence); |
179 | _syscall3(int,read,int,fd,char *,buf,off_t,count); |
179 | _syscall3(int,read,int,fd,char *,buf,off_t,count); |
180 | _syscall3(int,write,int,fd,char *,buf,off_t,count); |
180 | _syscall3(int,write,int,fd,char *,buf,off_t,count); |
181 | _syscall3(int,open,char *,pathname,int,flags,mode_t,mode); |
181 | _syscall3(int,open,char *,pathname,int,flags,mode_t,mode); |
|
|
182 | _syscall1(int,close,int,fd); |
182 | |
183 | |
183 | /* then loop */ |
184 | /* then loop */ |
184 | while (read (reqpipe[0], (void *)&req, sizeof (req)) == sizeof (req)) |
185 | while (read (reqpipe[0], (void *)&req, sizeof (req)) == sizeof (req)) |
185 | { |
186 | { |
186 | req->thread = thr; |
187 | req->thread = thr; |
… | |
… | |
197 | } |
198 | } |
198 | } |
199 | } |
199 | else if (req->type == REQ_OPEN) |
200 | else if (req->type == REQ_OPEN) |
200 | { |
201 | { |
201 | req->result = open (req->dataptr, req->fd, req->mode); |
202 | req->result = open (req->dataptr, req->fd, req->mode); |
|
|
203 | } |
|
|
204 | else if (req->type == REQ_CLOSE) |
|
|
205 | { |
|
|
206 | req->result = close (req->fd); |
202 | } |
207 | } |
203 | else |
208 | else |
204 | { |
209 | { |
205 | write (respipe[1], (void *)&req, sizeof (req)); |
210 | write (respipe[1], (void *)&req, sizeof (req)); |
206 | break; |
211 | break; |
… | |
… | |
294 | req->mode = mode; |
299 | req->mode = mode; |
295 | req->callback = SvREFCNT_inc (callback); |
300 | req->callback = SvREFCNT_inc (callback); |
296 | |
301 | |
297 | send_req (req); |
302 | send_req (req); |
298 | |
303 | |
|
|
304 | void |
|
|
305 | aio_close(fh,callback) |
|
|
306 | PerlIO * fh |
|
|
307 | SV * callback |
|
|
308 | PROTOTYPE: $ |
|
|
309 | CODE: |
|
|
310 | aio_req req; |
|
|
311 | |
|
|
312 | New (0, req, 1, aio_cb); |
|
|
313 | |
|
|
314 | if (!req) |
|
|
315 | croak ("out of memory during aio_req allocation"); |
|
|
316 | |
|
|
317 | req->type = REQ_CLOSE; |
|
|
318 | req->fd = PerlIO_fileno (fh); |
|
|
319 | req->callback = SvREFCNT_inc (callback); |
|
|
320 | |
|
|
321 | send_req (req); |
|
|
322 | |
299 | int |
323 | int |
300 | poll_fileno() |
324 | poll_fileno() |
301 | PROTOTYPE: |
325 | PROTOTYPE: |
302 | CODE: |
326 | CODE: |
303 | RETVAL = respipe[0]; |
327 | RETVAL = respipe[0]; |