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.5 by root, Sun Jul 10 23:45:16 2005 UTC vs.
Revision 1.9 by root, Tue Jul 12 11:02:54 2005 UTC

6#include <sys/stat.h> 6#include <sys/stat.h>
7#include <unistd.h> 7#include <unistd.h>
8#include <fcntl.h> 8#include <fcntl.h>
9#include <signal.h> 9#include <signal.h>
10#include <sched.h> 10#include <sched.h>
11#include <endian.h>
12 11
13#include <pthread.h> 12#include <pthread.h>
14#include <sys/syscall.h> 13#include <sys/syscall.h>
15 14
16typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */ 15typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */
148 147
149 PUSHMARK (SP); 148 PUSHMARK (SP);
150 XPUSHs (fh); 149 XPUSHs (fh);
151 } 150 }
152 151
152 if (SvOK (req->callback))
153 {
153 PUTBACK; 154 PUTBACK;
154 call_sv (req->callback, G_VOID | G_EVAL); 155 call_sv (req->callback, G_VOID | G_EVAL);
155 SPAGAIN; 156 SPAGAIN;
157 }
156 158
157 if (req->callback) 159 if (req->callback)
158 SvREFCNT_dec (req->callback); 160 SvREFCNT_dec (req->callback);
159 161
160 errno = errorno; 162 errno = errorno;
361 return 0; 363 return 0;
362} 364}
363 365
364MODULE = IO::AIO PACKAGE = IO::AIO 366MODULE = IO::AIO PACKAGE = IO::AIO
365 367
368PROTOTYPES: ENABLE
369
366BOOT: 370BOOT:
367{ 371{
368 if (pipe (respipe)) 372 if (pipe (respipe))
369 croak ("unable to initialize result pipe"); 373 croak ("unable to initialize result pipe");
370 374
410 CODE: 414 CODE:
411 RETVAL = max_outstanding; 415 RETVAL = max_outstanding;
412 max_outstanding = nreqs; 416 max_outstanding = nreqs;
413 417
414void 418void
415aio_open(pathname,flags,mode,callback) 419aio_open(pathname,flags,mode,callback=&PL_sv_undef)
416 SV * pathname 420 SV * pathname
417 int flags 421 int flags
418 int mode 422 int mode
419 SV * callback 423 SV * callback
420 PROTOTYPE: $$$$ 424 PROTOTYPE: $$$;$
421 CODE: 425 CODE:
422{ 426{
423 aio_req req; 427 aio_req req;
424 428
425 Newz (0, req, 1, aio_cb); 429 Newz (0, req, 1, aio_cb);
436 440
437 send_req (req); 441 send_req (req);
438} 442}
439 443
440void 444void
441aio_close(fh,callback) 445aio_close(fh,callback=&PL_sv_undef)
442 InputStream fh 446 InputStream fh
443 SV * callback 447 SV * callback
444 PROTOTYPE: $$ 448 PROTOTYPE: $;$
445 ALIAS: 449 ALIAS:
446 aio_close = REQ_CLOSE 450 aio_close = REQ_CLOSE
447 aio_fsync = REQ_FSYNC 451 aio_fsync = REQ_FSYNC
448 aio_fdatasync = REQ_FDATASYNC 452 aio_fdatasync = REQ_FDATASYNC
449 CODE: 453 CODE:
461 465
462 send_req (req); 466 send_req (req);
463} 467}
464 468
465void 469void
466aio_read(fh,offset,length,data,dataoffset,callback) 470aio_read(fh,offset,length,data,dataoffset,callback=&PL_sv_undef)
467 InputStream fh 471 InputStream fh
468 UV offset 472 UV offset
469 IV length 473 IV length
470 SV * data 474 SV * data
471 IV dataoffset 475 IV dataoffset
472 SV * callback 476 SV * callback
473 PROTOTYPE: $$$$$$ 477 PROTOTYPE: $$$$$;$
474 CODE: 478 CODE:
475 read_write (0, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); 479 read_write (0, PerlIO_fileno (fh), offset, length, data, dataoffset, callback);
476 480
477void 481void
478aio_write(fh,offset,length,data,dataoffset,callback) 482aio_write(fh,offset,length,data,dataoffset,callback=&PL_sv_undef)
479 OutputStream fh 483 OutputStream fh
480 UV offset 484 UV offset
481 IV length 485 IV length
482 SV * data 486 SV * data
483 IV dataoffset 487 IV dataoffset
484 SV * callback 488 SV * callback
485 PROTOTYPE: $$$$$$ 489 PROTOTYPE: $$$$$;$
486 CODE: 490 CODE:
487 read_write (1, PerlIO_fileno (fh), offset, length, data, dataoffset, callback); 491 read_write (1, PerlIO_fileno (fh), offset, length, data, dataoffset, callback);
488 492
489void 493void
490aio_readahead(fh,offset,length,callback) 494aio_readahead(fh,offset,length,callback=&PL_sv_undef)
491 InputStream fh 495 InputStream fh
492 UV offset 496 UV offset
493 IV length 497 IV length
494 SV * callback 498 SV * callback
495 PROTOTYPE: $$$$ 499 PROTOTYPE: $$$;$
496 CODE: 500 CODE:
497{ 501{
498 aio_req req; 502 aio_req req;
499 503
500 if (length < 0) 504 if (length < 0)
513 517
514 send_req (req); 518 send_req (req);
515} 519}
516 520
517void 521void
518aio_stat(fh_or_path,callback) 522aio_stat(fh_or_path,callback=&PL_sv_undef)
519 SV * fh_or_path 523 SV * fh_or_path
520 SV * callback 524 SV * callback
521 PROTOTYPE: $$
522 ALIAS: 525 ALIAS:
526 aio_stat = REQ_STAT
523 aio_lstat = 1 527 aio_lstat = REQ_LSTAT
524 CODE: 528 CODE:
525{ 529{
526 aio_req req; 530 aio_req req;
527 531
528 Newz (0, req, 1, aio_cb); 532 Newz (0, req, 1, aio_cb);
535 if (!req->statdata) 539 if (!req->statdata)
536 croak ("out of memory during aio_req->statdata allocation"); 540 croak ("out of memory during aio_req->statdata allocation");
537 541
538 if (SvPOK (fh_or_path)) 542 if (SvPOK (fh_or_path))
539 { 543 {
540 req->type = ix ? REQ_LSTAT : REQ_STAT; 544 req->type = ix;
541 req->data = newSVsv (fh_or_path); 545 req->data = newSVsv (fh_or_path);
542 req->dataptr = SvPV_nolen (req->data); 546 req->dataptr = SvPV_nolen (req->data);
543 } 547 }
544 else 548 else
545 { 549 {
551 555
552 send_req (req); 556 send_req (req);
553} 557}
554 558
555void 559void
556aio_unlink(pathname,callback) 560aio_unlink(pathname,callback=&PL_sv_undef)
557 SV * pathname 561 SV * pathname
558 SV * callback 562 SV * callback
559 PROTOTYPE: $$
560 CODE: 563 CODE:
561{ 564{
562 aio_req req; 565 aio_req req;
563 566
564 Newz (0, req, 1, aio_cb); 567 Newz (0, req, 1, aio_cb);
572 req->callback = SvREFCNT_inc (callback); 575 req->callback = SvREFCNT_inc (callback);
573 576
574 send_req (req); 577 send_req (req);
575} 578}
576 579
580void
581flush()
582 PROTOTYPE:
583 CODE:
584 while (nreqs)
585 {
586 poll_wait ();
587 poll_cb ();
588 }
589
590void
591poll()
592 PROTOTYPE:
593 CODE:
594 if (nreqs)
595 {
596 poll_wait ();
597 poll_cb ();
598 }
599
577int 600int
578poll_fileno() 601poll_fileno()
579 PROTOTYPE: 602 PROTOTYPE:
580 CODE: 603 CODE:
581 RETVAL = respipe [0]; 604 RETVAL = respipe [0];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines