Commit Graph
58 Commits
Author SHA1 Message Date
Joachim Wiberg 0c8ff24353 Update .pc file with build reqs, issue #25
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-10-02 17:21:49 +02:00
Joachim Wiberg d7a8c7895b Fix #25: glibc >= 2.33 requires _FILE_OFFSET_BITS=64 with _TIME_BITS=64
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-08-01 22:37:01 +02:00
Joachim Wiberg e626d080d7 Update doc comments to proper doxygen syntax
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-06-13 23:27:08 +02:00
Joachim Wiberg 7b1e0eb551 Relocate most documentation to doc/
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-06-13 23:22:44 +02:00
Joachim Wiberg e20d37228d New siginfo member in uev_t for signal watchers
This patch adds support for exporting the signalfd_siginfo struct read
from the signal fd descriptor on signals.  This allows watcher callbacks
to, e.g., figure out who sent a signal.  See signalfd(2) for details on
struct signalfd_siginfo.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-18 09:57:57 +02:00
Joachim Wiberg 86e01be26e Update copyright years and maintainer surname
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-12 09:15:40 +01:00
Joachim Nilsson 5fd29f7241 Clarify documentation of uev_timer_start()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-20 15:27:12 +02:00
Joachim Nilsson e79d25bb42 Bump ABI version 2.1.0 --> 2.2.0
New eventfd() API added.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-04-06 13:30:07 +02:00
Joachim Nilsson a334d230a1 Update copyright years
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-04-06 12:45:50 +02:00
Joachim Nilsson 2a709f739d Reverse christmas tree and simplify a bit
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-04-06 12:45:29 +02:00
Joachim Nilsson 90048e5996 Add support for generic events using Linux eventfd
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-08 07:15:40 +02:00
Joachim Nilsson fd89af6ca1 Minor, fix old copy-paste error in comment
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-08 07:14:54 +02:00
Joachim Nilsson 6439a34670 Minor, reorder watchers a bit => same order in all functions
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-08 07:13:05 +02:00
Joachim Nilsson 17a765b957 Bump ABI version 2.0.2 --> 2.1.0
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-04 21:06:32 +02:00
Joachim Nilsson 6fa88eacb4 Add new API; uev_init1(ctx, maxevents) to cap event cache size
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-02 17:49:32 +02:00
Joachim Nilsson 32d3842f8a Fix issue with library not being rebuilt when header files change
Add header files to list of library dependencies.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-02 17:48:30 +02:00
Joachim Nilsson 574c463c9a Enforce -std=gnu11, which enables typeof() in GCC 4.8
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-09-27 19:10:09 +02:00
Joachim Nilsson e6b99da0f5 Refactor, replace BSD queue.h LIST_ macros with homegrown version
This patch replaces the BSD doubly linked list implementation with a
simplified homegrown version.  This not only reduces the dependency on
an external "library", but also greatly simplifies licensing and gives
us a clean name space that does not intrude on users who want to use
their own version of queue.h in their application that also includes
the libuEv header file.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-09-25 23:31:23 +02:00
Joachim Nilsson ebe3888d6f Minor, whitespace fixes
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-09-25 23:23:43 +02:00
Joachim Nilsson 99ef6eb884 Remove __attribute__ ((unused)), use -Wno-unused-parameter instead
The __attribute__ ((unused)) is useful sometimes to declare variables as
intended to be unused, e.g. in callback functions.  However, they tend
to clutter up the code making hard to read.  We therefore remove all
uses of it and instead set -Wno-unused-parameter.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-09-25 23:19:02 +02:00
Joachim Nilsson de89b6647d Update ChangeLog and bump ABI + release version for v2.1.3 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-09-06 22:03:16 +02:00
Joachim Nilsson cccaabfad5 Don't call uev_timer_set() when stopping timer, just close() it
The semantics for timerfd in Linux is to use close() to stop,
so no need for the extra overhead with uev_timer_set().

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-09-04 21:22:33 +02:00
Joachim Nilsson 6d33c56d0f Return early and OK if signal watcher is already stopped
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-09-04 07:16:01 +02:00
Joachim Nilsson d3e5900f73 Refactor, use LIST_FOREACH_SAFE() instead of while() in uev_exit()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-09-01 18:55:22 +02:00
Joachim Nilsson 856546f4c7 Refactor, simplify
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-28 21:36:47 +01:00
Joachim Nilsson cebe66e8a4 Update change logs and bump version for v2.1.1 release
Also bump ABI revision, code change.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-28 14:03:56 +01:00
Joachim Nilsson dd651ae791 Call watcher callback as last action for watcher, may delete itself
A watcher callback may be a timeout callback, or similar, that deletes
itself and the watcher.  So we should not dereference anything in the
watcher after the callback.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-28 13:53:10 +01:00
Joachim Nilsson a528405258 Minor, whitespace
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-28 13:50:50 +01:00
Joachim Nilsson dbf8c0dae2 Doc: a timer must have a non-zero timeout value to be armed properly
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-19 11:29:19 +01:00
Joachim Nilsson e35c065d77 uev.c: Stop I/O watcher immediately on EPOLLERR or EPOLLHUP
No need to check fd with fcntl().  On EPOLLERR the descriptor has an
error condition that must bed ACK'ed by the callback.  On EPOLLHUP
we got a hang-up on the remote end, usually a stream or pipe, either
way the callback must ACK this too, regardless.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-14 12:56:39 +01:00
Joachim Nilsson fbcd200fd5 uev.h: Remind hardcore devs about checking common errors in callback
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-14 12:56:39 +01:00
Joachim Nilsson 9df7cbfc52 uev_timer_stop(): Check if already stopped to prevent double close()
Both cron and regular timers were closed twice on uev_exit(), first
when iterating over all watchers, next after each cb() has run in
uev_run().  This patch adds a check if a watcher is active before
attempting to stop it (again).

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-14 12:17:41 +01:00
Joachim Nilsson 6cbeb057b8 uev_timer_init(): Mark fd as uninitialized on error
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-14 12:17:41 +01:00
Joachim Nilsson 853604a65a Reorder switch in same order as enum, +minor whitespace
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-14 12:17:37 +01:00
Joachim Nilsson 35a54ef75e Follow-up to 2f9cce9, handle I/O watchers similar to timer+signal
This patch is a follow-up to 2f9cce9, and a complete refactor of
fe8f3f1 which first introduced the EPOLLERR and EPOLLHUP handling.
Then mainly for managing errors and hangups on stream sockets.

Now, instead of trying to reopen the epoll() fd, and breaking out
hard from the event loop on catastrophic error,  we now delegate
I/O watcher EPOLLERR and EPOLLHUP to the watcher callback, just
like other watchers.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-14 12:16:23 +01:00
Joachim Nilsson 966f29c207 Refactor, multiple if() statements into a switch()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-13 17:01:55 +01:00
Joachim Nilsson 6bc1b88973 Refactor, main event loop cleanup and simplification
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-13 15:38:40 +01:00
Joachim Nilsson 7c86cc31f1 Reorder enum in order of first appearance in libuEv
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-13 15:02:06 +01:00
Joachim Nilsson d9f8caf0e8 Refactor 2f9cce9, stop timers and try to restart signal watchers
In 2f9cce9 the invalidate_watcher() function was introduced to stop
invalid timer/cron and signal watchers.  This patch refactors that
change to instead call the stop method for cron/timer and attempt to
restart failing signal watchers.

The cron/timer and signal watchers are quite different from regular
I/O watchers in that their internal "fd" is hidden from and not under
the control of the user, so we should try to handle them better.  For
the former two we cannot do much other than stop and call the user's
registered callback with UEV_ERROR, but for the latter we can at least
try to restart it.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-13 14:52:16 +01:00
Joachim Nilsson f5806a28c0 Bump ABI, major change in how uev_run() and callbacks work
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-11 16:46:03 +01:00
Joachim Nilsson f78348a92a uev_run(): Return unique error codes in case of actual error.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-10 23:40:49 +01:00
Joachim Nilsson 1037eed481 Minor simplification, result is never changed
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-10 22:25:12 +01:00
Joachim Nilsson 2f9cce9150 Do NOT exit event loop on timer/signal watcher error
This patch fixes a blocking issue discovered in the Finit project.
At shutdown, or when there is any problem with a timer or signal
watcher, the event loop is abruptly terminated.

Instead of unconditionally exiting the event loop on problems with a
single watcher, invalidate the watcher and run the callback one last
time with UEV_ERROR in the events argument.

This is a semantic change wrt. watchers and their callbacks, so the
major version number will be bumped accordingly to signal the severity
of this change.  From now on it is STRONGLY recommended that each call
back function check for UEV_ERROR.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-10 22:18:40 +01:00
Joachim Nilsson f3b3177963 Introduce UEV_ERROR, for unexpected error on timer+signal watchers
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-10 21:49:57 +01:00
Joachim Nilsson 0dfc9152bd uev_run(): Exit event loop as soon as there are no more watchers
The purpose of the event loop is to process events on all registered
watches.  When all watchers have completed the event loop should exit.

Having implemented a workaround for issue #12 in commit e0cebc3 it has
become evident we need to check the list of watchers at the beginning
of the event loop rather than the end, since the workaround skips past
the end.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-24 00:33:28 +02:00
Joachim Nilsson 61bb69795d Use FIONREAD to detect if stdin has data, safer than just select()
When handling the stdin redirect workaround we should use FIONREAD to
figure out if there is any data to read.

When there is no more data to read from stdin we remove the watcher from
internal bookkeeping but allow the callback to run one last time so it
can detect a short read.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-21 19:55:17 +02:00
Joachim Nilsson e0cebc33b1 Fix #12: Implement workaround for application < foo.txt
This patch implements a workaround for issue #12, i.e. when an I/O
watcher for redirected stdin is registered and causes epoll_ctl()
to return EPERM.

The workaround registers the watcher as `active = -1` and bypasses
the epoll_wait() call in the main loop until all data has been read
from stdin and the temporary -1 watcher(s) have completed.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-21 19:10:04 +02:00
Joachim Nilsson 704d7d5612 Refactor, leverage internal API
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-21 12:47:01 +02:00
Joachim Nilsson 6f5e6e5232 Make internal API more private
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-21 12:04:13 +02:00
Joachim Nilsson b67c62045f Improve documentation for event flags on init and callback
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-20 08:59:39 +02:00