X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:reply-to :references:mime-version:content-type:in-reply-to; q=dns; s= default; b=yKY64WZk/EPWQqkqCeP+iRz8vu/9FFR6KaYOqQDtVWOFbscF6Mv6k KMxJYZBOGOa8WTxtZh1OpIMxjNwo57uktG+AsZiIIJ0QLKkbZxKMuqHe6oluJRrH RApp63QHE7kzxaurtuxaucGpsGahV7nFUrLcRTk9Gd29e+nmfG+pHs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:reply-to :references:mime-version:content-type:in-reply-to; s=default; bh=Lf20VRMuhr/14ibBOCsCXEXlwqs=; b=FgnnTudWb+Gj9Gq8mj+Qf36PteFU uojFXRyjsY1PTu3+jp1DSw5shyWAMNVfIW1PwRof6cHC9e6jOxlmEZatPhpBoEx4 eU52QGBXh4ZtfHO+wvQblRcMqPMygT5h8Pw2myJGMZ6/wwGkLaBDbbwneqED/rWA ESwydy8N2nsbpPQ= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: 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 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-106.4 required=5.0 tests=AWL,BAYES_00,GOOD_FROM_CORINNA_CYGWIN,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=HX-Languages-Length:1656 X-HELO: mout.kundenserver.de Date: Fri, 28 Feb 2020 20:23:30 +0100 From: Corinna Vinschen To: cygwin AT cygwin DOT com Cc: =?utf-8?Q?=C3=85ke?= Rehnman Subject: Re: Incorrect behavior in TIOCINQ ioctl Message-ID: <20200228192330.GN4045@calimero.vinschen.de> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com, =?utf-8?Q?=C3=85ke?= Rehnman References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="yhqQ34TVR4fE8mPU" Content-Disposition: inline In-Reply-To: --yhqQ34TVR4fE8mPU Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Feb 27 22:38, =C3=85ke Rehnman wrote: > Hi, >=20 > 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 existi= ng > framing overrun errors etc etc=C2=A0 before calling the TIOCINQ ioctl it = is > returning an error (EINVAL). Reading through linux implmentation of TIOCI= NQ > does simply return number of pending chars without any clearing or checki= ng > for errors. >=20 > I suggest the whole if (ev & CE_FRAME=C2=A0 ...... ) is removed. >=20 > Excerpt from fhandler_serial.cc: >=20 > /* ioctl: */ > int > fhandler_serial::ioctl (unsigned int cmd, void *buf) > { > . > . > =C2=A0 if (!ClearCommError (get_handle (), &ev, &st)) > =C2=A0=C2=A0=C2=A0 { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 __seterrno (); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 res =3D -1; > =C2=A0=C2=A0=C2=A0 } > . > . > . > =C2=A0=C2=A0=C2=A0=C2=A0 case TIOCINQ: > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (ev & CE_FRAME || ev & CE_IOE || = ev & CE_OVERRUN || ev & CE_RXOVER > =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0 || ev & CE_RXPARITY) > =C2=A0=C2=A0=C2=A0 =C2=A0{ > =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0 set_errno (EINVAL);=C2=A0=C2=A0=C2=A0 /* = FIXME: Use correct errno */ > =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0 res =3D -1; > =C2=A0=C2=A0=C2=A0 =C2=A0} > =C2=A0=C2=A0=C2=A0=C2=A0 else > =C2=A0 =C2=A0 =C2=A0 =C2=A0 ipbuf =3D st.cbInQue; > =C2=A0=C2=A0=C2=A0=C2=A0 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" --=20 Corinna Vinschen Cygwin Maintainer --yhqQ34TVR4fE8mPU Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAl5ZaLIACgkQ9TYGna5E T6DDRA/9HwYFl/XnWKztbNxO4UN9vn3nvvETQSuzQ9E8ALcViMiZPB0xgW4XcLXW t34xCVwie/7zR15qV5lM51fof77Yp4zg0v3Qal5EnlIp8Eb+v63vmTOpafYhy4kE m+juaw6KMpcQ+YCCiT3mBh/2p9NWpadxY4Y5SYpiBwE0j/JsRJd5bgfyEaGPcQsW ZQq//gtcg4Zfud/hC/hz55nD7W9bKtNjZhobvP0e+odhTxEvCI3sxFQ6KOPQvVyQ uQHfgOZnDWlDRaQWcKnBFWqJLZLu7t1Ajvdr0R7emBwepZOyqVkRA0eJzN05x5hR 37brWwc2oFrG0fr8cKIGPqymYxVYFB0RnSO53pRNMJ76HgP5jzPzDQKS3l/cpn0J Lg2cLB6VOgPSFX+VUMS1fCHQwDhvDY0bxL7IE0lCSA+FzP2TUbpoGuSkhtwXkuXc XdDlEEqOWlDXfIBLu053ZXh+dArtjSO/PoyGd4NJn3gS5diPXsT88UqfnKRZ/PhH 04ys0aHuN/wVPS9TPdrGwOziH96ACUryx/zX2fCZ5tIZrUBoyymeFg+dxfvThhwz kPNg/HFio0OoiV63kinJRd3Ev4Yw2D5sOV4njexpdM/2kKra28KUz934YAEdPDvb Frcswxbh80ctvO9m6nwpEJmClFPcBPusdA3OTkXN2j5fSHbSa2E= =KgDs -----END PGP SIGNATURE----- --yhqQ34TVR4fE8mPU--