Cygwin: pty: Revise the code for timeout in term_has_pcon_cap().

- Sometimes timeout period in term_has_pcon_cap() may not be enough
  when the machine slows down for some reason. This patch eases the
  issue. In the new code, effective timeout period is expected to be
  extended as a result due to slowing-down the wait loop as well when
  the machine gets into busy.
This commit is contained in:
Takashi Yano via Cygwin-patches 2020-12-14 17:26:09 +09:00 committed by Corinna Vinschen
parent c2c33e4d67
commit 55eff668b8
1 changed files with 3 additions and 3 deletions

View File

@ -2651,7 +2651,7 @@ fhandler_pty_slave::term_has_pcon_cap (const WCHAR *env)
char *p; char *p;
int len; int len;
int x1, y1, x2, y2; int x1, y1, x2, y2;
DWORD t0; int wait_cnt = 0;
/* Check if terminal has ANSI escape sequence. */ /* Check if terminal has ANSI escape sequence. */
if (!has_ansi_escape_sequences (env)) if (!has_ansi_escape_sequences (env))
@ -2668,7 +2668,6 @@ fhandler_pty_slave::term_has_pcon_cap (const WCHAR *env)
ReleaseMutex (input_mutex); ReleaseMutex (input_mutex);
p = buf; p = buf;
len = sizeof (buf) - 1; len = sizeof (buf) - 1;
t0 = GetTickCount ();
do do
{ {
if (::bytes_available (n, get_handle ()) && n) if (::bytes_available (n, get_handle ()) && n)
@ -2680,9 +2679,10 @@ fhandler_pty_slave::term_has_pcon_cap (const WCHAR *env)
char *p1 = strrchr (buf, '\033'); char *p1 = strrchr (buf, '\033');
if (p1 == NULL || sscanf (p1, "\033[%d;%dR", &y1, &x1) != 2) if (p1 == NULL || sscanf (p1, "\033[%d;%dR", &y1, &x1) != 2)
continue; continue;
wait_cnt = 0;
break; break;
} }
else if (GetTickCount () - t0 > 40) /* Timeout */ else if (++wait_cnt > 100) /* Timeout */
goto not_has_csi6n; goto not_has_csi6n;
else else
Sleep (1); Sleep (1);