src/signals.h
author Tero Marttila <terom@fixme.fi>
Thu, 12 Mar 2009 23:54:03 +0200
changeset 48 4841f4398fd2
child 70 a9a4c5e6aa30
permissions -rw-r--r--
add irc_net_quit and signal handling
#ifndef SIGNALS_H
#define SIGNALS_H

/**
 * @file 
 *
 * Handle signals in a libevent way
 */
#include "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);

/*
 * 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
 */
void signals_free (struct signals *signals);

#endif /* LIB_SIGNAL_H */