From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 56F233858412; Tue, 13 Feb 2024 14:38:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 56F233858412 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1707835091; bh=meAFhhCiWg7NJ5TM8aLd7BTJzjwzDRsd8XeWOI/9tbU=; h=From:To:Subject:Date:From; b=NWUmtcEVU0RUhWeVamwD6VfW+hCQAp4kikHnahdhMIZ5OFCQF4LkLTKztkPA4qIHP sUoNFiduFCBwUza1m5k6VdiokAOJdQhTvPqUq25xAAW+7/9KezsWgqBQlZ4FGX0lb1 y+qtXELoA7CeKGZXgThzIGcTgfQ8lH8Xomi3z3T4= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: console: Make VMIN and VTIME work. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 8e24d162f4da6bad32712f902e4cc4d2f438d649 X-Git-Newrev: ac92c4c9f564eda3158c1c0742c0939e6152f769 Message-Id: <20240213143811.56F233858412@sourceware.org> Date: Tue, 13 Feb 2024 14:38:10 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Dac92c4c9f56= 4eda3158c1c0742c0939e6152f769 commit ac92c4c9f564eda3158c1c0742c0939e6152f769 Author: Takashi Yano Date: Tue Feb 13 11:42:42 2024 +0900 Cygwin: console: Make VMIN and VTIME work. =20 Previously, VMIN and VTIME did not work at all. This patch fixes that. =20 Signed-off-by: Takashi Yano Diff: --- 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/con= sole.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) =20 push_process_state process_state (PID_TTYIN); =20 - int copied_chars =3D 0; + size_t copied_chars =3D 0; =20 - DWORD timeout =3D is_nonblocking () ? 0 : INFINITE; + DWORD timeout =3D is_nonblocking () ? 0 : + (get_ttyp ()->ti.c_lflag & ICANON ? INFINITE : + (get_ttyp ()->ti.c_cc[VMIN] =3D=3D 0 ? 0 : + (get_ttyp ()->ti.c_cc[VTIME]*100 ? : INFINITE))); =20 +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 =3D copied_chars; + return; + } set_sig_errno (EAGAIN); buflen =3D (size_t) -1; return; @@ -1204,19 +1213,20 @@ wait_retry: } =20 /* Check console read-ahead buffer filled from terminal requests */ - while (con.cons_rapoi && *con.cons_rapoi && buflen) - { - buf[copied_chars++] =3D *con.cons_rapoi++; - buflen --; - } + while (con.cons_rapoi && *con.cons_rapoi && buflen > copied_chars) + buf[copied_chars++] =3D *con.cons_rapoi++; =20 copied_chars +=3D - get_readahead_into_buffer (buf + copied_chars, buflen); + get_readahead_into_buffer (buf + copied_chars, buflen - copied_chars); =20 if (!con_ra.ralen) input_ready =3D false; release_input_mutex (); =20 + if (buflen > copied_chars && !(get_ttyp ()->ti.c_lflag & ICANON) + && copied_chars < get_ttyp ()->ti.c_cc[VMIN]) + goto read_more; + #undef buf =20 buflen =3D 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.