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>
The `examples/` directory was never built. The documentation however
indicated the existence of an `--enable-examples` option, which didn't
really exist. This patch adds that option.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
If an I/O watcher callback fails to read(), returning zero, we check
events for UEV_HUP to detect EOF or socket remote end shutdown().
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This patch adds UEV_ERROR handling to the test I/O watcher, restarting
the watcher properly. Also, additional error handling to read(), which
was unchecked and failed when fuzzing the libc read() function.
We also take the opportunity to document the reasons for when using the
w->fd (watcher descriptor) and when *not* to in the test. Even to the
author this was confusing and looked suspicious.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Many users look at both examples *and* unit tests to learn how to use a
library. We should pride ourselves in that we have not just working but
also correct and readable tests.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
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>
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>
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>
With distcheck we not only build the distribution files, but also runs
test suite and verifies that the resulting dist file(s) can be built.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
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>
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>
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>
We want to continue running the event loop until it is exited properly,
not if the callback for stdin detects a short read.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
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>