Skip to content

Instantly share code, notes, and snippets.

@Mistat
Created December 11, 2010 12:59
Show Gist options
  • Select an option

  • Save Mistat/737356 to your computer and use it in GitHub Desktop.

Select an option

Save Mistat/737356 to your computer and use it in GitHub Desktop.
libevent2 Catch SIGINT signal
/**
* libevent2 sample code
* Catch SIGINT signal
*/
#include <event2/event.h>
#include <stdio.h>
#include <stlib.h>
void sigint_event_function(evutil_socket_t fd, short what, void *arg)
{
struct event_base *base = (struct event_base*)arg;
printf("\nSIGINT\n");
event_base_loopexit(base, NULL);
}
int main (int argc, char** argv) {
struct event* sigint_event;
struct event_base *base = event_base_new();
sigint_event = evsignal_new(base, SIGINT, sigint_event_function, base);
event_add(sigint_event, NULL);
event_base_dispatch(base);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment