delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/07/28/07:13:34

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 <corinna-cygwin AT cygwin DOT com>
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: <b000da060907280400q3ad7d39awcdd3ff2514e987c4 AT mail DOT gmail DOT com>
MIME-Version: 1.0
In-Reply-To: <b000da060907280400q3ad7d39awcdd3ff2514e987c4@mail.gmail.com>
User-Agent: Mutt/1.5.19 (2009-02-20)
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
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 <stdio.h>
> #include <unistd.h>
> #include <termios.h>
> 
> 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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019