mirror of
https://github.com/troglobit/libuev.git
synced 2026-10-13 10:04:41 +00:00
Add support for signals using signalfd(2)
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
b1de765841
commit
1319f2ba5a
6 files changed
+190
-23
No files matched your search
@@ -23,8 +23,9 @@
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h> /* intptr_t */
|
||||
|
||||
#include "uev.h"
|
||||
@@ -54,6 +55,11 @@ static void periodic_task(uev_t *ctx __attribute__ ((unused)), uev_watcher_t *w
|
||||
fprintf(stderr, "|");
|
||||
}
|
||||
|
||||
static void signal_cb(uev_t *ctx __attribute__ ((unused)), uev_watcher_t *w, void *data __attribute__ ((unused)))
|
||||
{
|
||||
fprintf(stderr, w->signo == SIGINT ? "^Cv" : "^\v");
|
||||
}
|
||||
|
||||
static void pipe_read_cb(uev_t *ctx, uev_watcher_t *w __attribute__ ((unused)), void *data __attribute__ ((unused)))
|
||||
{
|
||||
int cnt;
|
||||
@@ -114,6 +120,10 @@ int main(void)
|
||||
/* Periodic background task */
|
||||
uev_timer_create(ctx, periodic_task, NULL, 200, 200);
|
||||
|
||||
/* Signal watchers, Ctrl-C => SIGINT, Ctrl-\ => SIGQUIT */
|
||||
uev_signal_create(ctx, signal_cb, NULL, SIGINT);
|
||||
uev_signal_create(ctx, signal_cb, NULL, SIGQUIT);
|
||||
|
||||
/* Start event loop */
|
||||
uev_run(ctx);
|
||||
|
||||
|
||||
Reference in new issue
Block a user