From 8dc65d54d2c422690852b8bc7d0b7d35ca4582bc Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Wed, 14 May 2014 09:02:51 +1000 Subject: Starting up and closing down the servers gets some love. Needs more love. --- killem.sh | 20 +++++++++++ lib/LSL.lua | 2 +- src/LuaSL/LuaSL_main.c | 22 ++++++++++-- src/extantz/extantz.c | 3 +- src/love/love.c | 95 +++++++++++++++++++------------------------------- 5 files changed, 77 insertions(+), 65 deletions(-) create mode 100755 killem.sh diff --git a/killem.sh b/killem.sh new file mode 100755 index 0000000..de67db3 --- /dev/null +++ b/killem.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +ps aux | grep love +ps aux | grep LuaSL + +killall -TERM love +sleep 1 +killall -TERM LuaSL +sleep 1 + +ps aux | grep love +ps aux | grep LuaSL + +killall -KILL love +sleep 1 +killall -KILL LuaSL +sleep 1 + +ps aux | grep love +ps aux | grep LuaSL diff --git a/lib/LSL.lua b/lib/LSL.lua index 662c880..3b5ba89 100644 --- a/lib/LSL.lua +++ b/lib/LSL.lua @@ -771,7 +771,7 @@ function LSL.mainLoop(sid, name, x) LSL.stateChange(x); waitAndProcess(false) - msg("Script quitting.") + msg("LSL.Lua: Script quitting.") end function waitAndProcess(returnWanted) diff --git a/src/LuaSL/LuaSL_main.c b/src/LuaSL/LuaSL_main.c index f02c5bf..bfa8728 100644 --- a/src/LuaSL/LuaSL_main.c +++ b/src/LuaSL/LuaSL_main.c @@ -255,14 +255,16 @@ int main(int argc, char **argv) if ((ourGlobals.server = ecore_con_server_add(ECORE_CON_REMOTE_TCP, ourGlobals.address, ourGlobals.port, &ourGlobals))) { int i; + Eina_Iterator *scripts; + script *me; ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, (Ecore_Event_Handler_Cb) _add, &ourGlobals); ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA, (Ecore_Event_Handler_Cb) _data, &ourGlobals); ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, (Ecore_Event_Handler_Cb) _del, &ourGlobals); ecore_con_server_timeout_set(ourGlobals.server, 0); ecore_con_server_client_limit_set(ourGlobals.server, -1, 0); - ecore_con_server_timeout_set(ourGlobals.server, 10); - ecore_con_server_client_limit_set(ourGlobals.server, 3, 0); +// ecore_con_server_timeout_set(ourGlobals.server, 10); +// ecore_con_server_client_limit_set(ourGlobals.server, 3, 0); clientStream = eina_strbuf_new(); result = 0; @@ -274,8 +276,21 @@ int main(int argc, char **argv) PE("Error creating luaproc worker thread."); } ecore_main_loop_begin(); + PD("Fell out of the main loop."); - // TODO - this is what hangs the system, should change from raw pthreads to ecore threads. + scripts = eina_hash_iterator_data_new(ourGlobals.scripts); + while(eina_iterator_next(scripts, (void **) &me)) + { + const char *status = NULL; + + status = sendToChannel(&ourGlobals, me->SID, "quit()"); + if (status) + PE("Error sending command quit() to script %s : %s", me->SID, status); + } + + PD("Finished quitting scripts."); + // TODO - This is what hangs the system, should change from raw pthreads to ecore threads. + // Or perhaps just run the main loop for a bit longer so all the scripts can quit? sched_join_workerthreads(); } else @@ -292,6 +307,7 @@ int main(int argc, char **argv) else fprintf(stderr, "Failed to init eina!"); + PD("Falling out of main()"); return result; } diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c index 7fce3a3..848bc9a 100644 --- a/src/extantz/extantz.c +++ b/src/extantz/extantz.c @@ -76,8 +76,8 @@ static Eina_Bool _del(void *data, int type, Ecore_Con_Event_Server_Del *ev) if (ev->server) { + ecore_con_server_del(ourGlobals->server); ourGlobals->server = NULL; - ecore_con_server_del(ev->server); } return ECORE_CALLBACK_RENEW; @@ -633,6 +633,7 @@ EAPI_MAIN int elm_main(int argc, char **argv) // Try to connect to the love server we started before. ourGlobals.address = "127.0.0.1"; ourGlobals.port = 8211; + sleep(2); if ((ourGlobals.server = ecore_con_server_connect(ECORE_CON_REMOTE_TCP, ourGlobals.address, ourGlobals.port + 1, &ourGlobals))) { ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb) _add, &ourGlobals); diff --git a/src/love/love.c b/src/love/love.c index 4d78a8c..e30c292 100644 --- a/src/love/love.c +++ b/src/love/love.c @@ -59,7 +59,7 @@ static int scriptCount = 0; static int compiledCount = 0; static float compileTime = 0.0; static struct timeval startTime; -static int timedEvent = 0; +//static int timedEvent = 0; static char *ownerKey = "12345678-1234-4321-abcd-0123456789ab"; static char *ownerName = "onefang rejected"; @@ -176,58 +176,14 @@ static void dirList_compile(const char *name, const char *path, void *data) static Eina_Bool _timer_cb(void *data) { - gameGlobals *ourGlobals = data; - Eina_Iterator *scripts; - script *me; - boolean exit = FALSE; - char buf[PATH_MAX]; - - if (5 == timedEvent) - { - gettimeofday(&startTime, NULL); - snprintf(buf, sizeof(buf), "%s/Test sim/objects", PACKAGE_DATA_DIR); - eina_file_dir_list(buf, EINA_TRUE, dirList_compile, ourGlobals); - } - - if (5 >= timedEvent) - { - timedEvent++; - return ECORE_CALLBACK_RENEW; - } +// gameGlobals *ourGlobals = data; + char buf[PATH_MAX]; - scripts = eina_hash_iterator_data_new(ourGlobals->scripts); - while(eina_iterator_next(scripts, (void **) &me)) - { - switch (timedEvent) - { - case 10 : - { - sendForth(ourGlobals->serverLuaSL, me->SID, "events.detectedKeys({\"%s\"})", ownerKey); - sendForth(ourGlobals->serverLuaSL, me->SID, "events.detectedNames({\"%s\"})", ownerName); - sendForth(ourGlobals->serverLuaSL, me->SID, "events.touch_start(1)"); - break; - } - case 15 : - { - sendForth(ourGlobals->serverLuaSL, me->SID, "quit()"); - break; - } - case 20 : - { - exit = TRUE; - break; - } - } - } - timedEvent++; + gettimeofday(&startTime, NULL); + snprintf(buf, sizeof(buf), "%s/Test sim/objects", PACKAGE_DATA_DIR); + eina_file_dir_list(buf, EINA_TRUE, dirList_compile, data); - if (exit) - { - sendForth(ourGlobals->serverLuaSL, ownerKey, "exit()"); - ecore_main_loop_quit(); - return ECORE_CALLBACK_CANCEL; - } - return ECORE_CALLBACK_RENEW; + return ECORE_CALLBACK_CANCEL; } static Eina_Bool _addLuaSL(void *data, int type, Ecore_Con_Event_Server_Add *ev) @@ -235,8 +191,8 @@ static Eina_Bool _addLuaSL(void *data, int type, Ecore_Con_Event_Server_Add *ev) gameGlobals *ourGlobals = data; ourGlobals->serverLuaSL = ev->server; - // Wait a while, then start sending events for testing. - ecore_timer_add(0.5, _timer_cb, ourGlobals); + // Wait a while before compiling and running scripts. + ecore_timer_add(3.0, _timer_cb, ourGlobals); return ECORE_CALLBACK_RENEW; } @@ -397,8 +353,6 @@ static Eina_Bool _delLuaSL(void *data, int type, Ecore_Con_Event_Server_Del *ev) if (ev->server) { - ourGlobals->serverLuaSL = NULL; - ecore_con_server_del(ev->server); if (!ourGlobals->ui) ecore_main_loop_quit(); } @@ -507,13 +461,27 @@ static Eina_Bool _dataClient(void *data, int type, Ecore_Con_Event_Client_Data * static Eina_Bool _delClient(void *data, int type, Ecore_Con_Event_Client_Del *ev) { -// gameGlobals *ourGlobals = data; + gameGlobals *ourGlobals = data; if (ev->client) { - PD("No more clients, exiting."); + Eina_List const *clients; ecore_con_client_del(ev->client); - ecore_main_loop_quit(); + + // This is only really for testing, normally it just runs 24/7, or until told to. + clients = ecore_con_server_clients_get(ourGlobals->server); + if (0 == eina_list_count(clients)) + { + PD("No more clients, exiting."); + sendForth(ourGlobals->serverLuaSL, ownerKey, "exit()"); + ecore_main_loop_quit(); + } + else + { + PD("Some %d more clients, exiting anyway.", eina_list_count(clients)); + sendForth(ourGlobals->serverLuaSL, ownerKey, "exit()"); + ecore_main_loop_quit(); + } } return ECORE_CALLBACK_RENEW; } @@ -527,6 +495,9 @@ int main(int argc, char **argv) int result = EXIT_FAILURE; char buf[PATH_MAX]; +// TODO - Just a temporary kill command until I can fix the LuaSL hanging on exit bug. +system("killall -KILL LuaSL"); +sleep(2); sprintf(buf, "%s/LuaSL &", PACKAGE_BIN_DIR); system(buf); sleep(1); @@ -558,8 +529,6 @@ int main(int argc, char **argv) ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, (Ecore_Event_Handler_Cb) _delClient, &ourGlobals); ecore_con_server_timeout_set(ourGlobals.server, 0); ecore_con_server_client_limit_set(ourGlobals.server, -1, 0); - ecore_con_server_timeout_set(ourGlobals.server, 10); - ecore_con_server_client_limit_set(ourGlobals.server, 3, 0); clientStream = eina_strbuf_new(); @@ -675,6 +644,11 @@ int main(int argc, char **argv) } ecore_main_loop_begin(); + PD("Fell out of the main loop"); + + ecore_con_server_del(ourGlobals.server); + ecore_con_server_del(ourGlobals.serverLuaSL); + if (ourGlobals.ui) { ecore_animator_del(ani); @@ -706,5 +680,6 @@ int main(int argc, char **argv) else fprintf(stderr, "Failed to init eina!"); + PD("Falling out of main()"); return result; } -- cgit v1.1