X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=libaltos%2Flibaltos_common.c;h=6f0cbe6137d898ce2998de3628eb46213cd78575;hb=af8f0b5892e01bdcf9fa4ca86a4752a8294992a1;hp=713a775c6f70c9acee6011705b5aa6256cd06bc2;hpb=54e8e033ccf47526e5ff08f93c105ef75334924e;p=fw%2Faltos diff --git a/libaltos/libaltos_common.c b/libaltos/libaltos_common.c index 713a775c..6f0cbe61 100644 --- a/libaltos/libaltos_common.c +++ b/libaltos/libaltos_common.c @@ -49,12 +49,17 @@ PUBLIC int altos_getchar(struct altos_file *file, int timeout) { int ret; + + file->busy = 1; while (file->in_read == file->in_used) { ret = altos_fill(file, timeout); if (ret) - return ret; + goto done; } - return file->in_data[file->in_read++]; + ret = file->in_data[file->in_read++]; +done: + file->busy = 0; + return ret; } PUBLIC int @@ -112,9 +117,16 @@ int altos_bt_port(struct altos_bt_device *device) { return BT_PORT_DEFAULT; } +#include + PUBLIC void altos_free(struct altos_file *file) { + int i; altos_close(file); + for (i = 0; i < 10 && file->busy; i++) { + struct timespec delay = { .tv_sec = 1, .tv_nsec = 0 }; + nanosleep(&delay, NULL); + } free(file); }