From f561db380be29e2db4e49d1196a73292c94c4e66 Mon Sep 17 00:00:00 2001 From: Anthony Pesch Date: Wed, 28 Aug 2013 13:48:12 -0700 Subject: updated test_stdin to work in SM shell --- tests/module/test_stdin.c | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to 'tests/module') diff --git a/tests/module/test_stdin.c b/tests/module/test_stdin.c index ab84fa77..4838d466 100644 --- a/tests/module/test_stdin.c +++ b/tests/module/test_stdin.c @@ -14,31 +14,40 @@ void main_loop(void *arg) char str[10] = {0}; int ret; - if (line == 0) { - ret = fgetc(stdin); - if (ret != EOF) putc(ret, stdout); - if (ret == '\n') line++; - } else if (line > 0) { - ret = scanf("%10s", str); - if (ret > 0) puts(str); - } + errno = 0; + while (errno != EAGAIN) { + if (line == 0) { + ret = fgetc(stdin); + if (ret != EOF) putc(ret, stdout); + if (ret == '\n') line++; + } else if (line > 0) { + ret = scanf("%10s", str); + if (ret > 0) puts(str); + } - if (ferror(stdin) && errno != EAGAIN) { - puts("error"); - exit(EXIT_FAILURE); - } + if (ferror(stdin) && errno != EAGAIN) { + puts("error"); + exit(EXIT_FAILURE); + } - if (feof(stdin)) { - puts("eof"); - exit(EXIT_SUCCESS); - } + if (feof(stdin)) { + puts("eof"); + exit(EXIT_SUCCESS); + } - clearerr(stdin); + clearerr(stdin); + } } int main(int argc, char const *argv[]) { fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK); + + // SM shell doesn't implement an event loop and therefor doesn't support + // emscripten_set_main_loop. However, its stdin reads are sync so it + // should exit out after calling main_loop once. + main_loop(NULL); + #if EMSCRIPTEN emscripten_set_main_loop(main_loop, 60, 0); #else -- cgit v1.2.3-18-g5258