mirror of
https://github.com/troglobit/libuev.git
synced 2026-11-17 19:31:18 +00:00
Honor UEV_ONCE when stdin is redirected from a file
With stdin redirected from a regular file, uev_run() with UEV_ONCE does
not return until end of file:
app < file.txt
The workaround for regular files, which epoll cannot watch, restarts
the loop before the UEV_ONCE check.
Check the flag there too.
Closes #37
This commit is contained in:
1 parent
fbe2c15377
commit
e699cb7f5f
4 files changed
+50
-1
No files matched your search
@@ -344,8 +344,11 @@ int uev_run(uev_ctx_t *ctx, int flags)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rerun)
|
if (rerun) {
|
||||||
|
if (flags & UEV_ONCE)
|
||||||
|
break;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
ctx->workaround = 0;
|
ctx->workaround = 0;
|
||||||
|
|
||||||
while ((nfds = epoll_wait(ctx->fd, ee, maxevents, timeout)) < 0) {
|
while ((nfds = epoll_wait(ctx->fd, ee, maxevents, timeout)) < 0) {
|
||||||
|
|||||||
@@ -6,5 +6,6 @@ complete
|
|||||||
cronrun
|
cronrun
|
||||||
io
|
io
|
||||||
signal
|
signal
|
||||||
|
stdin
|
||||||
timer
|
timer
|
||||||
event
|
event
|
||||||
@@ -11,6 +11,7 @@ TESTS += complete
|
|||||||
TESTS += cronrun
|
TESTS += cronrun
|
||||||
TESTS += io
|
TESTS += io
|
||||||
TESTS += signal
|
TESTS += signal
|
||||||
|
TESTS += stdin
|
||||||
TESTS += timer
|
TESTS += timer
|
||||||
TESTS += event
|
TESTS += event
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/* Verifies UEV_ONCE with stdin redirected from a regular file */
|
||||||
|
#include "check.h"
|
||||||
|
|
||||||
|
static int calls;
|
||||||
|
|
||||||
|
static void cb(uev_t *w, void *arg, int events)
|
||||||
|
{
|
||||||
|
char ch;
|
||||||
|
|
||||||
|
calls++;
|
||||||
|
read(w->fd, &ch, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
FILE *fp = tmpfile();
|
||||||
|
uev_ctx_t ctx;
|
||||||
|
uev_t w;
|
||||||
|
|
||||||
|
fail_unless(fp != NULL);
|
||||||
|
fail_unless(fputs("abc", fp) >= 0);
|
||||||
|
rewind(fp);
|
||||||
|
fail_unless(dup2(fileno(fp), STDIN_FILENO) == STDIN_FILENO);
|
||||||
|
|
||||||
|
fail_unless(uev_init(&ctx) == 0);
|
||||||
|
fail_unless(uev_io_init(&ctx, &w, cb, NULL, STDIN_FILENO, UEV_READ) == 0);
|
||||||
|
|
||||||
|
alarm(5);
|
||||||
|
fail_unless(uev_run(&ctx, UEV_ONCE) == 0);
|
||||||
|
fail_unless(calls == 1);
|
||||||
|
|
||||||
|
/* Without UEV_ONCE the rest is drained, including EOF */
|
||||||
|
fail_unless(uev_run(&ctx, 0) == 0);
|
||||||
|
fail_unless(calls == 4);
|
||||||
|
|
||||||
|
return uev_exit(&ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
Reference in new issue
Block a user