This is the mail archive of the
mailing list for the Cygwin project.
Re: 1.7.0: read() blocking with VMIN = VTIME = 0
- From: Steffen Sledz <sledz at zone42 dot org>
- To: cygwin Mailing List <cygwin at cygwin dot com>
- Date: Tue, 11 Aug 2009 16:18:11 +0200
- Subject: Re: 1.7.0: read() blocking with VMIN = VTIME = 0
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
// 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 );
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple