Feature #21837
openIntroduce socket hooks in Fiber Scheduler interface
Description
Currently the fiber scheduler interface does not support any socket operations. The stock Ruby socket implementation performs all operations in a non-blocking way, and invokes the #io_wait fiber scheduler hook in order to wait for readiness. Adding fiber scheduler hooks for socket I/O will allow using io_uring to perform socket I/O directly without waiting for socket readiness.
I propose adding the following hooks:
-
#socket_recv(sock, buffer, length, flags, recvfrom): performs arecvorrecvfrom. Therecvfromargument is a boolean denoting whether arecvfromshould be performed. When true, the hook should return an array containing the number of bytes received and the source address. When false, the hook should return the number of bytes received. -
#socket_send(sock, dest, buffer, length, flags): performs asendorsendto. Thedestargument is nil for asend. When not nil, asendtooperation should be done. -
#socket_connect(sock, addr): performs aconnect. -
#socket_accept(sock, client_sockaddr)- performs anaccept. Theclient_sockaddrargument is anIO::Bufferthat receives the peer addrinfo.
The PR for this feature: https://github.com/ruby/ruby/pull/15865
Updated by Eregon (Benoit Daloze) about 1 month ago
What's the advantage to do it this way vs just the non-blocking + #io_wait way? (the description doesn't explain that)
Updated by noteflakes (Sharon Rosner) about 1 month ago
What's the advantage to do it this way vs just the non-blocking + #io_wait way? (the description doesn't explain that)
This is specifically to allow using the io_uring interface to perform socket I/O in a fiber scheduler implementation. I'm adding this information to the above feature proposal.
Updated by noteflakes (Sharon Rosner) about 1 month ago
- Description updated (diff)