ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.xs
(Generate patch)

Comparing IO-AIO/AIO.xs (file contents):
Revision 1.106 by root, Mon Sep 24 18:14:00 2007 UTC vs.
Revision 1.107 by root, Wed Oct 3 21:27:51 2007 UTC

97# define SvVAL64 SvIV 97# define SvVAL64 SvIV
98#else 98#else
99# define SvVAL64 SvNV 99# define SvVAL64 SvNV
100#endif 100#endif
101 101
102static HV *stash;
103
102#define dBUF \ 104#define dBUF \
103 char *aio_buf; \ 105 char *aio_buf; \
104 X_LOCK (wrklock); \ 106 X_LOCK (wrklock); \
105 self->dbuf = aio_buf = malloc (AIO_BUFSIZE); \ 107 self->dbuf = aio_buf = malloc (AIO_BUFSIZE); \
106 X_UNLOCK (wrklock); \ 108 X_UNLOCK (wrklock); \
501 break; 503 break;
502 504
503 case REQ_OPEN: 505 case REQ_OPEN:
504 { 506 {
505 /* convert fd to fh */ 507 /* convert fd to fh */
506 SV *fh; 508 SV *fh = &PL_sv_undef;
507 509
508 PUSHs (sv_2mortal (newSViv (req->result))); 510 if (req->result >= 0)
509 PUTBACK; 511 {
510 call_pv ("IO::AIO::_fd2fh", G_SCALAR | G_EVAL); 512 GV *gv = (GV *)sv_newmortal ();
511 SPAGAIN; 513 int flags = req->int1 & (O_RDONLY | O_WRONLY | O_RDWR);
514 char sym [64];
515 int symlen;
516
517 symlen = snprintf (sym, sizeof (sym), "fd#%d", req->result);
518 gv_init (gv, stash, sym, symlen, 0);
512 519
520 symlen = snprintf (
521 sym,
522 sizeof (sym),
523 "%s&=%d",
524 flags == O_RDONLY ? "<" : flags == O_WRONLY ? ">" : "+<",
525 req->result
526 );
527
528 if (do_open (gv, sym, symlen, 0, 0, 0, 0))
513 fh = POPs; 529 fh = gv;
514 PUSHMARK (SP); 530 }
531
515 XPUSHs (fh); 532 XPUSHs (fh);
516 } 533 }
517 break; 534 break;
518 535
519 case REQ_GROUP: 536 case REQ_GROUP:
1238 case REQ_FCHMOD: req->result = fchmod (req->int1, req->mode); break; 1255 case REQ_FCHMOD: req->result = fchmod (req->int1, req->mode); break;
1239 case REQ_TRUNCATE: req->result = truncate (req->ptr1, req->offs); break; 1256 case REQ_TRUNCATE: req->result = truncate (req->ptr1, req->offs); break;
1240 case REQ_FTRUNCATE: req->result = ftruncate (req->int1, req->offs); break; 1257 case REQ_FTRUNCATE: req->result = ftruncate (req->int1, req->offs); break;
1241 1258
1242 case REQ_OPEN: req->result = open (req->ptr1, req->int1, req->mode); break; 1259 case REQ_OPEN: req->result = open (req->ptr1, req->int1, req->mode); break;
1243 case REQ_CLOSE: req->result = close (req->int1); break; 1260 case REQ_CLOSE: req->result = PerlIO_close ((PerlIO *)req->ptr1); break;
1244 case REQ_UNLINK: req->result = unlink (req->ptr1); break; 1261 case REQ_UNLINK: req->result = unlink (req->ptr1); break;
1245 case REQ_RMDIR: req->result = rmdir (req->ptr1); break; 1262 case REQ_RMDIR: req->result = rmdir (req->ptr1); break;
1246 case REQ_MKDIR: req->result = mkdir (req->ptr1, req->mode); break; 1263 case REQ_MKDIR: req->result = mkdir (req->ptr1, req->mode); break;
1247 case REQ_RENAME: req->result = rename (req->ptr2, req->ptr1); break; 1264 case REQ_RENAME: req->result = rename (req->ptr2, req->ptr1); break;
1248 case REQ_LINK: req->result = link (req->ptr2, req->ptr1); break; 1265 case REQ_LINK: req->result = link (req->ptr2, req->ptr1); break;
1421 1438
1422PROTOTYPES: ENABLE 1439PROTOTYPES: ENABLE
1423 1440
1424BOOT: 1441BOOT:
1425{ 1442{
1426 HV *stash = gv_stashpv ("IO::AIO", 1); 1443 stash = gv_stashpv ("IO::AIO", 1);
1427 1444
1428 newCONSTSUB (stash, "EXDEV", newSViv (EXDEV)); 1445 newCONSTSUB (stash, "EXDEV", newSViv (EXDEV));
1429 newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY)); 1446 newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY));
1430 newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY)); 1447 newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY));
1431 newCONSTSUB (stash, "O_CREAT", newSViv (O_CREAT)); 1448 newCONSTSUB (stash, "O_CREAT", newSViv (O_CREAT));
1499 1516
1500 REQ_SEND; 1517 REQ_SEND;
1501} 1518}
1502 1519
1503void 1520void
1504aio_close (SV *fh, SV *callback=&PL_sv_undef) 1521aio_fsync (SV *fh, SV *callback=&PL_sv_undef)
1505 PROTOTYPE: $;$ 1522 PROTOTYPE: $;$
1506 ALIAS: 1523 ALIAS:
1507 aio_close = REQ_CLOSE
1508 aio_fsync = REQ_FSYNC 1524 aio_fsync = REQ_FSYNC
1509 aio_fdatasync = REQ_FDATASYNC 1525 aio_fdatasync = REQ_FDATASYNC
1510 PPCODE: 1526 PPCODE:
1511{ 1527{
1512 dREQ; 1528 dREQ;
1514 req->type = ix; 1530 req->type = ix;
1515 req->sv1 = newSVsv (fh); 1531 req->sv1 = newSVsv (fh);
1516 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh))); 1532 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh)));
1517 1533
1518 REQ_SEND (req); 1534 REQ_SEND (req);
1535}
1536
1537void
1538aio_close (SV *fh, SV *callback=&PL_sv_undef)
1539 PROTOTYPE: $;$
1540 PPCODE:
1541{
1542 PerlIO *io = IoIFP (sv_2io (fh));
1543 int fd = PerlIO_fileno (io);
1544
1545 if (fd < 0)
1546 croak ("aio_close called with fd-less filehandle");
1547
1548 PerlIO_binmode (io, 0, 0, 0);
1549
1550 {
1551 dREQ;
1552
1553 req->type = REQ_CLOSE;
1554 req->sv1 = newSVsv (fh);
1555 req->ptr1 = (void *)io;
1556
1557 REQ_SEND (req);
1558 }
1519} 1559}
1520 1560
1521void 1561void
1522aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef) 1562aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef)
1523 ALIAS: 1563 ALIAS:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines