From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin-patches@cygwin.com
Cc: Takashi Yano <takashi.yano@nifty.ne.jp>
Subject: [PATCH] Cygwin: console: Make VMIN and VTIME work.
Date: Tue, 13 Feb 2024 23:30:54 +0900 [thread overview]
Message-ID: <20240213143104.1899-2-takashi.yano@nifty.ne.jp> (raw)
Previously, VMIN and VTIME did not work at all. This patch fixes that.
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
---
winsup/cygwin/fhandler/console.cc | 26 ++++++++++++++++++--------
winsup/cygwin/release/3.5.1 | 2 ++
2 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/console.cc
index 1c8d383cd..b0907eb31 100644
--- a/winsup/cygwin/fhandler/console.cc
+++ b/winsup/cygwin/fhandler/console.cc
@@ -1131,10 +1131,14 @@ fhandler_console::read (void *pv, size_t& buflen)
push_process_state process_state (PID_TTYIN);
- int copied_chars = 0;
+ size_t copied_chars = 0;
- DWORD timeout = is_nonblocking () ? 0 : INFINITE;
+ DWORD timeout = is_nonblocking () ? 0 :
+ (get_ttyp ()->ti.c_lflag & ICANON ? INFINITE :
+ (get_ttyp ()->ti.c_cc[VMIN] == 0 ? 0 :
+ (get_ttyp ()->ti.c_cc[VTIME]*100 ? : INFINITE)));
+read_more:
while (!input_ready && !get_cons_readahead_valid ())
{
int bgres;
@@ -1157,6 +1161,11 @@ wait_retry:
pthread::static_cancel_self ();
/*NOTREACHED*/
case WAIT_TIMEOUT:
+ if (copied_chars)
+ {
+ buflen = copied_chars;
+ return;
+ }
set_sig_errno (EAGAIN);
buflen = (size_t) -1;
return;
@@ -1204,19 +1213,20 @@ wait_retry:
}
/* Check console read-ahead buffer filled from terminal requests */
- while (con.cons_rapoi && *con.cons_rapoi && buflen)
- {
- buf[copied_chars++] = *con.cons_rapoi++;
- buflen --;
- }
+ while (con.cons_rapoi && *con.cons_rapoi && buflen > copied_chars)
+ buf[copied_chars++] = *con.cons_rapoi++;
copied_chars +=
- get_readahead_into_buffer (buf + copied_chars, buflen);
+ get_readahead_into_buffer (buf + copied_chars, buflen - copied_chars);
if (!con_ra.ralen)
input_ready = false;
release_input_mutex ();
+ if (buflen > copied_chars && !(get_ttyp ()->ti.c_lflag & ICANON)
+ && copied_chars < get_ttyp ()->ti.c_cc[VMIN])
+ goto read_more;
+
#undef buf
buflen = copied_chars;
diff --git a/winsup/cygwin/release/3.5.1 b/winsup/cygwin/release/3.5.1
index 715fcf74d..e041f98f3 100644
--- a/winsup/cygwin/release/3.5.1
+++ b/winsup/cygwin/release/3.5.1
@@ -16,3 +16,5 @@ Fixes:
- Fix handle leak in pty master which occurs when non-cygwin process
is started in pty.
Addresses: https://github.com/msys2/msys2-runtime/issues/198
+
+- Fix the problem that VMIN and VTIME does not work at all in console.
--
2.43.0
reply other threads:[~2024-02-13 14:31 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=20240213143104.1899-2-takashi.yano@nifty.ne.jp \
--to=takashi.yano@nifty.ne.jp \
--cc=cygwin-patches@cygwin.com \
/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: link
Be 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).