summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2010-12-19 17:37:17 +0000
committerChristian Pointner <equinox@spreadspace.org>2010-12-19 17:37:17 +0000
commit3235cbde1936856791e1f79ea5cc2853be025a61 (patch)
tree74962cde66ff4d879614a3420896585f3fb810d1
parentloading comamnds and response table form file (diff)
updated TODO
timer values allow + and - now git-svn-id: https://svn.spreadspace.org/gcsd/trunk@71 ac14a137-c7f1-4531-abe0-07747231d213
-rw-r--r--TODO15
-rw-r--r--src/command_queue.lua2
-rw-r--r--src/l_timer.c50
3 files changed, 41 insertions, 26 deletions
diff --git a/TODO b/TODO
index 691ad33..04ef741 100644
--- a/TODO
+++ b/TODO
@@ -1,8 +1,13 @@
- * input modules
- - stdio
- - tcp
- * out-of-order response
- * command & response dispatch table
+ * send response to requestor
+ * out-of-order responses
+ * finish API for command & response dispatch tables
+ * add listener tables (for requests, responses and other messages)
* module loader cleanup (no require)
* module API etc. clean-up, finalize, freeze
* config-parser
+ * check max instances at modules (instance counter)
+ * add modules
+ - tcp
+ - udp
+ - unix
+ - inotify
diff --git a/src/command_queue.lua b/src/command_queue.lua
index 6bfd3d6..c91f9a7 100644
--- a/src/command_queue.lua
+++ b/src/command_queue.lua
@@ -77,7 +77,7 @@ function command_queue:command_sent()
self.current.sent = true
if(self.current.timeout) then
- self.current.expiration_time = timer.add(timer.now(), self.current.timeout)
+ self.current.expiration_time = timer.now() + self.current.timeout
end
if(self.current.expected_response) then
return self.current.expected_response
diff --git a/src/l_timer.c b/src/l_timer.c
index 129fd13..f510e22 100644
--- a/src/l_timer.c
+++ b/src/l_timer.c
@@ -35,19 +35,35 @@
#include <sys/time.h>
#include <string.h>
-#include <stdio.h>
#include <errno.h>
#include "l_timer.h"
-#define LUA_TIMER_UDATA_NAME "struct timeval"
+typedef struct timeval timer_t;
+#define LUA_TIMER_UDATA_NAME "timer_t"
+
+static int l_timer_add(lua_State *L);
+static int l_timer_sub(lua_State *L);
+
+static timer_t* newtimerudata(lua_State *L)
+{
+ timer_t* tv = (timer_t*)lua_newuserdata(L, sizeof(timer_t));
+ if(luaL_newmetatable(L, LUA_TIMER_UDATA_NAME)) {
+ lua_pushliteral(L, "__add");
+ lua_pushcfunction(L, l_timer_add);
+ lua_settable(L, -3);
+ lua_pushliteral(L, "__sub");
+ lua_pushcfunction(L, l_timer_sub);
+ lua_settable(L, -3);
+ }
+ lua_setmetatable(L, -2);
+ return tv;
+}
static int l_timer_new(lua_State *L)
{
int ms = luaL_optint(L, 1, 0);
- struct timeval* tv = (struct timeval*)lua_newuserdata(L, sizeof(struct timeval));
- luaL_newmetatable(L, LUA_TIMER_UDATA_NAME);
- lua_setmetatable(L, -2);
+ timer_t* tv = newtimerudata(L);
tv->tv_sec = ms/1000;
tv->tv_usec = (ms%1000)*1000;
return 1;
@@ -55,44 +71,38 @@ static int l_timer_new(lua_State *L)
static int l_timer_now(lua_State *L)
{
- struct timeval* now = (struct timeval*)lua_newuserdata(L, sizeof(struct timeval));
+ timer_t* now = newtimerudata(L);
int ret = gettimeofday(now, NULL);
if(ret) {
lua_pushnil(L);
lua_pushstring(L, strerror(errno)); // FIXXXXXME: strerror is not threadsafe!!!
return 2;
}
- luaL_newmetatable(L, LUA_TIMER_UDATA_NAME);
- lua_setmetatable(L, -2);
return 1;
}
static int l_timer_add(lua_State *L)
{
- struct timeval* a = (struct timeval*)luaL_checkudata(L, 1, LUA_TIMER_UDATA_NAME);
- struct timeval* b = (struct timeval*)luaL_checkudata(L, 2, LUA_TIMER_UDATA_NAME);
- struct timeval* res = (struct timeval*)lua_newuserdata(L, sizeof(struct timeval));
- luaL_newmetatable(L, LUA_TIMER_UDATA_NAME);
- lua_setmetatable(L, -2);
+ timer_t* a = (timer_t*)luaL_checkudata(L, 1, LUA_TIMER_UDATA_NAME);
+ timer_t* b = (timer_t*)luaL_checkudata(L, 2, LUA_TIMER_UDATA_NAME);
+ timer_t* res = newtimerudata(L);
timeradd(a, b, res);
return 1;
}
static int l_timer_sub(lua_State *L)
{
- struct timeval* a = (struct timeval*)luaL_checkudata(L, 1, LUA_TIMER_UDATA_NAME);
- struct timeval* b = (struct timeval*)luaL_checkudata(L, 2, LUA_TIMER_UDATA_NAME);
- struct timeval* res = (struct timeval*)lua_newuserdata(L, sizeof(struct timeval));
- luaL_newmetatable(L, LUA_TIMER_UDATA_NAME);
- lua_setmetatable(L, -2);
+ timer_t* a = (timer_t*)luaL_checkudata(L, 1, LUA_TIMER_UDATA_NAME);
+ timer_t* b = (timer_t*)luaL_checkudata(L, 2, LUA_TIMER_UDATA_NAME);
+ timer_t* res = newtimerudata(L);
timersub(a, b, res);
return 1;
}
static int l_timer_cmp(lua_State *L)
{
- struct timeval* a = (struct timeval*)luaL_checkudata(L, 1, LUA_TIMER_UDATA_NAME);
- struct timeval* b = (struct timeval*)luaL_checkudata(L, 2, LUA_TIMER_UDATA_NAME);
+ timer_t* a = (timer_t*)luaL_checkudata(L, 1, LUA_TIMER_UDATA_NAME);
+ timer_t* b = (timer_t*)luaL_checkudata(L, 2, LUA_TIMER_UDATA_NAME);
if(timercmp(a, b, <))
lua_pushinteger(L, -1);
else if(timercmp(a, b, >))