X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00 X-Spam-Check-By: sourceware.org Message-ID: <4A817DA3.7090409@zone42.org> Date: Tue, 11 Aug 2009 16:18:11 +0200 From: Steffen Sledz User-Agent: Thunderbird 2.0.0.22 (Windows/20090605) MIME-Version: 1.0 To: cygwin Mailing List Subject: Re: 1.7.0: read() blocking with VMIN = VTIME = 0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com 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