首页 > 代码库 > libevent(十二)信号事件

libevent(十二)信号事件

libevent通过socketpair实现对信号事件的监听。

event_base结构体有个成员sig,结构如下:

struct evsig_info {
    /* Event watching ev_signal_pair[1] */
    struct event ev_signal;
    /* Socketpair used to send notifications from the signal handler */
    evutil_socket_t ev_signal_pair[2];
    /* True iff we‘ve added the ev_signal event yet. */
    int ev_signal_added;
    /* Count of the number of signals we‘re currently watching. */
    int ev_n_signals_added;

    /* Array of previous signal handler objects before Libevent started
     * messing with them.  Used to restore old signal handlers. */
#ifdef _EVENT_HAVE_SIGACTION
    struct sigaction **sh_old;
#else
    ev_sighandler_t **sh_old;
#endif
    /* Size of sh_old. */
    int sh_old_max;
};

event_base还有个成员evsigsel,用来描述信号处理的底层逻辑,

libevent(十二)信号事件