public inbox for cygwin-cvs@sourceware.org help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org> To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Revert "Cygwin: serial: read: if VMIN > 0, wait for VMIN chars in inbound queue" Date: Thu, 26 Mar 2020 11:27:06 +0000 (GMT) [thread overview] Message-ID: <20200326112706.F019D385E035@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=009c7a0553b6d59f0d5ed79210069a9c7c336184 commit 009c7a0553b6d59f0d5ed79210069a9c7c336184 Author: Corinna Vinschen <corinna@vinschen.de> Date: Wed Mar 25 21:01:29 2020 +0100 Revert "Cygwin: serial: read: if VMIN > 0, wait for VMIN chars in inbound queue" This reverts commit 082f2513c721e942d0fd563c4dc9117eee3513ab. 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> Diff: --- winsup/cygwin/fhandler_serial.cc | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/winsup/cygwin/fhandler_serial.cc b/winsup/cygwin/fhandler_serial.cc index 3fd8a974c..9446315e5 100644 --- a/winsup/cygwin/fhandler_serial.cc +++ b/winsup/cygwin/fhandler_serial.cc @@ -34,20 +34,19 @@ void __reg3 fhandler_serial::raw_read (void *ptr, size_t& ulen) { OVERLAPPED ov = { 0 }; - DWORD io_err, event; + DWORD io_err; COMSTAT st; DWORD bytes_to_read, read_bytes; ssize_t tot = 0; - bool wait_for_vmin, ret; if (ulen > SSIZE_MAX) ulen = SSIZE_MAX; if (ulen == 0) return; - /* If MIN > 0 in blocking mode, we have to wait for at least MIN chars. - Otherwise we're in polling mode and there's no minimum chars. */ - ssize_t minchars = is_nonblocking () ? 0 : vmin_; + /* 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. */ + ssize_t minchars = (!is_nonblocking () && vmin_) ? MIN (vmin_, ulen) : 0; 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 { - wait_for_vmin = false; - /* First check if chars are already in the inbound queue. */ if (!ClearCommError (get_handle (), &io_err, &st)) goto err; @@ -85,22 +82,14 @@ fhandler_serial::raw_read (void *ptr, size_t& ulen) and don't wait. */ if (st.cbInQue && st.cbInQue >= minchars) 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); - if (wait_for_vmin) - ret = WaitCommEvent (get_handle (), &event, &ov); - else - ret = ReadFile (get_handle (), ptr, bytes_to_read, &read_bytes, &ov); - if (!ret) + if (!ReadFile (get_handle (), ptr, bytes_to_read, &read_bytes, &ov)) { if (GetLastError () != ERROR_IO_PENDING) goto err; - if (!wait_for_vmin && is_nonblocking ()) + if (is_nonblocking ()) { CancelIo (get_handle ()); 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); - ulen -= read_bytes; - minchars -= read_bytes; - debug_printf ("vtime_ %u, vmin_ %u, read_bytes %u, tot %D", - vtime_, vmin_, read_bytes, tot); - } + tot += read_bytes; + ptr = (void *) ((caddr_t) ptr + read_bytes); + ulen -= read_bytes; + minchars -= read_bytes; + debug_printf ("vtime_ %u, vmin_ %u, read_bytes %u, tot %D", + vtime_, vmin_, read_bytes, tot); continue; err:
reply other threads:[~2020-03-26 11:27 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200326112706.F019D385E035@sourceware.org \ --to=corinna@sourceware.org \ --cc=cygwin-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).