Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IO::Buffer for scheduler interface. #4621

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

@ioquatix
Copy link
Member

@ioquatix ioquatix commented Jul 2, 2021

There are several places where we cannot avoid using (void*, size_t) for read and write operation.

While using fake strings seemed to work, I was told we cannot expose it to Ruby code.

Therefore, the only solution is to create a IO buffer interface that can correctly and efficiently implement this required interface.

I have validated that this works using the event gem which has several implementations including Pure Ruby, kqueue, epoll and io_uring.

  • Write tests.
  • Add convenient predicate methods for flags.
  • Implement handling for IMMUTABLE and LOCKED flags.
  • Consider removing String backed buffer interface (unreliable).
@eregon
Copy link
Member

@eregon eregon commented Jul 2, 2021

Would wrapping the (void*, size_t) in a FFI::Pointer work?
One can do FFI::Pointer.new(address).slice(0, size) or ptr = FFI::Pointer.new(address); ptr.total = size.

@eregon
Copy link
Member

@eregon eregon commented Jul 2, 2021

The callbacks from rb_fiber_scheduler_io_read etc could also simply pass the address + size as Integer to Ruby, and then let the scheduler do whatever it wants with that, no?

@ioquatix
Copy link
Member Author

@ioquatix ioquatix commented Jul 2, 2021

The callbacks from rb_fiber_scheduler_io_read etc could also simply pass the address + size as Integer to Ruby, and then let the scheduler do whatever it wants with that, no?

As you know the scheduler interface is defined by Ruby interface, not C interface. So it needs Ruby objects, not void* and size_t. I think passing void* as integer is a bad design. You cannot write pure Ruby implementation of scheduler with that.

@ioquatix ioquatix force-pushed the ioquatix:io-buffer branch 2 times, most recently from 37659b3 to 95cc6e2 Jul 2, 2021
@ioquatix ioquatix force-pushed the ioquatix:io-buffer branch from 95cc6e2 to bf87086 Jul 2, 2021
@ioquatix ioquatix force-pushed the ioquatix:io-buffer branch from 8ebee69 to 8b5440d Jul 3, 2021
@ioquatix ioquatix force-pushed the ioquatix:io-buffer branch from cdd6c3d to dcee28c Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants