delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2012/05/25/05:38:42

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Fri, 25 May 2012 11:37:53 +0200
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: Reading data from ttyS fails
Message-ID: <20120525093753.GB4225@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <1337876268 DOT 2629209054 AT as03 DOT cooltoad DOT com>
MIME-Version: 1.0
In-Reply-To: <1337876268.2629209054@as03.cooltoad.com>
User-Agent: Mutt/1.5.21 (2010-09-15)
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 May 24 19:17, thunderboy42 wrote:
> Hello Corinna,
> 
> I used a part from http://en.wikibooks.org/wiki/Serial_Programming/termios for
> testting because my 'original' is a little bit complicated. (see the source at
> the end)
> 
> But I think I found the problem in "fhandler_serial.cc". There was some code
> added for leaving the method raw_read when there are no more chars received
> and the serial port was opened in non blocking mode (code starting at line
> 86). But I think it would be a good idea to deliver the chars received until
> then, so I build my own cygwin1.dll with the following changes in
> fhandler_serial.cc: 
> 
> 88,94c88
> -             PurgeComm (get_handle (), PURGE_RXABORT);
> -             if (tot == 0)
> -               {
> -                 tot = -1;
> -                 set_errno (EAGAIN);
> -               }
> -             goto out;
> ---
> +               break;
> 
> This works for me now.

Thanks for the testcase and thanks for diving into the Cygwin source code.

I applied a slightly different patch.  The problem is that, after calling
ReadFile, an overlapped operation is in progress.  This overlapped I/O
must be stopped before leaving raw_read, so I changed the code after
ReadFile to cancel the I/O using the CancelIO function, rather than using
PurgeComm.

It's kind of weird, but in my testing, CancelIO just stopped the current
I/O without losing bytes, while calling PurgeComm (PURGE_RXABORT) would
result in lost bytes.  That's a bit puzzeling.  The description of
PurgeComm implies that PURGE_RXABORT only stops the I/O operation,
CancelIO-like.  But apparently there's more going on in the device
driver when PURGE_RXABORT is called.

With the patch it works for me now without losing any bytes, even with
lots of data and with a bigger read buffer (1K instead of 1 byte).

Would you mind to test this a bit more intensive?


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