Commit Graph
10 Commits
Author SHA1 Message Date
NefelibateLG 28643fa599 Return from uev_run() when UEV_NONBLOCK and no event is pending
uev_run() with only UEV_NONBLOCK never returns when there are watchers
but no events, it spins at full CPU load:

    uev_run(ctx, UEV_NONBLOCK);

The loop polls epoll with a zero timeout and only stops on UEV_ONCE.

Leave the loop when a nonblocking poll finds no events.
2026-11-16 15:08:42 +01:00
omrzk 09d9b6ba04 Keep timer deadlines between calls to uev_run()
Timers never expire when the event loop is run one iteration at a time
and something else keeps it busy, e.g., when polled from another event
loop:

    uev_run(ctx, UEV_ONCE | UEV_NONBLOCK);

Every call to uev_run() starts all timers over from their full timeout.

Start dormant timers on the first call only.  A caller that wants a
timer restarted for each call must now use uev_timer_set().

Closes #36
2026-11-16 15:08:41 +01:00
NefelibateLG 4792b988a1 Fix eventfd leak in uev_event_init()
uev_event_init() leaks its eventfd, and leaves it in the watcher, when
the watcher cannot be added to the event loop.

Close it and reset the descriptor in the watcher.
2026-11-16 14:54:49 +01:00
NefelibateLG ae28276f3f Fix restart of a stopped cron watcher
uev_cron_start() on a stopped cron watcher brings it back as a regular
timer, with a timeout made up of parts of the cron schedule.  It calls
uev_timer_start(), which reads the timer fields of the watcher and
creates a monotonic timer.

Restart with uev_cron_set() and the cron schedule instead.
2026-11-16 14:54:48 +01:00
omrzk e699cb7f5f 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
2026-11-16 14:54:47 +01:00
omrzk fbe2c15377 Honor new descriptor and events in uev_io_set()
uev_io_set() on an active oneshot watcher keeps watching the old
descriptor, for the old events:

    uev_io_set(w, newfd, UEV_READ | UEV_ONESHOT);

It only rearms the watcher, with what is already stored in it.

Rearm only when neither has changed, otherwise stop the watcher and set
it up again.

Closes #35
2026-11-16 14:54:46 +01:00
Joachim Wiberg 02832543e3 test: use AM_LDFLAGS for linker args to test programs
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 08:13:21 +02:00
Joachim Wiberg c8d1de10a3 test: prefix CFLAGS/CPPFLAGS with AM_ to avoid clash with Fedora
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-03 07:40:06 +02:00
Joachim Wiberg 0e0291f85e Fix #25: apps must be built with 64-bit time, just like the lib
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-02 17:21:17 +02:00
Joachim Wiberg caa62910db Relocate tests/ -> test/
For my own sanity, test/ is used in every other project of mine.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-08-01 22:40:35 +02:00