X-Recipient: archive-cygwin AT delorie DOT com X-Spam-Check-By: sourceware.org Date: Tue, 28 Jul 2009 13:13:10 +0200 From: Corinna Vinschen To: cygwin AT cygwin DOT com Subject: Re: 1.7.0: read() blocking with VMIN = VTIME = 0 Message-ID: <20090728111310.GS18621@calimero.vinschen.de> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.19 (2009-02-20) Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: 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 On Jul 28 13:00, daniel ?kerud wrote: > Hello! > > 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. > > Does not work on: > CYGWIN_NT-5.0 1.7.0(0.212/5/3) 2009-07-24 09:59 > > Works on: > Linux version 2.6.28-13-generic (buildd AT vernadsky) (gcc version 4.3.3 > (Ubuntu 4.3.3-5ubuntu4) ) #45-Ubuntu SMP Tue Jun 30 19:49:51 UTC 2009 > > Example program: > > #include > #include > #include > > int main() { > char c = 0; > struct termios term, term_orig; > > if(tcgetattr(0, &term_orig)) { > printf("tcgetattr failed\n"); > return 2; > } > > term = term_orig; > > term.c_lflag &= ~ICANON; > term.c_lflag |= ECHO; > term.c_cc[VMIN] = 0; > term.c_cc[VTIME] = 0; > > if (tcsetattr(0, TCSANOW, &term)) { > printf("tcsetattr failed\n"); > return 2; > } > > printf("Calling read (blocks here on cygwin)\n"); > fflush(stdout); > > read(0, &c, 1); > > printf("Back from read\n"); > > tcsetattr(0, TCSANOW, &term_orig); > > return 0; > } > > Is this supported in Cygwin? The only work around I know for now is to > do a select() before read()ing. It's not supported in the normal Windows console mode. It's supported in the tty emulation, though. This works in the console window as well by setting the environment variable CYGWIN to contain "tty" before starting your shell (for instance by adding `set CYGWIN=tty' to your Cygwin.bat file). Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Project Co-Leader cygwin AT cygwin DOT com Red Hat -- 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