Incorrect behavior in TIOCINQ ioctl
Corinna Vinschen
corinna-cygwin@cygwin.com
Fri Feb 28 19:23:00 GMT 2020
On Feb 27 22:38, Åke Rehnman wrote:
> Hi,
>
> I recently ran in to some troubles with the TIOCINQ ioctl. I am wondering if
> the cygwin implementation is correct... It seems if there were any existing
> framing overrun errors etc etc before calling the TIOCINQ ioctl it is
> returning an error (EINVAL). Reading through linux implmentation of TIOCINQ
> does simply return number of pending chars without any clearing or checking
> for errors.
>
> I suggest the whole if (ev & CE_FRAME ...... ) is removed.
>
> Excerpt from fhandler_serial.cc:
>
> /* ioctl: */
> int
> fhandler_serial::ioctl (unsigned int cmd, void *buf)
> {
> .
> .
> if (!ClearCommError (get_handle (), &ev, &st))
> {
> __seterrno ();
> res = -1;
> }
> .
> .
> .
> case TIOCINQ:
> if (ev & CE_FRAME || ev & CE_IOE || ev & CE_OVERRUN || ev & CE_RXOVER
> || ev & CE_RXPARITY)
> {
> set_errno (EINVAL); /* FIXME: Use correct errno */
> res = -1;
> }
> else
> ipbuf = st.cbInQue;
> break;
I'm not familiar with serial I/O and the code is pretty stable(*).
- Is it a safe bet that ClearCommError returns valid values in
st.cbInQue even if one of the error conditions occur? Maybe the
right thing to do is to return 0 in certain error cases...?
- Did you actually try if this fixes your problem? It's pretty
simple to build the Cygwin DLL
https://cygwin.com/faq.html#faq.programming.building-cygwin
Corinna
(*) euphemistically for "nobody looked into the code for a long time"
--
Corinna Vinschen
Cygwin Maintainer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20200228/e150ea49/attachment.sig>
More information about the Cygwin
mailing list