From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.133]) by sourceware.org (Postfix) with ESMTPS id 9F2DC3942028 for ; Fri, 13 Mar 2020 10:12:49 +0000 (GMT) Received: from calimero.vinschen.de ([24.134.7.25]) by mrelayeu.kundenserver.de (mreue010 [212.227.15.167]) with ESMTPSA (Nemesis) id 1M1YxX-1j9fRL23Cd-0035OZ for ; Fri, 13 Mar 2020 11:12:48 +0100 Received: by calimero.vinschen.de (Postfix, from userid 500) id EC1F9A806D6; Fri, 13 Mar 2020 11:12:47 +0100 (CET) Date: Fri, 13 Mar 2020 11:12:47 +0100 From: Corinna Vinschen To: cygwin@cygwin.com Subject: Re: Setting termios VMIN > 0 and VTIME > 0 on non blocking file Message-ID: <20200313101247.GD512788@calimero.vinschen.de> Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: <9e4c6428-59de-df07-9e33-44ba95d5497f@gmail.com> <20200312114041.GJ4042@calimero.vinschen.de> <365dd437-7553-eb4e-3253-aba3bab74895@gmail.com> <20200312144445.GP4042@calimero.vinschen.de> <20200312150833.GQ4042@calimero.vinschen.de> <9e56e005-660b-373e-d557-9c8bc97c45ba@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="4jXrM3lyYWu4nBt5" Content-Disposition: inline In-Reply-To: <9e56e005-660b-373e-d557-9c8bc97c45ba@gmail.com> X-Provags-ID: V03:K1:AbepJaoRSJ3UXrxqf4AzV4dzOUojZJukpHu5Vf0V5W+wFqsTQX2 NKBeRgVy044jhOA+zVmOEu/azklhzgOKT6QuIa9pT+abPIzkdym45itnPQjsa3NO4cVodPm 2nMiBjViB+Q0NFVwoZ37raQSob6Cq4HIdIauWLPABtBwrJbZ/Y4tw8Nxgd1tm4ejW7Npwft SY5KSzlvj0AWi/O7vDXkw== X-UI-Out-Filterresults: notjunk:1;V03:K0:60sdJIdBonQ=:9MwLbaoHP6NYPPE4qPmr31 u5pA99tPdV/ckrZ+QIZIxoo/1F57HyGeBDAM7/BtbQZLMc6HHPjxU9ci/QOg1oGGCnUMYrjLa CmeAsbauDqrqiUC+3ecSsOboawPkEpC8miMb74eOofT/c9g6zsf2za4HTjDUuYL5as6XjDaI6 EbXctaW3+8f+HB9Amy/ad5oRdgVSndTHaYZTH6RSuLP998jWKNFMFlvYQqFEwTK8xwZ6vCn34 d7rzXBj0FMEjkMNKeF5b4E6w6BmpYoUC7+c+GJCZhjXfH0kPQVojbUCHXEq4QQdpLBkAnrYsz WWOeZioohNaxSuZk7+Nvvoj17QssQWja1bK7eGrkHFPfGpcMhpNNDo3QuQOjQxRmASaRhP4Xd 8U3Jxt7wh6KZEioNq7J3uKtb/19qNsc6K3MembCwsOBdkBy4PuOwR/EZv8Z4P56b9o7nGTkiE tNpIe/pInr6UHkMVCv3UcE8rS9NHMXQVtMBphoFWgHonT99KpRgUhS0a3PSGmALuWY/+ybYyB 6LNK8Cfp3GxaI+zNmyfREp2Num29c9v/CHRAjbIC8xR/3KISG8WfuOFRhfjlVeaz+ViYu5F97 eOw2JgyrBEWK84zaUJxtVa/gxB/a3hX+p4IJiCflsCCAhRWiAfhcHrtWr0LzbH/MyN3kWK+8H mlBmGA5nqzLqYcyEsJ65yAz7/QkD1C//RyM6/1yad33XdsmkbaaCPhvtQFSCViWgr5GHYab5a SRN6hgZEy/wA/vIrclFIcbpRZZWLLfZPX/05AYiTs5d8U+T1vueNQQVRwe4g0Ex3xsaL0/cnd qHPQRuh5k2QVUogWoORkGh87MU0NmvVOtMBVJBUammR2767Vmj/+HIN3axATPLvtyo5ujer X-Spam-Status: No, score=-119.4 required=5.0 tests=BAYES_00, GARBLED_BODY, GIT_PATCH_0, GIT_PATCH_2, GIT_PATCH_3, GOOD_FROM_CORINNA_CYGWIN, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: cygwin@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Mar 2020 10:12:51 -0000 --4jXrM3lyYWu4nBt5 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mar 12 18:04, =C3=85ke Rehnman via Cygwin wrote: >=20 > On 2020-03-12 16:08, Corinna Vinschen wrote: > > On Mar 12 15:44, Corinna Vinschen wrote: > > > On Mar 12 15:20, =C3=85ke Rehnman via Cygwin wrote: > > > > I think the problem is if the number of bytes requested are more th= an what > > > To clarify: number of bytes =3D=3D VMIN? > no number of bytes requested from ReadFile(). As far as I know Win32 has = no > concept of VMIN. Right, just this weird TimeoutMultiplier, but nevertheless I wasn't sure what you meant. > > > > is in the buffer it is going to overlap the read function (because = of VTIME) > > > > and immediately after that CancelIO is called. Contrary to what is = mentioned > > > > in the source code I think CancelIO is actually discarding data... > > > So far we didn't have that experience. CancelIO is usually safe > > > in this regard. > The data is MIA somehow... Yes, but we're calling CancelIo in other circumstances in Cygwin and there were no reports of missing data. CancelIo is just supposed to terminate the currently running overlapped IO, not to discard any in-flight data. If that's different for serial IO, there would be no way to terminate serial overlapped IO gracefully. Well, yeah, it's Windows, but still... > > > > -=C2=A0=C2=A0=C2=A0 if ((vmin_ > 0) && (vtime_ =3D=3D 0)) > > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (is_nonblocking()) > > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 { > > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 to.ReadIntervalTimeout =3D MAXDWORD; > > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > > > > +=C2=A0=C2=A0=C2=A0 else if ((vmin_ > 0) && (vtime_ =3D=3D 0)) > > > What if you switch to !O_NONBLOCK after calling tcsetattr? The > > > setting of ReadIntervalTimeout would be lost then. > > >=20 > > > Either we have to repeat calling SetCommTimeouts every time > > > we switch mode, or we have to do the above setting temporary > > > every time we call ReadFile in non blocking mode. > True. > > What about this: > >=20 > > diff --git a/winsup/cygwin/fhandler_serial.cc b/winsup/cygwin/fhandler_= serial.cc > > --- a/winsup/cygwin/fhandler_serial.cc > > +++ b/winsup/cygwin/fhandler_serial.cc > > @@ -68,6 +68,16 @@ fhandler_serial::raw_read (void *ptr, size_t& ulen) > > goto err; > > else if (ev) > > termios_printf ("error detected %x", ev); > > + else if (is_nonblocking ()) > > + { > > + if (!st.cbInQue) > > + { > > + tot =3D -1; > > + set_errno (EAGAIN); > > + goto out; > > + } > > + inq =3D st.cbInQue; > > + } > > else if (st.cbInQue && !vtime_) > > inq =3D st.cbInQue; > > else if (!is_nonblocking () && !overlapped_armed) >=20 > Looks promising. I will try it. >=20 > BTW there is a gremlin in the "else if (ev)" line.... A gremlin? Would you mind to explain? Btw., if you find a bug in the code, we do take patches :) https://cygwin.com/contrib.html Thanks, Corinna --=20 Corinna Vinschen Cygwin Maintainer --4jXrM3lyYWu4nBt5 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAl5rXJ8ACgkQ9TYGna5E T6AefRAAibV5MzaFKXnQ62SDtMndBB1uWiksMykgKtaDOyYYoGB5dyHtp/U3sZoi Nolmjcq0S1IcIgGF0m9aS8oNbo7cGtSRanOfNkOjibEvNcVg9FlU0XzHUB3uCpYF uZeCGn1nrLodv0uhrqYapAX9vukqRvbmjM5j4ItBAe6+cIfMyszhIcg79dxduRTM OegKc+TR+3Vz5IpMyLcE5yfUi3USZr0UUIkEfVoijwadLpYe+qNdjAikuxPG+K+8 EMVMUamAg4B6U1Ky+6Jt9pj+tRuQVU4mt1uhu3dCirynKvBA5IbMoT6Jxye3PLXC NCfFvgb68nTGGq6qEWZx+xDvNO0WFWMgD+WKMU3IJSQIWb9dONHr9ZoV1jpA1Oep YhIe9+E9ZIJmsP2q4ACNANvDuVwgaONTfDvfk+f68fdA3Ty1Hv5pnJbiX45ILtYr fdTXNn5HK7Dt7zFNKysvuptHQ8skSA75VWULWyPuJAtvGW1OY2ybFgeUF+/Nyuow FqY4DAgFqp5v42M2gTQA0XhM2Bio+9hxowzPmb7xo7PiPQLzOverp2z85jeHOJJg RZLvwSyXGIbb4FcSyF0nTWC6T5bgyJJP6jYR57l8Q69FfQghb9x2ZaHhUfcIS5wB PxmMbzBqyuFvpA2EY7LDI/maN6W4F/S3BbqTqZ+G50qPLgwKxyQ= =p84u -----END PGP SIGNATURE----- --4jXrM3lyYWu4nBt5--