src/lib/signals.h
changeset 61 9f7ecf7bf699
parent 3 10b53719659c
equal deleted inserted replaced
60:b17d2cf35504 61:9f7ecf7bf699
       
     1 #ifndef LIB_SIGNAL_H
       
     2 #define LIB_SIGNAL_H
       
     3 
       
     4 /*
       
     5  * Handle signals in a libevent-sane way
       
     6  */
       
     7 
       
     8 #include <event2/event.h>
       
     9 
       
    10 /*
       
    11  * How many signals we can define actions for
       
    12  */
       
    13 #define MAX_SIGNALS 8
       
    14 
       
    15 /*
       
    16  * info about a set of signals
       
    17  */
       
    18 struct signals;
       
    19 
       
    20 /*
       
    21  * Used as a handler for signals that should cause a loopexit.
       
    22  */
       
    23 void signals_loopexit (int signal, short event, void *arg);
       
    24 
       
    25 /*
       
    26  * Used to receive signals, but discard them.
       
    27  */
       
    28 void signals_ignore (int signal, short event, void *arg);
       
    29 
       
    30 /*
       
    31  * Allocate a signals struct, acting on the given ev_base.
       
    32  *
       
    33  * Returns NULL on failure
       
    34  */
       
    35 struct signals *signals_alloc (struct event_base *ev_base);
       
    36 
       
    37 /*
       
    38  * Add a signal to be handled by the given signals struct with the given handler.
       
    39  */
       
    40 int signals_add (struct signals *signals, int sigval, void (*sig_handler)(evutil_socket_t, short, void *));
       
    41 
       
    42 /*
       
    43  * Add a set of default signals
       
    44  *      SIGPIPE     signals_ignore
       
    45  *      SIGINT      signals_loopexit
       
    46  */
       
    47 struct signals *signals_default (struct event_base *ev_base);
       
    48 
       
    49 /*
       
    50  * Free the resources/handlers associated with the given signal handler
       
    51  */
       
    52 void signals_free (struct signals *signals);
       
    53 
       
    54 #endif /* LIB_SIGNAL_H */