Module: AIO
- Defined in:
- ext/aio/aio.c
Defined Under Namespace
Constant Summary collapse
- SYNC =
INT2NUM(O_SYNC)
- QUEUE =
XXX O_DSYNC not supported by Darwin rb_define_const(mAio, “DSYNC”, INT2NUM(O_DSYNC));
INT2NUM(100)
- INPROGRESS =
INT2NUM(EINPROGRESS)
- ALLDONE =
INT2NUM(AIO_ALLDONE)
- CANCELED =
INT2NUM(AIO_CANCELED)
- NOTCANCELED =
INT2NUM(AIO_NOTCANCELED)
- WAIT =
INT2NUM(LIO_WAIT)
- NOWAIT =
INT2NUM(LIO_NOWAIT)
- NOP =
INT2NUM(LIO_NOP)
- READ =
INT2NUM(LIO_READ)
- WRITE =
INT2NUM(LIO_WRITE)
Class Method Summary collapse
- .cancel(*args) ⇒ Object
- .error(cb) ⇒ Object
-
.lio_listio(cb1, cb2, ...) ⇒ Array
Schedules a batch of read requests for execution by the kernel in order to reduce system calls.Blocks until all the requests complete and returns an array equal in length to the given files, with the read buffers as string elements.The number of operations is currently limited to 16 due to cross platform limitations.
-
.read(cb) ⇒ String
Asynchronously reads a file.This is an initial blocking implementation until cross platform notification is supported.
- .return(cb) ⇒ Object
- .sync(op, cb) ⇒ Object
-
.write(cb) ⇒ Fixnum
Asynchronously writes to a file.This is an initial blocking implementation until cross platform notification is supported.
Class Method Details
.cancel(*args) ⇒ Object
651 652 653 654 655 656 657 658 659 660 661 662 663 |
# File 'ext/aio/aio.c', line 651 static VALUE rb_aio_s_cancel(int argc, VALUE *argv, VALUE aio) { VALUE fd, cb; rb_scan_args(argc, argv, "02", &fd, &cb); if (NIL_P(fd) || !FIXNUM_P(fd)) rb_aio_error("No file descriptor given"); if (NIL_P(cb)) return rb_aio_cancel( NUM2INT(fd), NULL ); rb_aiocb_t *cbs = GetCBStruct(cb); if (rb_block_given_p()){ cbs->rcb = rb_block_proc(); } return rb_aio_cancel( NUM2INT(fd), &cbs->cb ); } |
.error(cb) ⇒ Object
727 728 729 730 731 732 733 734 735 |
# File 'ext/aio/aio.c', line 727 static VALUE rb_aio_s_error( VALUE aio, VALUE cb ) { rb_aiocb_t *cbs = GetCBStruct(cb); if (rb_block_given_p()){ cbs->rcb = rb_block_proc(); } return rb_aio_err( &cbs->cb ); } |
.lio_listio(cb1, cb2, ...) ⇒ Array
Schedules a batch of read requests for execution by the kernel in order to reduce system calls.Blocks until all the requests complete and returns an array equal in length to the given files, with the read buffers as string elements.The number of operations is currently limited to 16 due to cross platform limitations.
open_nocancel(“first.txt0”, 0x0, 0x1B6) = 3 0 fstat(0x3, 0xBFFFEE04, 0x1B6) = 0 0 open_nocancel(“second.txt0”, 0x0, 0x1B6) = 4 0 fstat(0x4, 0xBFFFEE04, 0x1B6) = 0 0 open_nocancel(“third.txt0”, 0x0, 0x1B6) = 5 0 fstat(0x5, 0xBFFFEE04, 0x1B6) = 0 0 fstat64(0x1, 0xBFFFE234, 0x1B6) = 0 0 ioctl(0x1, 0x4004667A, 0xBFFFE29C) = 0 0 lio_listio(0x2, 0xBFFFEE64, 0x3) = 0 0 close_nocancel(0x4) = 0 0 close_nocancel(0x3) = 0 0
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 |
# File 'ext/aio/aio.c', line 599 static VALUE rb_aio_s_lio_listio( VALUE aio, VALUE cbs ) { VALUE mode_arg, mode; mode_arg = RARRAY_PTR(cbs)[0]; mode = (mode_arg == c_aio_wait || mode_arg == c_aio_nowait || mode_arg == c_aio_nop) ? rb_ary_shift(cbs) : c_aio_wait; int ops = RARRAY_LEN(cbs); if (ops > AIO_MAX_LIST) return c_aio_queue; switch(NUM2INT(mode)){ case LIO_WAIT: return rb_ensure( rb_aio_lio_listio_blocking, (VALUE)cbs, rb_io_closes, (VALUE)cbs ); case LIO_NOWAIT: return rb_ensure( rb_aio_lio_listio_non_blocking, (VALUE)cbs, rb_io_closes, (VALUE)cbs ); case LIO_NOP: return rb_ensure( rb_aio_lio_listio_noop, (VALUE)cbs, rb_io_closes, (VALUE)cbs ); } rb_aio_error("Only modes AIO::WAIT, AIO::NOWAIT and AIO::NOP supported"); } |
.read(cb) ⇒ String
Asynchronously reads a file.This is an initial blocking implementation until cross platform notification is supported.
567 568 569 570 571 572 573 574 575 |
# File 'ext/aio/aio.c', line 567 static VALUE rb_aio_s_read( VALUE aio, VALUE cb ) { rb_aiocb_t *cbs = GetCBStruct(cb); if (rb_block_given_p()){ cbs->rcb = rb_block_proc(); } return rb_ensure( rb_aio_read, (VALUE)&cbs->cb, control_block_close, cb ); } |
.return(cb) ⇒ Object
692 693 694 695 696 697 698 699 700 |
# File 'ext/aio/aio.c', line 692 static VALUE rb_aio_s_return( VALUE aio, VALUE cb ) { rb_aiocb_t *cbs = GetCBStruct(cb); if (rb_block_given_p()){ cbs->rcb = rb_block_proc(); } return rb_aio_return( &cbs->cb ); } |
.sync(op, cb) ⇒ Object
766 767 768 769 770 771 772 773 774 775 776 777 |
# File 'ext/aio/aio.c', line 766 static VALUE rb_aio_s_sync( VALUE aio, VALUE op, VALUE cb ) { rb_aiocb_t *cbs = GetCBStruct(cb); if (rb_block_given_p()){ cbs->rcb = rb_block_proc(); } Check_Type( op, T_FIXNUM ); /* XXX handle AIO::DSYNC gracefully as well */ if (op != c_aio_sync) rb_aio_error("Operation AIO::SYNC expected"); return rb_aio_sync( NUM2INT(op), &cbs->cb ); } |
.write(cb) ⇒ Fixnum
Asynchronously writes to a file.This is an initial blocking implementation until cross platform notification is supported.
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 |
# File 'ext/aio/aio.c', line 542 static VALUE rb_aio_s_write( VALUE aio, VALUE cb ) { rb_aiocb_t *cbs = GetCBStruct(cb); #ifdef RUBY19 rb_io_t *fptr; #else OpenFile *fptr; #endif GetOpenFile(cbs->io, fptr); rb_io_check_writable(fptr); if (rb_block_given_p()){ cbs->rcb = rb_block_proc(); } return rb_ensure( rb_aio_write, (VALUE)&cbs->cb, control_block_close, cb ); } |