From 170ce567ce5710f5d33822429b4309a69a8fb573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 26 Feb 2016 23:19:03 +0100 Subject: [PATCH] Fixed timeout issues --- src/c/event.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/c/event.c b/src/c/event.c index 02f82c3..7852295 100644 --- a/src/c/event.c +++ b/src/c/event.c @@ -40,7 +40,11 @@ static void handleStdin(evutil_socket_t fd, short what, void *ptr) { } void event_prepare() { - base = event_base_new(); + struct event_config* cfg = event_config_new(); + event_config_set_flag(cfg, EVENT_BASE_FLAG_NO_CACHE_TIME); + + base = event_base_new_with_config(cfg); + evutil_make_socket_nonblocking(STDIN_FILENO); event_assign(&stdinEvent, base, STDIN_FILENO, EV_READ, handleStdin, NULL); } @@ -48,18 +52,17 @@ static void add_events(struct timeval* timeout) { event_add(&stdinEvent, timeout); } + int event_pull(int _timeout) { if(_timeout > 0) { /* wait max this much time for event */ - struct timeval timeout = {_timeout / 1000, (_timeout % 1000) * 1000000}; + struct timeval timeout = {_timeout / 1000, (_timeout % 1000) * 1000}; add_events(&timeout); - /* event_base_loopexit(base, &timeout); */ event_base_loop(base, EVLOOP_ONCE); } else if(_timeout == 0) { /* Get event without blocking */ add_events(NULL); event_base_loop(base, EVLOOP_ONCE | EVLOOP_NONBLOCK); } else { /* wait for event to appear */ add_events(NULL); - event_base_loopexit(base, NULL); event_base_loop(base, EVLOOP_ONCE); }