Hi libevent-users, I noticed something odd and wanted to see if this is a bug or if I'm doing something wrong:
event_base's tv_cache is not getting cleared after event_base_loop() exits. Calling event_add() again much later can cause an expired timestamp to be registered. Background: I'm working on a program that uses libevent in this manner: 1) Start program and call event_init(). 2) Call event_set(), event_add() to monitor some connections. 3) Call event_dispatch() to start the event loop. 4) During event loop, callbacks are triggered which will eventually call event_del() on each connection when all the work is done. 5) event_dispatch() automatically returns when there are no more connections to process. 6) Program continues, time passes, unrelated stuff happens, and eventually we go back to step 2 again. Problem: event_base's tv_cache is cleared and set inside event_base_loop(). But tv_cache is not cleared when event_base_loop() returns. When we return to Step #2, we call event_add(). This calls gettime() which will use the tv_cache timestamp since it's non-zero now. This cached timestamp might be pretty old. event_add() calls evutil_timeradd() to compute the expiration timestamp, but the resulting expiration timestamp could already be in the past. When event_dispatch() gets called, it immediately thinks that the event has already timed out due to the old timestamp. Am I using libevent properly?: I'm relatively new to using libevent, so I wondered if I was doing something wrong :-) I suppose most typical libevent applications just sit in event_base_loop() forever until termination. In this typical case, the tv_cache is getting refreshed frequently enough so that it's not too old. (Assuming callbacks don't take excessively long) Intuitively, I would think that event_set/add() could get called before and during event_dispatch(). And when no more events need to be monitored, event_dispatch() returns and the event_base should be back in its "initial" state, ready to be reused if needed. Right now, it seems I'd have to call event_init() again to create a new event_base with a blank tv_cache. (Not to mention calling event_base_free() to dispose of the original event_base.) This seems like overkill... Your thoughts? Victor _______________________________________________ Libevent-users mailing list Libevent-users@monkey.org http://monkeymail.org/mailman/listinfo/libevent-users