Skip to content

Commit

Permalink
Cygwin: console: Make VMIN and VTIME work.
Browse files Browse the repository at this point in the history
Previously, VMIN and VTIME did not work at all. This patch fixes that.

Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
tyan0 authored and dscho committed Feb 13, 2024
1 parent 9bf75c4 commit c292b3d
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions winsup/cygwin/fhandler/console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1011,10 +1011,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;
Expand All @@ -1037,6 +1041,11 @@ fhandler_console::read (void *pv, size_t& buflen)
pthread::static_cancel_self ();
/*NOTREACHED*/
case WAIT_TIMEOUT:
if (copied_chars)
{
buflen = copied_chars;
return;
}
set_sig_errno (EAGAIN);
buflen = (size_t) -1;
return;
Expand Down Expand Up @@ -1082,19 +1091,20 @@ fhandler_console::read (void *pv, size_t& buflen)
}

/* 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;
Expand Down

0 comments on commit c292b3d

Please sign in to comment.