Skip to content

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

Open
@headius

Description

@headius

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions