forked from espressif/esp-idf
console: fix linenoiseProbe never timing out
Fixes a regression from 753a92952
: if cb was negative, read_bytes
overflowed, because the type was changed from int to size_t.
Also fixes incorrect timeout calculation: timeout_ms was 200, but
each iteration delayed for 10ms, and reduced timeout_ms by 1. This
made the effective timeout to be 2000ms.
This commit is contained in:
@@ -935,13 +935,17 @@ int linenoiseProbe(void) {
|
|||||||
|
|
||||||
/* Try to read response */
|
/* Try to read response */
|
||||||
int timeout_ms = 200;
|
int timeout_ms = 200;
|
||||||
|
const int retry_ms = 10;
|
||||||
size_t read_bytes = 0;
|
size_t read_bytes = 0;
|
||||||
while (timeout_ms > 0 && read_bytes < 4) { // response is ESC[0n or ESC[3n
|
while (timeout_ms > 0 && read_bytes < 4) { // response is ESC[0n or ESC[3n
|
||||||
usleep(10000);
|
usleep(retry_ms * 1000);
|
||||||
|
timeout_ms -= retry_ms;
|
||||||
char c;
|
char c;
|
||||||
int cb = read(stdin_fileno, &c, 1);
|
int cb = read(stdin_fileno, &c, 1);
|
||||||
|
if (cb < 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
read_bytes += cb;
|
read_bytes += cb;
|
||||||
timeout_ms--;
|
|
||||||
}
|
}
|
||||||
/* Restore old mode */
|
/* Restore old mode */
|
||||||
flags &= ~O_NONBLOCK;
|
flags &= ~O_NONBLOCK;
|
||||||
|
Reference in New Issue
Block a user