[ruby-core:124519] [Ruby Feature#21837] Introduce socket hooks in Fiber Scheduler interface
Issue #21837 has been reported by noteflakes (Sharon Rosner). ---------------------------------------- Feature #21837: Introduce socket hooks in Fiber Scheduler interface https://bugs.ruby-lang.org/issues/21837 * Author: noteflakes (Sharon Rosner) * Status: Open ---------------------------------------- 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. I propose adding the following hooks: - `#socket_recv(sock, buffer, length, flags, recvfrom)`: performs a `recv` or `recvfrom`. The `recvfrom` argument is a boolean denoting whether a `recvfrom` should 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 a `send` or `sendto`. The `dest` argument is nil for a `send`. When not nil, a `sendto` operation should be done. - `#socket_connect(sock, addr)`: performs a `connect`. - `#socket_accept(sock, client_sockaddr)` - performs an `accept`. The `client_sockaddr` argument is an `IO::Buffer` that receives the peer addrinfo. The PR for this feature: https://github.com/ruby/ruby/pull/15865 -- https://bugs.ruby-lang.org/
Issue #21837 has been updated by Eregon (Benoit Daloze). What's the advantage to do it this way vs just the `non-blocking` + `#io_wait` way? (the description doesn't explain that) ---------------------------------------- Feature #21837: Introduce socket hooks in Fiber Scheduler interface https://bugs.ruby-lang.org/issues/21837#change-116131 * Author: noteflakes (Sharon Rosner) * Status: Open ---------------------------------------- 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. I propose adding the following hooks: - `#socket_recv(sock, buffer, length, flags, recvfrom)`: performs a `recv` or `recvfrom`. The `recvfrom` argument is a boolean denoting whether a `recvfrom` should 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 a `send` or `sendto`. The `dest` argument is nil for a `send`. When not nil, a `sendto` operation should be done. - `#socket_connect(sock, addr)`: performs a `connect`. - `#socket_accept(sock, client_sockaddr)` - performs an `accept`. The `client_sockaddr` argument is an `IO::Buffer` that receives the peer addrinfo. The PR for this feature: https://github.com/ruby/ruby/pull/15865 -- https://bugs.ruby-lang.org/
Issue #21837 has been updated by noteflakes (Sharon Rosner).
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. ---------------------------------------- Feature #21837: Introduce socket hooks in Fiber Scheduler interface https://bugs.ruby-lang.org/issues/21837#change-116136 * Author: noteflakes (Sharon Rosner) * Status: Open ---------------------------------------- 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. I propose adding the following hooks: - `#socket_recv(sock, buffer, length, flags, recvfrom)`: performs a `recv` or `recvfrom`. The `recvfrom` argument is a boolean denoting whether a `recvfrom` should 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 a `send` or `sendto`. The `dest` argument is nil for a `send`. When not nil, a `sendto` operation should be done. - `#socket_connect(sock, addr)`: performs a `connect`. - `#socket_accept(sock, client_sockaddr)` - performs an `accept`. The `client_sockaddr` argument is an `IO::Buffer` that receives the peer addrinfo. The PR for this feature: https://github.com/ruby/ruby/pull/15865 -- https://bugs.ruby-lang.org/
participants (2)
-
Eregon (Benoit Daloze) -
noteflakes (Sharon Rosner)