delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2020/03/13/06:13:31

X-Recipient: archive-cygwin AT delorie DOT com
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
Date: Fri, 13 Mar 2020 11:12:47 +0100
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: Setting termios VMIN > 0 and VTIME > 0 on non blocking file
Message-ID: <20200313101247.GD512788@calimero.vinschen.de>
Mail-Followup-To: cygwin AT cygwin DOT com
References: <9e4c6428-59de-df07-9e33-44ba95d5497f AT gmail DOT com>
<20200312114041 DOT GJ4042 AT calimero DOT vinschen DOT de>
<365dd437-7553-eb4e-3253-aba3bab74895 AT gmail DOT com>
<20200312144445 DOT GP4042 AT calimero DOT vinschen DOT de>
<20200312150833 DOT GQ4042 AT calimero DOT vinschen DOT de>
<9e56e005-660b-373e-d557-9c8bc97c45ba AT gmail DOT com>
MIME-Version: 1.0
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 AT cygwin DOT com
X-Mailman-Version: 2.1.29
List-Id: Cygwin mailing list <cygwin.cygwin.com>
List-Unsubscribe: <http://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <http://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <http://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
Reply-To: cygwin AT cygwin DOT com
Errors-To: cygwin-bounces AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces AT cygwin DOT com>

--===============8467874328838463228==
Content-Type: multipart/signed; micalg=pgp-sha256;
	protocol="application/pgp-signature"; boundary="4jXrM3lyYWu4nBt5"
Content-Disposition: inline


--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--

--===============8467874328838463228==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

--
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

--===============8467874328838463228==--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019