diff options
author | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2021-12-23 12:20:09 +1300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-23 12:20:09 +1300 |
commit | bed920f0731a1a89a0e5fc7a7428d21be3ffb8a0 (patch) | |
tree | 928abd45556a6f2380211ef347ce0df9c0858db9 /include/ruby | |
parent | 91c5c1c132994c9ca4540125d462988d83e37a6b (diff) |
Add fiber scheduler hooks for `pread`/`pwrite`, and add support to `IO::Buffer`.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5249
Merged-By: ioquatix <samuel@codeotaku.com>
Diffstat (limited to 'include/ruby')
-rw-r--r-- | include/ruby/fiber/scheduler.h | 26 | ||||
-rw-r--r-- | include/ruby/io/buffer.h | 6 |
2 files changed, 32 insertions, 0 deletions
diff --git a/include/ruby/fiber/scheduler.h b/include/ruby/fiber/scheduler.h index ff587e28c0..a255a1a712 100644 --- a/include/ruby/fiber/scheduler.h +++ b/include/ruby/fiber/scheduler.h @@ -262,6 +262,32 @@ VALUE rb_fiber_scheduler_io_read(VALUE scheduler, VALUE io, VALUE buffer, size_t VALUE rb_fiber_scheduler_io_write(VALUE scheduler, VALUE io, VALUE buffer, size_t length); /** + * Nonblocking read from the passed IO at the specified offset. + * + * @param[in] scheduler Target scheduler. + * @param[out] io An io object to read from. + * @param[out] buffer Return buffer. + * @param[in] length Requested number of bytes to read. + * @param[in] offset The offset in the given IO to read the data from. + * @retval RUBY_Qundef `scheduler` doesn't have `#io_read`. + * @return otherwise What `scheduler.io_read` returns. + */ +VALUE rb_fiber_scheduler_io_pread(VALUE scheduler, VALUE io, VALUE buffer, size_t length, off_t offset); + +/** + * Nonblocking write to the passed IO at the specified offset. + * + * @param[in] scheduler Target scheduler. + * @param[out] io An io object to write to. + * @param[in] buffer What to write. + * @param[in] length Number of bytes to write. + * @param[in] offset The offset in the given IO to write the data to. + * @retval RUBY_Qundef `scheduler` doesn't have `#io_write`. + * @return otherwise What `scheduler.io_write` returns. + */ +VALUE rb_fiber_scheduler_io_pwrite(VALUE scheduler, VALUE io, VALUE buffer, size_t length, off_t offset); + +/** * Nonblocking read from the passed IO using a native buffer. * * @param[in] scheduler Target scheduler. diff --git a/include/ruby/io/buffer.h b/include/ruby/io/buffer.h index 4826a7a76f..907fec20bb 100644 --- a/include/ruby/io/buffer.h +++ b/include/ruby/io/buffer.h @@ -80,6 +80,12 @@ VALUE rb_io_buffer_transfer(VALUE self); void rb_io_buffer_resize(VALUE self, size_t size); void rb_io_buffer_clear(VALUE self, uint8_t value, size_t offset, size_t length); +// The length is the minimum required length. +VALUE rb_io_buffer_read(VALUE self, VALUE io, size_t length); +VALUE rb_io_buffer_pread(VALUE self, VALUE io, size_t length, off_t offset); +VALUE rb_io_buffer_write(VALUE self, VALUE io, size_t length); +VALUE rb_io_buffer_pwrite(VALUE self, VALUE io, size_t length, off_t offset); + RBIMPL_SYMBOL_EXPORT_END() #endif /* RUBY_IO_BUFFER_T */ |