Created
December 11, 2010 12:59
-
-
Save Mistat/737356 to your computer and use it in GitHub Desktop.
libevent2 Catch SIGINT signal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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