src/spbot/signals.h
branchnew-lib-errors
changeset 217 7728d6ec3abf
parent 71 0a13030f795d
child 218 5229a5d098b2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/spbot/signals.h	Wed May 27 23:57:48 2009 +0300
@@ -0,0 +1,61 @@
+#ifndef SPBOT_SIGNALS_H
+#define SPBOT_SIGNALS_H
+
+/**
+ * @file 
+ *
+ * Some kind of convenience stuff to handle signals, but actually pretty crap.
+ */
+#include <lib/error.h>
+#include <event2/event.h>
+
+/**
+ * How many signals we can define actions for
+ */
+#define MAX_SIGNALS 8
+
+/**
+ * State for a set of signals
+ */
+struct signals;
+
+/**
+ * Used as a handler for signals that should cause a loopexit.
+ */
+void signals_loopexit (int signal, short event, void *arg);
+
+/**
+ * Used to receive signals, but discard them, and continue what we were doing.
+ */
+void signals_ignore (int signal, short event, void *arg);
+
+/**
+ * Allocate a signals struct, acting on the given ev_base.
+ *
+ * Returns NULL on failure
+ */
+err_t signals_create (struct signals **signals_ptr, struct event_base *ev_base);
+
+/**
+ * Add a signal to be handled by the given signals struct with the given handler.
+ */
+err_t signals_add (struct signals *signals, int sigval, void (*sig_handler)(evutil_socket_t, short, void *), void *arg);
+
+/**
+ * Ignore the given sigval.
+ */
+err_t signal_ignore (int signum, error_t *err);
+
+/**
+ * Add a set of default signals
+ *      SIGPIPE     signals_ignore
+ *      SIGINT      signals_loopexit
+ */
+struct signals *signals_default (struct event_base *ev_base);
+
+/**
+ * Free the resources/handlers associated with the given signal handler set
+ */
+void signals_free (struct signals *signals);
+
+#endif /* SPBOT_SIGNALS_H */