Revert "Cygwin: serial: read: if VMIN > 0, wait for VMIN chars in inbound queue"

This reverts commit 082f2513c7.

Turns out, Linux as well as BSD really only wait for the smaller
number, MIN or # of requested bytes.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2020-03-25 21:01:29 +01:00
parent 8ffe12b394
commit 009c7a0553
1 changed files with 12 additions and 26 deletions

View File

@ -34,20 +34,19 @@ void __reg3
fhandler_serial::raw_read (void *ptr, size_t& ulen) fhandler_serial::raw_read (void *ptr, size_t& ulen)
{ {
OVERLAPPED ov = { 0 }; OVERLAPPED ov = { 0 };
DWORD io_err, event; DWORD io_err;
COMSTAT st; COMSTAT st;
DWORD bytes_to_read, read_bytes; DWORD bytes_to_read, read_bytes;
ssize_t tot = 0; ssize_t tot = 0;
bool wait_for_vmin, ret;
if (ulen > SSIZE_MAX) if (ulen > SSIZE_MAX)
ulen = SSIZE_MAX; ulen = SSIZE_MAX;
if (ulen == 0) if (ulen == 0)
return; return;
/* If MIN > 0 in blocking mode, we have to wait for at least MIN chars. /* If MIN > 0 in blocking mode, we have to read at least VMIN chars,
Otherwise we're in polling mode and there's no minimum chars. */ otherwise we're in polling mode and there's no minimum chars. */
ssize_t minchars = is_nonblocking () ? 0 : vmin_; ssize_t minchars = (!is_nonblocking () && vmin_) ? MIN (vmin_, ulen) : 0;
debug_printf ("ulen %ld, vmin_ %u, vtime_ %u", ulen, vmin_, vtime_); debug_printf ("ulen %ld, vmin_ %u, vtime_ %u", ulen, vmin_, vtime_);
@ -55,8 +54,6 @@ fhandler_serial::raw_read (void *ptr, size_t& ulen)
do do
{ {
wait_for_vmin = false;
/* First check if chars are already in the inbound queue. */ /* First check if chars are already in the inbound queue. */
if (!ClearCommError (get_handle (), &io_err, &st)) if (!ClearCommError (get_handle (), &io_err, &st))
goto err; goto err;
@ -85,22 +82,14 @@ fhandler_serial::raw_read (void *ptr, size_t& ulen)
and don't wait. */ and don't wait. */
if (st.cbInQue && st.cbInQue >= minchars) if (st.cbInQue && st.cbInQue >= minchars)
bytes_to_read = MIN (st.cbInQue, bytes_to_read); bytes_to_read = MIN (st.cbInQue, bytes_to_read);
/* Otherwise, if MIN > 0, TIME == 0, we have to wait until
MIN bytes are available in the inbound queue. */
else if (minchars && !vtime_)
wait_for_vmin = true;
} }
ResetEvent (ov.hEvent); ResetEvent (ov.hEvent);
if (wait_for_vmin) if (!ReadFile (get_handle (), ptr, bytes_to_read, &read_bytes, &ov))
ret = WaitCommEvent (get_handle (), &event, &ov);
else
ret = ReadFile (get_handle (), ptr, bytes_to_read, &read_bytes, &ov);
if (!ret)
{ {
if (GetLastError () != ERROR_IO_PENDING) if (GetLastError () != ERROR_IO_PENDING)
goto err; goto err;
if (!wait_for_vmin && is_nonblocking ()) if (is_nonblocking ())
{ {
CancelIo (get_handle ()); CancelIo (get_handle ());
if (!GetOverlappedResult (get_handle (), &ov, &read_bytes, if (!GetOverlappedResult (get_handle (), &ov, &read_bytes,
@ -145,15 +134,12 @@ fhandler_serial::raw_read (void *ptr, size_t& ulen)
} }
} }
} }
if (!wait_for_vmin) tot += read_bytes;
{ ptr = (void *) ((caddr_t) ptr + read_bytes);
tot += read_bytes; ulen -= read_bytes;
ptr = (void *) ((caddr_t) ptr + read_bytes); minchars -= read_bytes;
ulen -= read_bytes; debug_printf ("vtime_ %u, vmin_ %u, read_bytes %u, tot %D",
minchars -= read_bytes; vtime_, vmin_, read_bytes, tot);
debug_printf ("vtime_ %u, vmin_ %u, read_bytes %u, tot %D",
vtime_, vmin_, read_bytes, tot);
}
continue; continue;
err: err: