X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fkern%2Fkfile.c;h=81cd9d0a422d941717250c0e84cdb3c71d166ce5;hb=72c5f5cde2bc9ffe5427d65bb8f798bf8c4a0cce;hp=6a8cb2042333783c6155406df263905afcc79ecc;hpb=719258e4a9db3105b555920eca3970fdec5d5fc1;p=bertos.git diff --git a/bertos/kern/kfile.c b/bertos/kern/kfile.c index 6a8cb204..81cd9d0a 100644 --- a/bertos/kern/kfile.c +++ b/bertos/kern/kfile.c @@ -44,6 +44,7 @@ #include #include +#include #include #include @@ -196,10 +197,10 @@ kfile_off_t kfile_genericSeek(struct KFile *fd, kfile_off_t offset, KSeekMode wh } #if LOG_LEVEL >= LOG_LVL_INFO - /* Bound check */ + /* Bound check */ if (seek_pos + offset > fd->size) LOG_INFO("seek outside EOF\n"); - #endif + #endif fd->seek_pos = seek_pos + offset; @@ -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; + } + + } +} + +