Created
December 18, 2017 21:01
-
-
Save azat/6359262d6e05c2b0e5030b19ae0a816f to your computer and use it in GitHub Desktop.
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
#include <event2/event.h> | |
#include <event2/thread.h> | |
#include <event2/util.h> | |
#include <stdlib.h> | |
#include <pthread.h> | |
#include <assert.h> | |
#include <unistd.h> | |
#include <string.h> | |
int test_ok; | |
struct event_base *base; | |
struct event *ev; | |
static void* del_wait_thread(void *arg) | |
{ | |
struct timeval tv_start, tv_end; | |
evutil_gettimeofday(&tv_start, NULL); | |
event_base_dispatch(base); | |
evutil_gettimeofday(&tv_end, NULL); | |
//test_timeval_diff_eq(&tv_start, &tv_end, 300); | |
return NULL; | |
} | |
static void | |
del_wait_cb(evutil_socket_t fd, short event, void *arg) | |
{ | |
printf("Sleeping: %i\n", test_ok); | |
usleep(300*1000); | |
if (test_ok < 10) | |
event_add(ev, NULL); | |
++test_ok; | |
} | |
static void | |
test_del_wait(void) | |
{ | |
pthread_t thread; | |
int pair[2]; | |
assert(!pipe(pair)); | |
ev = event_new(base, pair[0], EV_READ|EV_PERSIST, del_wait_cb, NULL); | |
const char TEST1[] = "foo bar"; | |
event_add(ev, NULL); | |
pthread_create(&thread, NULL, del_wait_thread, NULL); | |
if (write(pair[1], TEST1, strlen(TEST1)+1) < 0) { | |
perror("write"); | |
} | |
usleep(30*1000); | |
{ | |
struct timeval tv_start, tv_end; | |
evutil_gettimeofday(&tv_start, NULL); | |
puts("before del"); | |
event_del(ev); | |
puts("after del"); | |
evutil_gettimeofday(&tv_end, NULL); | |
//test_timeval_diff_eq(&tv_start, &tv_end, 270); | |
} | |
sleep(2); | |
assert(test_ok == 1); | |
} | |
int main(int argc, char **argv) | |
{ | |
evthread_use_pthreads(); | |
base = event_base_new(); | |
test_del_wait(); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With patch from libevent/libevent#529:
without