X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=bertos%2Fkern%2Fkfile.c;h=81cd9d0a422d941717250c0e84cdb3c71d166ce5;hb=c45e4cce0b0aa72809f868441979e122b6ad97d5;hp=5a44019d6914148c4e0a888419aea6b6905e9947;hpb=4c1123f234a975a1c041054ea183e5b0bd20015a;p=bertos.git 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; + } + + } +} + +