From c45e4cce0b0aa72809f868441979e122b6ad97d5 Mon Sep 17 00:00:00 2001 From: asterix Date: Thu, 4 Dec 2008 17:55:11 +0000 Subject: [PATCH] Add the generic kfile resync. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1974 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/kern/kfile.c | 28 ++++++++++++++++++++++++++++ bertos/kern/kfile.h | 1 + 2 files changed, 29 insertions(+) diff --git a/bertos/kern/kfile.c b/bertos/kern/kfile.c index 5a44019d..81cd9d0a 100644 --- a/bertos/kern/kfile.c +++ b/bertos/kern/kfile.c @@ -44,6 +44,7 @@ #include #include +#include #include #include @@ -228,3 +229,30 @@ int kfile_genericClose(UNUSED_ARG(struct KFile *, fd)) }; +/** + * Discard input to resynchronize with remote end. + * + * Discard incoming data until the kfile_getc stops receiving + * characters for at least \a delay milliseconds. + * + * \note If the timeout occur, we reset the error before to + * quit. + */ +void kfile_resync(KFile *fd, mtime_t delay) +{ + ticks_t start_time = timer_clock(); + for(;;) + { + if(kfile_getc(fd) != EOF) + start_time = timer_clock(); + + if ((timer_clock() - start_time) > ms_to_ticks(delay)) + { + kfile_clearerr(fd); + break; + } + + } +} + + diff --git a/bertos/kern/kfile.h b/bertos/kern/kfile.h index b959b959..a42defdd 100644 --- a/bertos/kern/kfile.h +++ b/bertos/kern/kfile.h @@ -216,6 +216,7 @@ int kfile_printf(struct KFile *fd, const char *format, ...); int kfile_print(struct KFile *fd, const char *s); int kfile_gets(struct KFile *fd, char *buf, int size); int kfile_gets_echo(struct KFile *fd, char *buf, int size, bool echo); +void kfile_resync(KFile *fd, mtime_t delay); /** * Interface functions for KFile access. -- 2.25.1