X-Recipient: archive-cygwin@delorie.com
X-SWARE-Spam-Status: No, hits=-2.6 required=5.0	tests=AWL,BAYES_00,KHOP_THREADED,T_RP_MATCHES_RCVD
X-Spam-Check-By: sourceware.org
Message-ID: <4F847E67.2@lysator.liu.se>
Date: Tue, 10 Apr 2012 20:39:35 +0200
From: Peter Rosin <peda@lysator.liu.se>
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20120327 Thunderbird/11.0.1
MIME-Version: 1.0
To: cygwin@cygwin.com
Subject: Re: Problem with reading nonblocking /dev/com in 1.7.10 and up
References: <4F847921.8020506@ui.ac.id>
In-Reply-To: <4F847921.8020506@ui.ac.id>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

On 2012-04-10 20:17, Abdul Muis wrote:
> I have notice that I could not read serial device (/dev/com4 or
> /dev/ttyS3) with non blocking mode since 1.7.10 and up. I used to read
> serial data while doing openGL visualization. In which, the openGL
> display was not changed due to blocking mode reading.
> 
> The command is
> 
> fcntl(fd, F_SETFL, FNDELAY); // set reading as non blocking mode, should
> return '0' if no data comming
> n=read(fd, &test, 10); // starting from 1.7.10 always return -1 although
> there is incoming data

I don't know and haven't tried lately (no serial ports connected at the
moment), but in the past I have successfully used:

	long flags = fcntl(fd, F_GETFL);
	fcntl(fd, F_SETFL, flags | O_NONBLOCK);

FNDELAY is probably a non-posix name that in practice is equivalent to
O_NONBLOCK, but more importantly I think you should OR the flag in without
clobbering all other flags.

However, I last tested that before 1.7.10, so my version may well behave
just like your code.

Cheers,
Peter

--
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

