aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2012-01-16 04:25:48 +0000
committerMatthew Wild <mwild1@gmail.com>2012-01-16 04:25:48 +0000
commit2e7ed3132883509ef86b70bf52fb7affa6322ab3 (patch)
tree8a591c64f89e9598c13dd4e2e1c075111a3496a8 /src
parentbe5260d0af0b9fc3f10dce9813e362eda66eba51 (diff)
downloadluaevent-prosody-2e7ed3132883509ef86b70bf52fb7affa6322ab3.tar.gz
luaevent-prosody-2e7ed3132883509ef86b70bf52fb7affa6322ab3.zip
event_callback.c: Don't delete and re-add the event if the timeout hasn't changedHEADorigin/mastermaster
Diffstat (limited to 'src')
-rw-r--r--src/event_callback.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/event_callback.c b/src/event_callback.c
index 1bf18ec..1ffe684 100644
--- a/src/event_callback.c
+++ b/src/event_callback.c
@@ -22,7 +22,7 @@ void luaevent_callback(int fd, short event, void* p) {
le_callback* cb = p;
lua_State* L;
int ret;
- double newTimeout = -1;
+ struct timeval new_tv = { 0, 0 };
assert(cb);
if(!cb->base)
return; /* Event has already been collected + destroyed */
@@ -34,13 +34,11 @@ void luaevent_callback(int fd, short event, void* p) {
if(!cb->base)
return; /* event was destroyed during callback */
ret = lua_tointeger(L, -2);
- if(lua_isnumber(L, -1)) {
- newTimeout = lua_tonumber(L, -1);
- if(newTimeout <= 0) {
- memset(&cb->timeout, 0, sizeof(cb->timeout));
- } else {
- load_timeval(newTimeout, &cb->timeout);
- }
+ if(lua_isnumber(L, -1))
+ {
+ double newTimeout = lua_tonumber(L, -1);
+ if(newTimeout>0)
+ load_timeval(newTimeout, &new_tv);
}
lua_pop(L, 2);
if(ret == -1) {
@@ -48,9 +46,10 @@ void luaevent_callback(int fd, short event, void* p) {
} else {
struct event *ev = &cb->ev;
int newEvent = ret;
- /* NOTE: Currently, even if new timeout is the same as the old, a new event is setup regardless... */
- if(newEvent != event || newTimeout != -1) { // Need to hook up new event...
+ if( newEvent != event || (cb->timeout.tv_sec != new_tv.tv_sec || cb->timeout.tv_usec != new_tv.tv_usec) )
+ {
struct timeval *ptv = &cb->timeout;
+ cb->timeout = new_tv;
if(!cb->timeout.tv_sec && !cb->timeout.tv_usec)
ptv = NULL;
event_del(ev);