src/signals.h
branchnew-lib-errors
changeset 217 7728d6ec3abf
parent 216 a10ba529ae39
child 218 5229a5d098b2
equal deleted inserted replaced
216:a10ba529ae39 217:7728d6ec3abf
     1 #ifndef SIGNALS_H
       
     2 #define SIGNALS_H
       
     3 
       
     4 /**
       
     5  * @file 
       
     6  *
       
     7  * Handle signals in a libevent way
       
     8  */
       
     9 #include "error.h"
       
    10 #include <event2/event.h>
       
    11 
       
    12 /**
       
    13  * How many signals we can define actions for
       
    14  */
       
    15 #define MAX_SIGNALS 8
       
    16 
       
    17 /**
       
    18  * State for a set of signals
       
    19  */
       
    20 struct signals;
       
    21 
       
    22 /**
       
    23  * Used as a handler for signals that should cause a loopexit.
       
    24  */
       
    25 void signals_loopexit (int signal, short event, void *arg);
       
    26 
       
    27 /**
       
    28  * Used to receive signals, but discard them, and continue what we were doing.
       
    29  */
       
    30 void signals_ignore (int signal, short event, void *arg);
       
    31 
       
    32 /**
       
    33  * Allocate a signals struct, acting on the given ev_base.
       
    34  *
       
    35  * Returns NULL on failure
       
    36  */
       
    37 err_t signals_create (struct signals **signals_ptr, struct event_base *ev_base);
       
    38 
       
    39 /**
       
    40  * Add a signal to be handled by the given signals struct with the given handler.
       
    41  */
       
    42 err_t signals_add (struct signals *signals, int sigval, void (*sig_handler)(evutil_socket_t, short, void *), void *arg);
       
    43 
       
    44 /**
       
    45  * Ignore the given sigval.
       
    46  */
       
    47 err_t signal_ignore (int signum, struct error_info *err);
       
    48 
       
    49 /**
       
    50  * Add a set of default signals
       
    51  *      SIGPIPE     signals_ignore
       
    52  *      SIGINT      signals_loopexit
       
    53  */
       
    54 struct signals *signals_default (struct event_base *ev_base);
       
    55 
       
    56 /**
       
    57  * Free the resources/handlers associated with the given signal handler set
       
    58  */
       
    59 void signals_free (struct signals *signals);
       
    60 
       
    61 #endif /* SIGNALS_H */