1.7.0: read() blocking with VMIN = VTIME = 0

Steffen Sledz sledz@zone42.org
Tue Aug 11 14:18:00 GMT 2009


daniel åkerud wrote:
> With my example program below the read() is blocking even though
> canonical input is set and VMIN = VTIME = 0.
> It is supposed to act in a non-blocking way.
> ...

I had a similar problem. Code looking like yours worked fine in an xterm, but not in a bash inside a windows console. After a bit trial and error i found this code working well in both cases:

    struct termios ttystate;
    // get the terminal state
    tcgetattr(STDIN_FILENO, &ttystate);
    // turn off canonical mode
    ttystate.c_lflag &= ~ICANON;
    // minimum number of characters for non-canonical read
    ttystate.c_cc[VMIN] = 0;
    // timeout in deciseconds for non-canonical read
    ttystate.c_cc[VTIME] = 0;

    int oldstat = fcntl(STDIN_FILENO, F_GETFL, 0 );
    fcntl(STDIN_FILENO, F_SETFL, oldstat | O_NONBLOCK );

Steffen




--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list