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 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 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline 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 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 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