delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/08/11/10:18:55

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 <sledz AT zone42 DOT org>
User-Agent: Thunderbird 2.0.0.22 (Windows/20090605)
MIME-Version: 1.0
To: cygwin Mailing List <cygwin AT cygwin DOT com>
Subject: Re: 1.7.0: read() blocking with VMIN = VTIME = 0
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.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

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

- Raw text -


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