--- IO-AIO/AIO.xs 2009/04/19 13:06:15 1.135 +++ IO-AIO/AIO.xs 2009/04/19 13:15:55 1.136 @@ -501,7 +501,18 @@ \ if (GIMME_V != G_VOID) \ XPUSHs (req_sv (req, AIO_REQ_KLASS)); - + +static int +extract_fd (SV *fh, int wr) +{ + int fd = PerlIO_fileno (wr ? IoOFP (sv_2io (fh)) : IoIFP (sv_2io (fh))); + + if (fd < 0) + croak ("illegal fh argument, either not an OS file or read/write mode mismatch"); + + return fd; +} + MODULE = IO::AIO PACKAGE = IO::AIO PROTOTYPES: ENABLE @@ -592,11 +603,12 @@ aio_fdatasync = EIO_FDATASYNC PPCODE: { + int fd = extract_fd (fh, 0); dREQ; req->type = ix; req->sv1 = newSVsv (fh); - req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh))); + req->int1 = fd; REQ_SEND (req); } @@ -606,11 +618,12 @@ PROTOTYPE: $$$$;$ PPCODE: { + int fd = extract_fd (fh, 0); dREQ; req->type = EIO_SYNC_FILE_RANGE; req->sv1 = newSVsv (fh); - req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh))); + req->int1 = fd; req->offs = SvVAL64 (offset); req->size = SvVAL64 (nbytes); req->int2 = flags; @@ -624,6 +637,7 @@ PPCODE: { static int close_pipe = -1; /* dummy fd to close fds via dup2 */ + int fd = extract_fd (fh, 0); dREQ; if (close_pipe < 0) @@ -641,7 +655,7 @@ req->type = EIO_DUP2; req->int1 = close_pipe; req->sv2 = newSVsv (fh); - req->int2 = PerlIO_fileno (IoIFP (sv_2io (fh))); + req->int2 = fd; REQ_SEND (req); } @@ -686,11 +700,7 @@ if (len < 0) croak ("length must not be negative"); - fd = PerlIO_fileno (ix == EIO_READ ? IoIFP (sv_2io (fh)) - : IoOFP (sv_2io (fh))); - - if (fd < 0) - croak ("illegal fh argument, either not an OS file or read/write mode mismatch"); + fd = extract_fd (fh, ix == EIO_WRITE); { dREQ; @@ -734,13 +744,15 @@ PROTOTYPE: $$$$;$ PPCODE: { + int ifd = extract_fd (in_fh , 0); + int ofd = extract_fd (out_fh, 0); dREQ; req->type = EIO_SENDFILE; req->sv1 = newSVsv (out_fh); - req->int1 = PerlIO_fileno (IoIFP (sv_2io (out_fh))); + req->int1 = ofd; req->sv2 = newSVsv (in_fh); - req->int2 = PerlIO_fileno (IoIFP (sv_2io (in_fh))); + req->int2 = ifd; req->offs = SvVAL64 (in_offset); req->size = length; @@ -752,11 +764,12 @@ PROTOTYPE: $$$;$ PPCODE: { + int fd = extract_fd (fh, 0); dREQ; req->type = EIO_READAHEAD; req->sv1 = newSVsv (fh); - req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh))); + req->int1 = fd; req->offs = SvVAL64 (offset); req->size = length;