diff --git a/ChangeLog b/ChangeLog index 0f54f7a..7be47e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,10 @@ 2021-02-12 NIIBE Yutaka + Backport from 2.1. * chopstx-gnu-linux.c (chopstx_create_arch): Clear TP. + * example-cdc-gnu-linux/usb-cdc.c (tty_recv): Cancel the input. + * example-cdc-gnu-linux/sample.c (main): Handle timeout by canceling + input. 2019-12-30 NIIBE Yutaka diff --git a/example-cdc-gnu-linux/sample.c b/example-cdc-gnu-linux/sample.c index 02d394d..d427a94 100644 --- a/example-cdc-gnu-linux/sample.c +++ b/example-cdc-gnu-linux/sample.c @@ -179,7 +179,14 @@ main (int argc, const char *argv[]) if (size < 0) goto connection_loop; - if (size == 1) + if (size == 0) + /* Timeout */ + { + if (tty_send (tty, "\r\n", 2) < 0) + return 0; + break; + } + else if (size == 1) /* Do nothing but prompt again. */ break; else if (size) diff --git a/example-cdc-gnu-linux/usb-cdc.c b/example-cdc-gnu-linux/usb-cdc.c index b742bfa..e1109b7 100644 --- a/example-cdc-gnu-linux/usb-cdc.c +++ b/example-cdc-gnu-linux/usb-cdc.c @@ -904,8 +904,18 @@ tty_recv (struct tty *t, char *buf, uint32_t *timeout) chopstx_mutex_lock (&t->mtx); r = check_rx (t); chopstx_mutex_unlock (&t->mtx); - if (r || (timeout != NULL && *timeout == 0)) + if (r) break; + else if (timeout != NULL && *timeout == 0) + { + int i; + + /* Cancel the input. */ + for (i = 0; i < t->inputline_len; i++) + tty_send (t, "\x08\x20\x08", 3); + t->inputline_len = 0; + break; + } } chopstx_mutex_lock (&t->mtx);