diff options
author | Christian Pointner <equinox@helsinki.at> | 2011-03-08 18:07:24 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2011-03-08 18:07:24 (GMT) |
commit | aa50ae92057db36e033b157bbe393d6c7df9fc05 (patch) | |
tree | 1c1d9469d625784f7e038d4c445eaf72055a2587 /nopsyncd/nopsyncd.c | |
parent | 914ee9d782bdd514058bf90ed118523a252bcc02 (diff) |
added pipe between worker threads
Diffstat (limited to 'nopsyncd/nopsyncd.c')
-rw-r--r-- | nopsyncd/nopsyncd.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/nopsyncd/nopsyncd.c b/nopsyncd/nopsyncd.c index b8907ee..d478b18 100644 --- a/nopsyncd/nopsyncd.c +++ b/nopsyncd/nopsyncd.c @@ -22,12 +22,15 @@ #include <stdlib.h> #include <stdio.h> #include <errno.h> +#include <string.h> #include <pthread.h> #include <lua.h> #include <lualib.h> #include <lauxlib.h> +#include "l_pipe.h" + #define LUA_MAIN_LOOP_FUNC "main_loop" static const luaL_Reg nopsyncd_lualibs[] = { @@ -36,6 +39,7 @@ static const luaL_Reg nopsyncd_lualibs[] = { {LUA_TABLIBNAME, luaopen_table}, {LUA_STRLIBNAME, luaopen_string}, {LUA_MATHLIBNAME, luaopen_math}, + {LUA_MATHLIBNAME, luaopen_pipe}, {NULL, NULL} }; @@ -114,6 +118,8 @@ void* main_loop(void* file) if(!ret) ret = call_main_loop(L, (char*)file); + printf("%s returned with %d\n", (char*)file, ret); + lua_close(L); pthread_exit(NULL); @@ -125,7 +131,13 @@ int main(int argc, char* argv[]) pthread_t qlistener, tcpserver; - int ret = pthread_create(&qlistener, NULL, main_loop, "qlistener.lua"); + int ret = pipe_init(); + if(ret) { + fprintf(stderr, "Error creating pipe: %s\n", strerror(errno)); + return 1; + } + + ret = pthread_create(&qlistener, NULL, main_loop, "qlistener.lua"); if(ret) { fprintf(stderr, "Error creating qlistener thread (code: %d)\n", ret); return 1; @@ -140,6 +152,13 @@ int main(int argc, char* argv[]) pthread_join(qlistener, NULL); pthread_join(tcpserver, NULL); + ret = pipe_close(); + if(ret) { + fprintf(stderr, "Error destroying pipe: %s\n", strerror(errno)); + return 1; + } + + printf("stopping nopsyncd.\n"); return 0; } |