BUG in fcntl?

In ruby 1.8.1 (2003-12-05) [i686-linux], why does this program:

require 'fcntl'

flags = $stdin.fcntl(Fcntl::F_GETFL)
flags |= Fcntl::O_NONBLOCK

$stdin.fcntl(Fcntl::F_SETFL, flags)

c = $stdin.getc
puts "c=#{c}"

Hang on the getc call? I’d expect the same behavior as this C program:

#include <fcntl.h>

main()
{
    int ch;
    int flags;
    flags = fcntl(0, F_GETFL);
    flags |= O_NONBLOCK;
    fcntl(0, F_SETFL, flags);
    ch = getchar();
    printf("ch=`%d'\n", ch);
}

which gets an instant EOF back from getchar().

-Mark

Hi,

···

At Mon, 22 Dec 2003 15:01:56 +0900, Mark J. Reed wrote:

In ruby 1.8.1 (2003-12-05) [i686-linux], why does this program:

require ‘fcntl’

flags = $stdin.fcntl(Fcntl::F_GETFL)
flags |= Fcntl::O_NONBLOCK

$stdin.fcntl(Fcntl::F_SETFL, flags)

c = $stdin.getc
puts “c=#{c}”

Hang on the getc call?

Because IO#getc retries at EAGAIN. $stdin.read(1) doesn’t stop
there but raises Errno::EAGAIN. Or you’d be possible to use
IO#ready? and #wait in io/wait library.


Nobu Nakada

D’oh. Thank you very much!

···

On Mon, Dec 22, 2003 at 04:16:32PM +0900, nobu.nokada@softhome.net wrote:

Because IO#getc retries at EAGAIN. $stdin.read(1) doesn’t stop
there but raises Errno::EAGAIN. Or you’d be possible to use
IO#ready? and #wait in io/wait library.