delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2020/03/12/07:41:24

X-Recipient: archive-cygwin AT delorie DOT com
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
Date: Thu, 12 Mar 2020 12:40:41 +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: <20200312114041.GJ4042@calimero.vinschen.de>
Mail-Followup-To: cygwin AT cygwin DOT com
References: <9e4c6428-59de-df07-9e33-44ba95d5497f AT gmail DOT com>
MIME-Version: 1.0
In-Reply-To: <9e4c6428-59de-df07-9e33-44ba95d5497f@gmail.com>
X-Provags-ID: V03:K1:tFcDgy+i/ppvl8vnAMSEsQ9jOjo/irHUbXDCNkOroRuN0kRkaRQ
grMLFqWAXcQVhWqQjkxWMgzlOHF6bAEM8/Q+lS1rynAWvdj4r59hnKL3/fjyjHJmcTfe2cu
Kvfy2m0v9Pr3t52u3XIw4qoz3RaPwHQaG8Q28IL17al/G0Ui5d0t2PawDOYXvG1+vYo3QyB
Ussv6KAIKtTDDz+2hMX4g==
X-UI-Out-Filterresults: notjunk:1;V03:K0:+p0GL7yrcb4=:Ox1+CL+K2nTAhy+WgFbN7c
/A/Px4niTb3/52/2b0sBphnCGCSQgv7tyoRWdSXEO+C2kuayqduDvFTxg0qu4hZ0YovhjWyNb
bramehY2meXu5IwypTGtFtr3edDfZ1PEzA+uCG9foIPQiVBSQi4Yo575jZVJT5RQYj9ejlrlB
dhskOsNPvuJrd4+w2xOuPWqYBxnOp88vCjPM8sKOOqilNHPA58X71VojAorWZLC1v9lUDR8H8
2fQYGuZgLpq4gCFygbhCgFRLq3HSGECVqxvK2VkqOxz6r/uftVJ/slecj4KcbsOy9O7gWrn6W
MjOjOsaimt3c+2/DaQgw50dyT68X1uOW1bfeZvTSHqdbhDmwy2c3rTGdrjLsQDaEpJewTvISq
Rg6haCDdrdjBoMSNF1IKdd041sqeuMEsPw9jH6gysb9N88iyAmuUfSB8ZEZoIpQ/dofWqKo6y
5LmR8OGE2NjuKnA27+nWJsKSo2LYkUH4L4Df00z7fI02BPBgdM3dRWSVCs0rEOmhwWbp4hclm
jSzGQ8DKrEq52vd2eJgXOzhnL3AbJlVfx///g+WJa+SW7zz5sW3QCchojXp4+jSsGItzqSRQO
HWOTheozxwicP9ZX28YtzInYWnZn49BDWiYmDtPz6L54giSFVgcyVcUP31Vr3lRgPln5Bm65i
jtzCbE9jEiK4oUETIEd98Jg4to4E2ikEjtJbL86DtTW5uP63m6EEChPcCBvTPWe9g2J1hx220
YcwHXSlHkxlfVp5VybhKD6YVdLbXsFuTIdBJMxCIl8gyluFgoLVq5TSO046MlVrA0ExOAdxdg
VqA7a1xxXGhfP7+qkWeTB1eESlYXf7ojSbRdS8lDZYSxzkx18w/XlaNSxzUJo+UDSmYMsqo
X-Spam-Status: No, score=-101.9 required=5.0 tests=BAYES_00,
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>

--===============4250735095685474437==
Content-Type: multipart/signed; micalg=pgp-sha256;
	protocol="application/pgp-signature"; boundary="1WN/MJ7JJGqVzwIW"
Content-Disposition: inline


--1WN/MJ7JJGqVzwIW
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hi =C3=85ke,

On Mar 11 21:48, =C3=85ke Rehnman via Cygwin wrote:
> Hello all,
>=20
> opening a file (serial port) with O_NONBLOCK and subsequently setting
> termios VMIN and VTIME > 0 makes read() never ever return any data (retur=
ns
> EAGAIN indefinitely).
>=20
> Don't ask my why one would want to do something like this but apparently =
the
> "screen" program think this is a good way of doing things...
>=20
> Nevertheless not returning any data ever seems wrong.
>=20
> Any insight on how it is supposed to work is welcome.

[Please note that I can't test this myself, so we may need a bit of
 back and forth over this issue]

For a start, can you please strace the problem with a simple
testcase,like this:

  $ strace -o serio.trace <yourtestcase>

and send the source of your testcase as well as the serio.trace file
here?  It may show at which point the error code is generated.

I inspected the serial I/O read function and I only see a subtil
difference in terms of VMIN/VTIME which doesn't seem to be the culprit
at first glance.  In O_NONBLOCK mode, the underlying Windows function
ReadFile is called unconditionally.  My current hunch is this:

- If VMIN>0 && VTIME>0, the Windows equivalent of tcsetattr is
  told that VMIN>0.

- So, assuming VMIN =3D=3D 2 in Windows.  If VTIME > 0, the Cygwin read
  function sets the number of bytes_to_read to 1 (this is old code,
  don't ask why).

- My assumption now is that the ReadFile function fails because it's
  supposed to return only 1 char, but VMIN is > 1.

There are two issues here.

- If my assumption is correct, the tcsetattr function must not
  set the Windows VMIN equivalent to !=3D 0 in the O_NONBLOCK case.

- Also, as mention above, if VTIME > 0, Cygwin's read sets the number of
  bytes_to_read to 1.   Weirdly, it does so even if there are more than
  1 byte in the inbound queue.  This sounds wrong to me.

Ok, that's for a start, let's see if we can fix this behaviour.


Thanks,
Corinna
 =20
--=20
Corinna Vinschen
Cygwin Maintainer

--1WN/MJ7JJGqVzwIW
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAl5qH7kACgkQ9TYGna5E
T6Bsog//TDAusaciLoA8EIYVVmSR7ysDEjJ0mQ6PPWUnG+rYLN86YCYnCIsKXtQs
Kmm6B6Qvd8ufE398cGOMkIFWLHpaLSKVBv6IiiOe3sD8WPNobk5oYdEqAechUUDv
TBS8SdyQ/tAtbiaZDi7EIcrpQD6ivEOc1MimPgxBcChpUQyvs6ntzZ9RbUoU6jOp
lafJpX31bShUSZSLmQALy6Cy2MlGW974PhGOQtbnTiLPtoIxF1TAReVc5YhzP5fW
lXMcrOYbsky5FX3NPYoPFKuUYpUKG9G3PIoDuy8Rd1qmz7KI2+bZV5q8X2tJe4EP
atwfIf755koc665jIVGfokBFPWm3xvbj364gsXcWQI6OznoZNClDclnmOkIqPc4X
kJD2RNum2ZxvmAq+iPZ1IsJgvI3oR6Yti5W/I4H7uO1JJRrSOmh1uAB0rWr27rl9
gubTi9doHBZ9d3obq8TzmFWR5Sj7pMP6GvxIqT5t0wl6ZBw025fx2mfilaVDFZ8f
rDbfriM1BxftMcIJuYPHRBYkpbFJyj77RdbPUZ8sij2/OiNZSaNqgXrXZCIOXvea
jmZ9oBvN9f0Cw1B3/e4nwRE4XmTlH2apx9LwTnWJcvE8qOXqcykeoF+W9V/h43t0
2Fz8WWlaUm8Qcy2jSfyW7OizkqItR/La7cp5HRft1asCJ1bHHxY=
=tW35
-----END PGP SIGNATURE-----

--1WN/MJ7JJGqVzwIW--

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

--===============4250735095685474437==--

- Raw text -


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