Reading data from ttyS fails

Corinna Vinschen
Fri May 25 09:39:00 GMT 2012

On May 24 19:17, thunderboy42 wrote:
> Hello Corinna,
> I used a part from for
> testting because my 'original' is a little bit complicated. (see the source at
> the end)
> But I think I found the problem in "". 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
> 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

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?


Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

Problem reports:
Unsubscribe info:

More information about the Cygwin mailing list