From 2575f4cbf0124aa21568f76a243980c679587759 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 27 Nov 2009 01:33:55 +0000 Subject: event_callback: Fix stack slot leak --- src/event_callback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/event_callback.c b/src/event_callback.c index 76a7789..b1cdd02 100644 --- a/src/event_callback.c +++ b/src/event_callback.c @@ -43,7 +43,7 @@ void luaevent_callback(int fd, short event, void* p) { load_timeval(newTimeout, &cb->timeout); } } - lua_pop(L, 1); + lua_pop(L, 2); if(ret == -1) { freeCallbackArgs(cb, L); } else { -- cgit v1.2.3 From 7eb84245607020b20fcf83404a7e4e93fc0a3f89 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 6 Dec 2009 01:10:59 +0000 Subject: Add base:loopexit() method --- src/luaevent.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/luaevent.c b/src/luaevent.c index c9b5430..71188a6 100644 --- a/src/luaevent.c +++ b/src/luaevent.c @@ -89,9 +89,18 @@ static int luaevent_loop(lua_State* L) { return 1; } +static int luaevent_loopexit(lua_State*L) { + le_base *base = event_base_get(L, 1); + struct timeval tv = { 0, 10 }; + int ret = event_base_loopexit(base->base, &tv); + lua_pushinteger(L, ret); + return 1; +} + static luaL_Reg base_funcs[] = { { "addevent", luaevent_addevent }, { "loop", luaevent_loop }, + { "loopexit", luaevent_loopexit }, { NULL, NULL } }; -- cgit v1.2.3 From b797f511efc3843cf32d62f907f1cfa08fca3828 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 7 Dec 2009 21:36:31 +0000 Subject: base:loopexit(): Support for specifying the timeout before exit --- src/luaevent.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/luaevent.c b/src/luaevent.c index 71188a6..550a386 100644 --- a/src/luaevent.c +++ b/src/luaevent.c @@ -91,7 +91,9 @@ static int luaevent_loop(lua_State* L) { static int luaevent_loopexit(lua_State*L) { le_base *base = event_base_get(L, 1); - struct timeval tv = { 0, 10 }; + struct timeval tv = { 0, 0 }; + if(lua_gettop(L) >= 2) /* Optional timeout before exiting the loop */ + load_timeval(luaL_checknumber(L, 2), &tv); int ret = event_base_loopexit(base->base, &tv); lua_pushinteger(L, ret); return 1; -- cgit v1.2.3 From bfd0058b760fb75ae466aa9049e9428645363a65 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 7 Dec 2009 21:44:00 +0000 Subject: Add base:method() to return string identifying the current libevent backend in use --- src/luaevent.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/luaevent.c b/src/luaevent.c index 550a386..0c5c37b 100644 --- a/src/luaevent.c +++ b/src/luaevent.c @@ -99,10 +99,17 @@ static int luaevent_loopexit(lua_State*L) { return 1; } +static int luaevent_method(lua_State* L) { + le_base *base = event_base_get(L, 1); + lua_pushstring(L, event_base_get_method(base->base)); + return 1; +} + static luaL_Reg base_funcs[] = { { "addevent", luaevent_addevent }, { "loop", luaevent_loop }, { "loopexit", luaevent_loopexit }, + { "method", luaevent_method }, { NULL, NULL } }; -- cgit v1.2.3 From 2506ebf1e52bdd83007b0463f0a02ea1d6062be8 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 7 Dec 2009 22:40:03 +0000 Subject: Add core.libevent_version() function to get version of libevent in use --- src/luaevent.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/luaevent.c b/src/luaevent.c index 0c5c37b..8a682df 100644 --- a/src/luaevent.c +++ b/src/luaevent.c @@ -29,6 +29,11 @@ int luaevent_newbase(lua_State* L) { return 1; } +int luaevent_libevent_version(lua_State* L) { + lua_pushstring(L, event_get_version()); + return 1; +} + static int luaevent_base_gc(lua_State* L) { le_base *base = event_base_get(L, 1); if(base->base) { @@ -115,6 +120,7 @@ static luaL_Reg base_funcs[] = { static luaL_Reg funcs[] = { { "new", luaevent_newbase }, + { "libevent_version", luaevent_libevent_version }, { NULL, NULL } }; -- cgit v1.2.3 From 890f155ec2f62c0512de28c16c86c2660b129e08 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 7 Dec 2009 22:48:43 +0000 Subject: Fix potential stack slot leak when error occurs --- src/buffer_event.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/buffer_event.c b/src/buffer_event.c index 4e20353..0b956cf 100644 --- a/src/buffer_event.c +++ b/src/buffer_event.c @@ -49,7 +49,12 @@ static void handle_callback(le_bufferevent* le_ev, short what, int callbackIndex /* func, bufferevent */ lua_pushinteger(L, what); /* What to do w/ errors...? */ - lua_pcall(L, 2, 0, 0); + if(!lua_pcall(L, 2, 0, 0)) + { + /* FIXME: Perhaps luaevent users should be + * able to set an error handler? */ + lua_pop(L, 1); /* Pop error message */ + } } static void buffer_event_readcb(struct bufferevent *ev, void *ptr) { -- cgit v1.2.3 From 5435cbb46fc3456a32fe7527c42e6c7419ceccc1 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 9 Dec 2009 00:34:39 +0000 Subject: base:addevent(): Accept integer as fd parameter --- src/luaevent.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/luaevent.c b/src/luaevent.c index 8a682df..a8d5f7d 100644 --- a/src/luaevent.c +++ b/src/luaevent.c @@ -45,14 +45,18 @@ static int luaevent_base_gc(lua_State* L) { int getSocketFd(lua_State* L, int idx) { int fd; - luaL_checktype(L, idx, LUA_TUSERDATA); - lua_getfield(L, idx, "getfd"); - if(lua_isnil(L, -1)) - return luaL_error(L, "Socket type missing 'getfd' method"); - lua_pushvalue(L, idx); - lua_call(L, 1, 1); - fd = lua_tointeger(L, -1); - lua_pop(L, 1); + if(lua_isnumber(L, idx)) { + fd = lua_tonumber(L, idx); + } else { + luaL_checktype(L, idx, LUA_TUSERDATA); + lua_getfield(L, idx, "getfd"); + if(lua_isnil(L, -1)) + return luaL_error(L, "Socket type missing 'getfd' method"); + lua_pushvalue(L, idx); + lua_call(L, 1, 1); + fd = lua_tointeger(L, -1); + lua_pop(L, 1); + } return fd; } -- cgit v1.2.3 From 2129e6154e3b48ef9568242af5d74c990c55dd6f Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Mon, 15 Feb 2010 06:22:58 +0500 Subject: luaevent.c: Make ANSI C compatible. --- src/luaevent.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/luaevent.c b/src/luaevent.c index a8d5f7d..19fb7d6 100644 --- a/src/luaevent.c +++ b/src/luaevent.c @@ -91,19 +91,21 @@ static int luaevent_addevent(lua_State* L) { } static int luaevent_loop(lua_State* L) { + int ret; le_base *base = event_base_get(L, 1); base->loop_L = L; - int ret = event_base_loop(base->base, 0); + ret = event_base_loop(base->base, 0); lua_pushinteger(L, ret); return 1; } static int luaevent_loopexit(lua_State*L) { + int ret; le_base *base = event_base_get(L, 1); struct timeval tv = { 0, 0 }; if(lua_gettop(L) >= 2) /* Optional timeout before exiting the loop */ load_timeval(luaL_checknumber(L, 2), &tv); - int ret = event_base_loopexit(base->base, &tv); + ret = event_base_loopexit(base->base, &tv); lua_pushinteger(L, ret); return 1; } -- cgit v1.2.3 From 59333212814d8de493295e2a19b046bed81d9a09 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Mon, 15 Feb 2010 06:26:34 +0500 Subject: buffer_event.c, event_buffer.c, luaevent.c: Remove redundant #includes. --- src/buffer_event.c | 1 - src/event_buffer.c | 1 - src/luaevent.c | 6 ------ 3 files changed, 8 deletions(-) (limited to 'src') diff --git a/src/buffer_event.c b/src/buffer_event.c index 0b956cf..deb1963 100644 --- a/src/buffer_event.c +++ b/src/buffer_event.c @@ -1,7 +1,6 @@ /* LuaEvent - Copyright (C) 2007 Thomas Harning * Licensed as LGPL - See doc/COPYING for details */ #include "buffer_event.h" -#include "luaevent.h" #include "utility.h" #include #include diff --git a/src/event_buffer.c b/src/event_buffer.c index 62dc0e3..23e28c4 100644 --- a/src/event_buffer.c +++ b/src/event_buffer.c @@ -2,7 +2,6 @@ * Licensed as LGPL - See doc/COPYING for details */ #include "event_buffer.h" -#include "luaevent.h" #include #include diff --git a/src/luaevent.c b/src/luaevent.c index 19fb7d6..06b84c5 100644 --- a/src/luaevent.c +++ b/src/luaevent.c @@ -1,21 +1,15 @@ /* LuaEvent - Copyright (C) 2007 Thomas Harning * Licensed as LGPL - See doc/COPYING for details */ -#include "luaevent.h" #include "event_callback.h" #include "event_buffer.h" #include "buffer_event.h" -#include #include #include #define EVENT_BASE_MT "EVENT_BASE_MT" -#ifdef _WIN32 -#include -#endif - le_base* event_base_get(lua_State* L, int idx) { return (le_base*)luaL_checkudata(L, idx, EVENT_BASE_MT); } -- cgit v1.2.3 From 5f7ea0a8dac6e279d4f15153f4833df1793a9c74 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 15 Feb 2010 14:15:36 +0000 Subject: event_buffer.c: Silence warnings about uninitialized variable 'ret' --- src/event_buffer.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/event_buffer.c b/src/event_buffer.c index 23e28c4..ea66a94 100644 --- a/src/event_buffer.c +++ b/src/event_buffer.c @@ -200,6 +200,7 @@ static int event_buffer_write(lua_State* L) { } else if(lua_isuserdata(L, 2)) { ret = evbuffer_write(buf->buffer, getSocketFd(L, 2)); } else { + ret = 0; /* Shush uninitialized warning */ luaL_argerror(L, 2, "Unexpected data type. Expects: integer/lightuserdata/socket"); } lua_pushinteger(L, ret); @@ -221,6 +222,7 @@ static int event_buffer_read(lua_State* L) { } else if(lua_isuserdata(L, 2)) { ret = evbuffer_read(buf->buffer, getSocketFd(L, 2), len); } else { + ret = 0; /* Shush uninitialized warning */ luaL_argerror(L, 2, "Unexpected data type. Expects: integer/lightuserdata/socket"); } lua_pushinteger(L, ret); -- cgit v1.2.3 From dcf2339cc6e5820b0c8345475329ff53151a5945 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 15 Feb 2010 14:16:55 +0000 Subject: luaevent.c: Fix for backwards-compatibility with 1.3 --- src/luaevent.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/luaevent.c b/src/luaevent.c index 06b84c5..6036cf1 100644 --- a/src/luaevent.c +++ b/src/luaevent.c @@ -7,6 +7,7 @@ #include #include +#include #define EVENT_BASE_MT "EVENT_BASE_MT" @@ -105,8 +106,13 @@ static int luaevent_loopexit(lua_State*L) { } static int luaevent_method(lua_State* L) { + #ifdef _EVENT_VERSION le_base *base = event_base_get(L, 1); - lua_pushstring(L, event_base_get_method(base->base)); + if(strcmp(_EVENT_VERSION, "1.3")<0) + lua_pushstring(L, event_base_get_method(base->base)); + else + #endif + lua_pushstring(L, event_get_method()); return 1; } -- cgit v1.2.3