This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Reading data from ttyS fails


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]