Skip to content

IO#fcntl logic for F_SETFL, O_NONBLOCK is inverted #8081

@headius

Description

@headius

Ruby IO streams can be set to nonblock by using the fcntl library and calling IO#fcntl as shown below:

require 'fcntl'

# get current flags
flags = write.fcntl(Fcntl::F_GETFL)

# set O_NONBLOCK flag
write.fcntl(Fcntl::F_SETFL, flags | (Fcntl::O_NONBLOCK)) 

# clear O_NONBLOCK flag
write.fcntl(Fcntl::F_SETFL, flags & (~Fcntl::O_NONBLOCK))

Our logic should be calling the NIO setBlocking with true when O_NONBLOCK flag is zero and with false when O_NONBLOCK is nonzero, but we have it reversed:

if ((nArg & OpenFlags.O_NONBLOCK.intValue()) != 0) {
fptr.setBlocking(runtime, true);
} else {
fptr.setBlocking(runtime, false);
}

This is obviously wrong, but inconveniently also messes up the workaround for #8069.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions