mirror of
https://github.com/troglobit/libuev.git
synced 2026-11-17 19:31:18 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f5841413e2 | ||
|
|
be89142b39 | ||
|
|
aedc189672 | ||
|
|
0b5461d5ff | ||
|
|
397247d567 | ||
|
|
28643fa599 | ||
|
|
09d9b6ba04 | ||
|
|
354cdcaf7a | ||
|
|
05bc6a0830 | ||
|
|
4792b988a1 | ||
|
|
ae28276f3f | ||
|
|
e699cb7f5f | ||
|
|
fbe2c15377 | ||
|
|
c964bbe8fb | ||
|
|
faf7667012 |
No files matched your search
@@ -0,0 +1,12 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
libuEv is a small project, as such we have no possibility to support older versions.
|
||||
The only supported version is the latest released on GitHub:
|
||||
|
||||
<https://github.com/troglobit/libuev/releases>
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Contact the project's main author and owner to report and discuss vulnerabilities.
|
||||
@@ -44,7 +44,7 @@ jobs:
|
||||
run: |
|
||||
make check || (cat test/test-suite.log; false)
|
||||
- name: Upload Test Results
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: libuev-test-${{ matrix.compiler }}
|
||||
path: test/*
|
||||
@@ -53,7 +53,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
container: debian:stable
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- name: Installing dependencies
|
||||
run: |
|
||||
apt-get update
|
||||
|
||||
@@ -25,7 +25,7 @@ jobs:
|
||||
--post-data "token=$TOKEN&project=${COVERITY_PROJ}&md5=1" \
|
||||
-O coverity-latest.tar.gz.md5
|
||||
echo "md5=$(cat coverity-latest.tar.gz.md5)" | tee -a $GITHUB_OUTPUT
|
||||
- uses: actions/cache@v3
|
||||
- uses: actions/cache@v4
|
||||
id: cache
|
||||
with:
|
||||
path: coverity-latest.tar.gz
|
||||
|
||||
+32
-1
@@ -4,6 +4,37 @@ Change Log
|
||||
All notable changes to the project are documented in this file.
|
||||
|
||||
|
||||
[UNRELEASED][]
|
||||
--------------
|
||||
|
||||
### Changes
|
||||
- Timers now keep their deadline between calls to `uev_run()`, they are
|
||||
only started by the first call. Previously every call restarted all
|
||||
timers, so with `UEV_ONCE` in a busy loop they never expired. Use
|
||||
`uev_timer_set()` to restart a timer for each call
|
||||
- `uev_run()` with only `UEV_NONBLOCK` now returns when no event is
|
||||
pending, previously it never returned and used 100% CPU
|
||||
- A cron watcher with start time zero now runs when the event loop is
|
||||
started, as documented, previously it never ran. This means that
|
||||
`uev_cron_set(w, 0, 0)` no longer disarms a cron watcher, it runs it
|
||||
now. Use `uev_cron_stop()` to stop it
|
||||
|
||||
### Fixes
|
||||
- Fix `uev_io_set()` ignoring a new file descriptor, or new events, for
|
||||
an active `UEV_ONESHOT` watcher
|
||||
- Fix `uev_run()` with `UEV_ONCE` not returning until end of file when
|
||||
stdin is redirected from a regular file
|
||||
- Fix `uev_cron_start()` restarting a stopped cron watcher as a regular
|
||||
timer, with the wrong timeout
|
||||
- Fix file descriptor leak in `uev_event_init()` when the watcher cannot
|
||||
be added to the event loop
|
||||
- Fix `uev_exit()` closing stdin after a failed `uev_init()`
|
||||
- Fix NULL pointer dereference in `uev_timer_init()` when called without
|
||||
a watcher
|
||||
- Fix `uev_cron_init()` and `uev_signal_init()` leaving a closed file
|
||||
descriptor in the watcher on failure
|
||||
|
||||
|
||||
[v2.4.1][] - 2024-01-04
|
||||
-----------------------
|
||||
|
||||
@@ -453,7 +484,7 @@ v0.0.1 - 2012-03-17
|
||||
Lua users mailing list.
|
||||
|
||||
|
||||
[UNRELEASED]: https://github.com/troglobit/libuev/compare/v2.4.0...HEAD
|
||||
[UNRELEASED]: https://github.com/troglobit/libuev/compare/v2.4.1...HEAD
|
||||
[v2.4.1]: https://github.com/troglobit/libuev/compare/v2.4.0...v2.4.1
|
||||
[v2.4.0]: https://github.com/troglobit/libuev/compare/v2.3.2...v2.4.0
|
||||
[v2.3.2]: https://github.com/troglobit/libuev/compare/v2.3.1...v2.3.2
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
AC_INIT(libuev, 2.4.1, https://github.com/troglobit/libuev/issues)
|
||||
AC_INIT(libuev, 2.5.0-dev, https://github.com/troglobit/libuev/issues)
|
||||
AC_CONFIG_AUX_DIR(aux)
|
||||
AM_INIT_AUTOMAKE([1.11 foreign dist-xz])
|
||||
AM_SILENT_RULES([yes])
|
||||
|
||||
+5
-2
@@ -168,8 +168,11 @@ result = uev_run(&ctx, UEV_NONE);
|
||||
```
|
||||
|
||||
With `flags` set to `UEV_ONCE` the event loop returns as soon as it has
|
||||
served the first event. If `flags` is set to `UEV_ONCE | UEV_NONBLOCK`
|
||||
the event loop returns immediately if no event is available.
|
||||
served the first event. With `UEV_NONBLOCK` the event loop returns as
|
||||
soon as no event is available, also when combined with `UEV_ONCE`.
|
||||
|
||||
Timers are started by the first call to `uev_run()` and keep their
|
||||
deadline between calls. Use `uev_timer_set()` to restart a timer.
|
||||
|
||||
```
|
||||
if (result < 0)
|
||||
|
||||
+24
-6
@@ -25,6 +25,7 @@
|
||||
#include <errno.h>
|
||||
#include <string.h> /* memset() */
|
||||
#include <sys/timerfd.h>
|
||||
#include <time.h> /* time() */
|
||||
#include <unistd.h> /* close(), read() */
|
||||
|
||||
#include "uev.h"
|
||||
@@ -67,6 +68,11 @@ int uev_cron_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, time_t when
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (!w || !ctx) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (when < 0 || interval < 0) {
|
||||
errno = ERANGE;
|
||||
return -1;
|
||||
@@ -83,6 +89,7 @@ int uev_cron_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, time_t when
|
||||
_uev_watcher_stop(w);
|
||||
exit:
|
||||
close(fd);
|
||||
w->fd = -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -92,9 +99,12 @@ int uev_cron_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, time_t when
|
||||
/**
|
||||
* Reset an at/cron job watcher
|
||||
* @param w Watcher to reset
|
||||
* @param when First point in time to call @p cb
|
||||
* @param when First point in time to call @p cb, zero for 'now'
|
||||
* @param interval For an at job this is zero, for cron the offset interval
|
||||
*
|
||||
* Note, unlike uev_timer_set() a @p when of zero does not disarm the
|
||||
* watcher, use uev_cron_stop() for that.
|
||||
*
|
||||
* @return POSIX OK(0) or non-zero with @p errno set on error.
|
||||
*/
|
||||
int uev_cron_set(uev_t *w, time_t when, time_t interval)
|
||||
@@ -110,12 +120,12 @@ int uev_cron_set(uev_t *w, time_t when, time_t interval)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Zero is 'now', when the event loop is started */
|
||||
if (!when && w->ctx->running)
|
||||
when = time(NULL);
|
||||
|
||||
/* Handle stopped timers */
|
||||
if (w->fd < 0) {
|
||||
/* Timer already stopped */
|
||||
if (!when && !interval)
|
||||
return 0;
|
||||
|
||||
if (uev_cron_init(w->ctx, w, (uev_cb_t *)w->cb, w->arg, when, interval))
|
||||
return -1;
|
||||
}
|
||||
@@ -144,7 +154,15 @@ int uev_cron_set(uev_t *w, time_t when, time_t interval)
|
||||
*/
|
||||
int uev_cron_start(uev_t *w)
|
||||
{
|
||||
return uev_timer_start(w);
|
||||
if (!w) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (-1 != w->fd)
|
||||
_uev_watcher_stop(w);
|
||||
|
||||
return uev_cron_set(w, w->u.c.when, w->u.c.interval);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+8
-2
@@ -57,8 +57,14 @@ int uev_event_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg)
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
|
||||
return _uev_watcher_init(ctx, w, UEV_EVENT_TYPE, cb, arg, fd, UEV_READ)
|
||||
|| _uev_watcher_start(w);
|
||||
if (_uev_watcher_init(ctx, w, UEV_EVENT_TYPE, cb, arg, fd, UEV_READ) ||
|
||||
_uev_watcher_start(w)) {
|
||||
close(fd);
|
||||
w->fd = -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -64,7 +64,8 @@ int uev_io_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int fd, int e
|
||||
*/
|
||||
int uev_io_set(uev_t *w, int fd, int events)
|
||||
{
|
||||
if ((events & UEV_ONESHOT) && _uev_watcher_active(w))
|
||||
if ((events & UEV_ONESHOT) && _uev_watcher_active(w) &&
|
||||
fd == w->fd && events == w->events)
|
||||
return _uev_watcher_rearm(w);
|
||||
|
||||
/* Ignore any errors, only to clean up anything lingering ... */
|
||||
|
||||
@@ -72,6 +72,7 @@ int uev_signal_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int signo
|
||||
_uev_watcher_stop(w);
|
||||
exit:
|
||||
close(fd);
|
||||
w->fd = -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
+7
-2
@@ -68,8 +68,8 @@ static void msec2tspec(int msec, struct timespec *ts)
|
||||
* period and restarted.
|
||||
*
|
||||
* A timer is automatically started if the event loop is already
|
||||
* running, otherwise it is kept on hold until triggered by calling
|
||||
* uev_run().
|
||||
* running, otherwise it is kept on hold until triggered by the first
|
||||
* call to uev_run().
|
||||
*
|
||||
* @see uev_timer_set
|
||||
* @return POSIX OK(0) or non-zero with @p errno set on error.
|
||||
@@ -78,6 +78,11 @@ int uev_timer_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, int timeou
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (!w || !ctx) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (timeout < 0 || period < 0) {
|
||||
errno = ERANGE;
|
||||
return -1;
|
||||
|
||||
@@ -226,6 +226,7 @@ int uev_init1(uev_ctx_t *ctx, int maxevents)
|
||||
maxevents = UEV_MAX_EVENTS;
|
||||
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
ctx->fd = -1;
|
||||
ctx->maxevents = maxevents;
|
||||
|
||||
return _init(ctx, 0);
|
||||
@@ -289,9 +290,12 @@ int uev_exit(uev_ctx_t *ctx)
|
||||
*
|
||||
* With @p flags set to ::UEV_ONCE the event loop returns after the first
|
||||
* event has been served, useful for instance to set a timeout on a file
|
||||
* descriptor. If @p flags also has the ::UEV_NONBLOCK flag set the event
|
||||
* loop will return immediately if no event is pending, useful when run
|
||||
* inside another event loop.
|
||||
* descriptor. With the ::UEV_NONBLOCK flag set the event loop returns
|
||||
* as soon as no event is pending, useful when run inside another event
|
||||
* loop.
|
||||
*
|
||||
* Timers are started by the first call and keep their deadline between
|
||||
* calls. Use uev_timer_set() to restart a timer.
|
||||
*
|
||||
* @return POSIX OK(0) upon successful termination of the event loop, or
|
||||
* non-zero on error.
|
||||
@@ -309,16 +313,17 @@ int uev_run(uev_ctx_t *ctx, int flags)
|
||||
if (flags & UEV_NONBLOCK)
|
||||
timeout = 0;
|
||||
|
||||
/* Start the event loop */
|
||||
/* Start the event loop and all dormant timers, first call only */
|
||||
if (!ctx->running) {
|
||||
ctx->running = 1;
|
||||
|
||||
/* Start all dormant timers */
|
||||
_UEV_FOREACH(w, ctx->watchers) {
|
||||
if (UEV_CRON_TYPE == w->type)
|
||||
uev_cron_set(w, w->u.c.when, w->u.c.interval);
|
||||
if (UEV_TIMER_TYPE == w->type)
|
||||
uev_timer_set(w, w->u.t.timeout, w->u.t.period);
|
||||
}
|
||||
}
|
||||
|
||||
while (ctx->running && ctx->watchers) {
|
||||
struct epoll_event ee[UEV_MAX_EVENTS];
|
||||
@@ -344,8 +349,11 @@ int uev_run(uev_ctx_t *ctx, int flags)
|
||||
}
|
||||
}
|
||||
|
||||
if (rerun)
|
||||
if (rerun) {
|
||||
if (flags & UEV_ONCE)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
ctx->workaround = 0;
|
||||
|
||||
while ((nfds = epoll_wait(ctx->fd, ee, maxevents, timeout)) < 0) {
|
||||
@@ -361,6 +369,9 @@ int uev_run(uev_ctx_t *ctx, int flags)
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (!nfds && (flags & UEV_NONBLOCK))
|
||||
break;
|
||||
|
||||
for (i = 0; ctx->running && i < nfds; i++) {
|
||||
struct signalfd_siginfo fdsi;
|
||||
ssize_t sz = sizeof(fdsi);
|
||||
@@ -409,11 +420,9 @@ int uev_run(uev_ctx_t *ctx, int flags)
|
||||
}
|
||||
|
||||
if (!w->u.c.interval)
|
||||
w->u.c.when = 0;
|
||||
uev_timer_stop(w);
|
||||
else
|
||||
w->u.c.when += w->u.c.interval;
|
||||
if (!w->u.c.when)
|
||||
uev_timer_stop(w);
|
||||
break;
|
||||
|
||||
case UEV_EVENT_TYPE:
|
||||
|
||||
@@ -3,7 +3,14 @@
|
||||
active
|
||||
api
|
||||
complete
|
||||
cronnow
|
||||
cronrun
|
||||
cronstart
|
||||
error
|
||||
io
|
||||
nonblock
|
||||
resume
|
||||
signal
|
||||
stdin
|
||||
timer
|
||||
event
|
||||
@@ -8,8 +8,15 @@ TESTS =
|
||||
TESTS += active
|
||||
TESTS += api
|
||||
TESTS += complete
|
||||
TESTS += cronnow
|
||||
TESTS += cronrun
|
||||
TESTS += cronstart
|
||||
TESTS += error
|
||||
TESTS += io
|
||||
TESTS += nonblock
|
||||
TESTS += resume
|
||||
TESTS += signal
|
||||
TESTS += stdin
|
||||
TESTS += timer
|
||||
TESTS += event
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/* Verifies that a cron watcher with start time zero runs now */
|
||||
#include "check.h"
|
||||
|
||||
static int fired;
|
||||
|
||||
static void cb(uev_t *w, void *arg, int events)
|
||||
{
|
||||
fired++;
|
||||
uev_exit(w->ctx);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uev_ctx_t ctx;
|
||||
uev_t w;
|
||||
|
||||
fail_unless(uev_init(&ctx) == 0);
|
||||
fail_unless(uev_cron_init(&ctx, &w, cb, NULL, 0, 0) == 0);
|
||||
|
||||
alarm(2);
|
||||
fail_unless(uev_run(&ctx, 0) == 0);
|
||||
fail_unless(fired == 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: t
|
||||
* c-file-style: "linux"
|
||||
* End:
|
||||
*/
|
||||
@@ -0,0 +1,29 @@
|
||||
/* Verifies that a stopped cron watcher can be started again */
|
||||
#include "check.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
time_t when = time(NULL) + 3600;
|
||||
uev_ctx_t ctx;
|
||||
uev_t cron;
|
||||
|
||||
fail_unless(uev_init(&ctx) == 0);
|
||||
fail_unless(uev_cron_init(&ctx, &cron, NULL, NULL, when, 3600) == 0);
|
||||
fail_unless(uev_cron_stop(&cron) == 0);
|
||||
fail_unless(!uev_cron_active(&cron));
|
||||
|
||||
fail_unless(uev_cron_start(&cron) == 0);
|
||||
fail_unless(uev_cron_active(&cron));
|
||||
fail_unless(cron.type == UEV_CRON_TYPE);
|
||||
fail_unless(cron.u.c.when == when);
|
||||
fail_unless(cron.u.c.interval == 3600);
|
||||
|
||||
return uev_exit(&ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: t
|
||||
* c-file-style: "linux"
|
||||
* End:
|
||||
*/
|
||||
@@ -0,0 +1,87 @@
|
||||
/* Verifies cleanup on failure to set up a context or watcher */
|
||||
#include "check.h"
|
||||
#include <signal.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
/* A failed uev_event_init() must not leak its eventfd */
|
||||
static void event_init(void)
|
||||
{
|
||||
uev_ctx_t ctx;
|
||||
uev_t w;
|
||||
int fd;
|
||||
|
||||
fail_unless(uev_init(&ctx) == 0);
|
||||
fail_unless(close(ctx.fd) == 0);
|
||||
|
||||
fd = dup(STDIN_FILENO);
|
||||
fail_unless(fd >= 0);
|
||||
close(fd);
|
||||
|
||||
fail_unless(uev_event_init(&ctx, &w, NULL, NULL) != 0);
|
||||
fail_unless(w.fd == -1);
|
||||
fail_unless(dup(STDIN_FILENO) == fd);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
/* A failed uev_init() must not leave stdin as the context descriptor */
|
||||
static void ctx_init(void)
|
||||
{
|
||||
struct rlimit old, lim;
|
||||
uev_ctx_t ctx;
|
||||
int rc;
|
||||
|
||||
fail_unless(getrlimit(RLIMIT_NOFILE, &old) == 0);
|
||||
lim = old;
|
||||
lim.rlim_cur = 0;
|
||||
fail_unless(setrlimit(RLIMIT_NOFILE, &lim) == 0);
|
||||
|
||||
rc = uev_init(&ctx);
|
||||
|
||||
fail_unless(setrlimit(RLIMIT_NOFILE, &old) == 0);
|
||||
fail_unless(rc == -1);
|
||||
fail_unless(ctx.fd == -1);
|
||||
}
|
||||
|
||||
/* A failed init must not leave a closed descriptor in the watcher */
|
||||
static void watcher_init(void)
|
||||
{
|
||||
uev_ctx_t ctx;
|
||||
uev_t w;
|
||||
|
||||
fail_unless(uev_init(&ctx) == 0);
|
||||
fail_unless(close(ctx.fd) == 0);
|
||||
|
||||
fail_unless(uev_cron_init(&ctx, &w, NULL, NULL, time(NULL) + 3600, 0) != 0);
|
||||
fail_unless(w.fd == -1);
|
||||
|
||||
fail_unless(uev_signal_init(&ctx, &w, NULL, NULL, SIGUSR1) != 0);
|
||||
fail_unless(w.fd == -1);
|
||||
}
|
||||
|
||||
/* Invalid arguments must not crash */
|
||||
static void null_init(void)
|
||||
{
|
||||
uev_ctx_t ctx;
|
||||
|
||||
fail_unless(uev_init(&ctx) == 0);
|
||||
fail_unless(uev_timer_init(&ctx, NULL, NULL, NULL, 100, 0) != 0);
|
||||
fail_unless(uev_cron_init(&ctx, NULL, NULL, NULL, time(NULL) + 3600, 0) != 0);
|
||||
fail_unless(uev_exit(&ctx) == 0);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
event_init();
|
||||
watcher_init();
|
||||
null_init();
|
||||
ctx_init();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: t
|
||||
* c-file-style: "linux"
|
||||
* End:
|
||||
*/
|
||||
@@ -0,0 +1,60 @@
|
||||
/* Verifies uev_io_set() on an active oneshot watcher */
|
||||
#include "check.h"
|
||||
#include <sys/socket.h>
|
||||
|
||||
static int fd = -1;
|
||||
static int ev;
|
||||
|
||||
static void cb(uev_t *w, void *arg, int events)
|
||||
{
|
||||
fd = w->fd;
|
||||
ev = events;
|
||||
}
|
||||
|
||||
static void run(uev_ctx_t *ctx)
|
||||
{
|
||||
fd = -1;
|
||||
ev = 0;
|
||||
fail_unless(uev_run(ctx, UEV_ONCE | UEV_NONBLOCK) == 0);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int a[2], b[2];
|
||||
uev_ctx_t ctx;
|
||||
uev_t w;
|
||||
|
||||
fail_unless(socketpair(AF_UNIX, SOCK_STREAM, 0, a) == 0);
|
||||
fail_unless(socketpair(AF_UNIX, SOCK_STREAM, 0, b) == 0);
|
||||
fail_unless(write(b[1], "b", 1) == 1);
|
||||
|
||||
fail_unless(uev_init(&ctx) == 0);
|
||||
fail_unless(uev_io_init(&ctx, &w, cb, NULL, a[0], UEV_READ | UEV_ONESHOT) == 0);
|
||||
|
||||
/* New descriptor */
|
||||
fail_unless(uev_io_set(&w, b[0], UEV_READ | UEV_ONESHOT) == 0);
|
||||
run(&ctx);
|
||||
fail_unless(fd == b[0]);
|
||||
|
||||
/* New events, same descriptor */
|
||||
fail_unless(uev_io_set(&w, a[0], UEV_WRITE | UEV_ONESHOT) == 0);
|
||||
run(&ctx);
|
||||
fail_unless(fd == a[0]);
|
||||
fail_unless(ev & UEV_WRITE);
|
||||
|
||||
/* Nothing new, only rearm */
|
||||
run(&ctx);
|
||||
fail_unless(fd == -1);
|
||||
fail_unless(uev_io_set(&w, a[0], UEV_WRITE | UEV_ONESHOT) == 0);
|
||||
run(&ctx);
|
||||
fail_unless(fd == a[0]);
|
||||
|
||||
return uev_exit(&ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: t
|
||||
* c-file-style: "linux"
|
||||
* End:
|
||||
*/
|
||||
@@ -0,0 +1,35 @@
|
||||
/* Verifies that UEV_NONBLOCK returns when no event is pending */
|
||||
#include "check.h"
|
||||
|
||||
static int fired;
|
||||
|
||||
static void cb(uev_t *w, void *arg, int events)
|
||||
{
|
||||
fired++;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uev_ctx_t ctx;
|
||||
uev_t w;
|
||||
|
||||
fail_unless(uev_init(&ctx) == 0);
|
||||
fail_unless(uev_event_init(&ctx, &w, cb, NULL) == 0);
|
||||
|
||||
alarm(2);
|
||||
fail_unless(uev_run(&ctx, UEV_NONBLOCK) == 0);
|
||||
fail_unless(fired == 0);
|
||||
|
||||
fail_unless(uev_event_post(&w) == 0);
|
||||
fail_unless(uev_run(&ctx, UEV_NONBLOCK) == 0);
|
||||
fail_unless(fired == 1);
|
||||
|
||||
return uev_exit(&ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: t
|
||||
* c-file-style: "linux"
|
||||
* End:
|
||||
*/
|
||||
@@ -0,0 +1,34 @@
|
||||
/* Verifies that timers keep their deadline between calls to uev_run() */
|
||||
#include "check.h"
|
||||
|
||||
static int fired;
|
||||
|
||||
static void cb(uev_t *w, void *arg, int events)
|
||||
{
|
||||
fired++;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uev_ctx_t ctx;
|
||||
uev_t w;
|
||||
int i;
|
||||
|
||||
fail_unless(uev_init(&ctx) == 0);
|
||||
fail_unless(uev_timer_init(&ctx, &w, cb, NULL, 50, 0) == 0);
|
||||
|
||||
for (i = 0; i < 15; i++) {
|
||||
fail_unless(uev_run(&ctx, UEV_ONCE | UEV_NONBLOCK) == 0);
|
||||
usleep(10000);
|
||||
}
|
||||
fail_unless(fired == 1);
|
||||
|
||||
return uev_exit(&ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: t
|
||||
* c-file-style: "linux"
|
||||
* End:
|
||||
*/
|
||||
@@ -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