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

read returns 0 for read when nonblock and no data is available #106

Open
headius opened this issue Jul 17, 2024 · 1 comment
Open

read returns 0 for read when nonblock and no data is available #106

headius opened this issue Jul 17, 2024 · 1 comment

Comments

@headius
Copy link
Member

headius commented Jul 17, 2024

There's some peculiar behavior when read is called with no data available, for sure when nonblock but possibly also when blocking: it always just returns 0. I have traced it all the way to the libc call. The fix for jnr/jnr-enxio#44 does not appear to improve the behavior.

This prevents JRuby working with nonblocking UNIX sockets properly:

require 'io/nonblock'
require 'socket'
require 'tmpdir'

buffer = IO::Buffer.new(1000)

Dir.mktmpdir {|d|
  f = File.join(d, "foo")
  server = UNIXServer.new(f)
  client = UNIXSocket.new(f)
  client.nonblock {|client|
    p buffer.read(client, 0, 10)
  }
}

Outputs -35 on CRuby but 0 on JRuby.

@headius
Copy link
Member Author

headius commented Jul 17, 2024

Note this requires the fiber_async branch currently in progress based on 9.5-dev and current master from this repository. A previous fix on the JRuby branch added a missing negation to the errno returned, which led to the discovery that unix sockets still always returned 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant