X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-1.5 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org MIME-Version: 1.0 In-Reply-To: <4C3EF7BB.4040204@hones.org.uk> References: <4C3E59E3 DOT 4050003 AT hones DOT org DOT uk> <20100715054952 DOT GB10561 AT trixie DOT casa DOT cgf DOT cx> <4C3EF7BB DOT 4040204 AT hones DOT org DOT uk> Date: Thu, 15 Jul 2010 13:41:04 +0100 Message-ID: Subject: Re: Problem with select() on console From: Andy Koppe To: cygwin AT cygwin DOT com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes 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 15 July 2010 12:57, Cliff Hones wrote: >> On Thu, Jul 15, 2010 at 01:44:19AM +0100, Cliff Hones wrote: >>> When select() is used to test for input availability on the standard >>> cygwin console in normal (cooked) mode, it indicates input is available >>> as soon as any key is pressed. =C2=A0However, a call to read(0,...) >>> will (correctly) block until a terminating RETURN is entered. >>> >>> select() should only indicate input is available when a call >>> to read would *not* block - ie when a read call will immediately >>> return at least one character or an error such as EOF. >>> > I'm surprised this hasn't come up more frequently. =C2=A0In my case, I ha= ve an > app which needs to respond to user input line-based commands, but also > does other processing. I don't want the app to block every time the user > starts to enter a command. =C2=A0Of course I could use threads, but that's > an unnecessary change (at least unnecessary on Linux etc). You could disable terminal line editing (with tcsetattr) and do the line processing yourself, or let the readline library do it all for you, which your users would proabably appreciate anyway. Readline's "Alternate Interface" allows you to interleave line input with other I/O. See http://tiswww.case.edu/php/chet/readline/readline.html#SEC41 I suspect readline() is the reason why this hasn't come up more frequently. Andy -- 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