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