--- IO-AIO/AIO.xs 2005/07/11 01:49:14 1.7 +++ IO-AIO/AIO.xs 2005/07/13 00:13:09 1.10 @@ -2,16 +2,20 @@ #include "perl.h" #include "XSUB.h" +#define _XOPEN_SOURCE 500 + #include #include + #include #include #include #include -#include +#if __linux +#include +#endif #include -#include typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */ typedef void *OutputStream; /* hack, but 5.6.1 is simply toooo old ;) */ @@ -150,9 +154,12 @@ XPUSHs (fh); } - PUTBACK; - call_sv (req->callback, G_VOID | G_EVAL); - SPAGAIN; + if (SvOK (req->callback)) + { + PUTBACK; + call_sv (req->callback, G_VOID | G_EVAL); + SPAGAIN; + } if (req->callback) SvREFCNT_dec (req->callback); @@ -308,8 +315,8 @@ switch (type) { - case REQ_READ: req->result = pread64 (req->fd, req->dataptr, req->length, req->offset); break; - case REQ_WRITE: req->result = pwrite64 (req->fd, req->dataptr, req->length, req->offset); break; + case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; + case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; #if SYS_readahead case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; #else @@ -363,6 +370,8 @@ MODULE = IO::AIO PACKAGE = IO::AIO +PROTOTYPES: ENABLE + BOOT: { if (pipe (respipe)) @@ -412,12 +421,12 @@ max_outstanding = nreqs; void -aio_open(pathname,flags,mode,callback) +aio_open(pathname,flags,mode,callback=&PL_sv_undef) SV * pathname int flags int mode SV * callback - PROTOTYPE: $$$$ + PROTOTYPE: $$$;$ CODE: { aio_req req; @@ -438,10 +447,10 @@ } void -aio_close(fh,callback) +aio_close(fh,callback=&PL_sv_undef) InputStream fh SV * callback - PROTOTYPE: $$ + PROTOTYPE: $;$ ALIAS: aio_close = REQ_CLOSE aio_fsync = REQ_FSYNC @@ -463,36 +472,36 @@ } void -aio_read(fh,offset,length,data,dataoffset,callback) +aio_read(fh,offset,length,data,dataoffset,callback=&PL_sv_undef) InputStream fh UV offset IV length SV * data IV dataoffset SV * callback - PROTOTYPE: $$$$$$ + PROTOTYPE: $$$$$;$ CODE: read_write (0, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); void -aio_write(fh,offset,length,data,dataoffset,callback) +aio_write(fh,offset,length,data,dataoffset,callback=&PL_sv_undef) OutputStream fh UV offset IV length SV * data IV dataoffset SV * callback - PROTOTYPE: $$$$$$ + PROTOTYPE: $$$$$;$ CODE: read_write (1, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); void -aio_readahead(fh,offset,length,callback) +aio_readahead(fh,offset,length,callback=&PL_sv_undef) InputStream fh UV offset IV length SV * callback - PROTOTYPE: $$$$ + PROTOTYPE: $$$;$ CODE: { aio_req req; @@ -515,12 +524,12 @@ } void -aio_stat(fh_or_path,callback) +aio_stat(fh_or_path,callback=&PL_sv_undef) SV * fh_or_path SV * callback - PROTOTYPE: $$ ALIAS: - aio_lstat = 1 + aio_stat = REQ_STAT + aio_lstat = REQ_LSTAT CODE: { aio_req req; @@ -537,7 +546,7 @@ if (SvPOK (fh_or_path)) { - req->type = ix ? REQ_LSTAT : REQ_STAT; + req->type = ix; req->data = newSVsv (fh_or_path); req->dataptr = SvPV_nolen (req->data); } @@ -553,10 +562,9 @@ } void -aio_unlink(pathname,callback) +aio_unlink(pathname,callback=&PL_sv_undef) SV * pathname SV * callback - PROTOTYPE: $$ CODE: { aio_req req;