From 5b3f4f59112aeb4c91806103c487ca3148b63486 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 18 May 2014 13:27:05 +1000 Subject: Clean up the server startup and connection a bit. --- src/extantz/extantz.c | 40 +++++++++++++++++----------------------- src/libraries/SledjHamr.c | 19 +++++++++---------- src/love/love.c | 46 +++++++++++++++++++--------------------------- 3 files changed, 45 insertions(+), 60 deletions(-) diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c index 74a0c58..ff418c0 100644 --- a/src/extantz/extantz.c +++ b/src/extantz/extantz.c @@ -19,7 +19,7 @@ static Eina_Bool _add(void *data, int type, Ecore_Con_Event_Server_Add *ev) { globals *ourGlobals = data; - PI("Server connected."); + PI("Connected to love server."); ourGlobals->server = ev->server; if (ourGlobals->LSLGuiMess) ourGlobals->LSLGuiMess->server = ourGlobals->server; if (ourGlobals->purkle) ourGlobals->purkle->server = ourGlobals->server; @@ -104,32 +104,29 @@ static Eina_Bool _data(void *data, int type, Ecore_Con_Event_Server_Data *ev) return ECORE_CALLBACK_RENEW; } -// Forward declare a circular reference. -static Eina_Bool _del(void *data, int type, Ecore_Con_Event_Server_Del *ev); - -static Eina_Bool _serverDelTimer(void *data) -{ - globals *ourGlobals = data; - - ourGlobals->server = reachOut("127.0.0.1", 8211 + 1, ourGlobals, (Ecore_Event_Handler_Cb) _add, (Ecore_Event_Handler_Cb) _data, (Ecore_Event_Handler_Cb) _del); - return ECORE_CALLBACK_CANCEL; -} - static Eina_Bool _del(void *data, int type, Ecore_Con_Event_Server_Del *ev) { globals *ourGlobals = data; + static int count = 0; + + ourGlobals->server = NULL; - if (ev->server) + // Let it fail a couple of times during startup, then try to start our own love server. + count++; + if (1 < count) { - ecore_con_server_del(ev->server); - ourGlobals->server = NULL; - if (ourGlobals->running) - { - PW("Server dropped out, trying to reconnect."); - ecore_timer_add(1.0, _serverDelTimer, ourGlobals); - } + char buf[PATH_MAX]; + + PW("Failed to connect to a world server, starting our own."); + + // TODO - Should use Ecore_Exe for this sort of thing. + sprintf(buf, "%s/love &", elm_app_bin_dir_get()); + system(buf); + count = 0; } + if (ourGlobals->running) + return ECORE_CALLBACK_RENEW; return ECORE_CALLBACK_CANCEL; } @@ -576,9 +573,6 @@ EAPI_MAIN int elm_main(int argc, char **argv) logDom = loggingStartup("extantz", logDom); ourGlobals.running = 1; - // TODO - Should use Ecore_Exe for this sort of thing. - sprintf(buf, "%s/love &", elm_app_bin_dir_get()); - system(buf); // Don't do this, we need to clean up other stuff to, so set a clean up function below. //elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); diff --git a/src/libraries/SledjHamr.c b/src/libraries/SledjHamr.c index 26df012..7fcede7 100644 --- a/src/libraries/SledjHamr.c +++ b/src/libraries/SledjHamr.c @@ -16,18 +16,10 @@ static Eina_Bool _add(void *data, int type, Ecore_Con_Event_Server_Del *ev) { struct _conct *this = data; - ecore_event_handler_del(this->add); - ecore_event_handler_del(this->del); - if (this->addCb) - { - ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, this->addCb, this->pointer); this->addCb(this->pointer, type, ev); - } if (this->dataCb) ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, this->dataCb, this->pointer); - if (this->delCb) - ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, this->delCb, this->pointer); return ECORE_CALLBACK_RENEW; } @@ -44,11 +36,18 @@ static Eina_Bool _del(void *data, int type, Ecore_Con_Event_Server_Del *ev) { struct _conct *this = data; - printf("FAILED to connect to server %s:%d, trying again in a second!\n", this->address, this->port); + printf("FAILED connection to server %s:%d, trying again in a second!\n", this->address, this->port); ecore_event_handler_del(this->add); ecore_event_handler_del(this->del); + + if (this->delCb) + { + if (ECORE_CALLBACK_RENEW == this->delCb(this->pointer, type, ev)) + ecore_timer_add(1.0, _delTimer, this); + } + if (ev->server) ecore_con_server_del(ev->server); - ecore_timer_add(1.0, _delTimer, this); + return ECORE_CALLBACK_CANCEL; } diff --git a/src/love/love.c b/src/love/love.c index 257d957..91c9d95 100644 --- a/src/love/love.c +++ b/src/love/love.c @@ -472,37 +472,33 @@ static Eina_Bool _dataLuaSL(void *data, int type, Ecore_Con_Event_Server_Data *e return ECORE_CALLBACK_RENEW; } -// Forward declare a circular reference. -static Eina_Bool _delLuaSL(void *data, int type, Ecore_Con_Event_Server_Del *ev); - -static Eina_Bool _serverDelTimer(void *data) +static Eina_Bool _delLuaSL(void *data, int type, Ecore_Con_Event_Server_Del *ev) { gameGlobals *ourGlobals = data; + static int count = 0; - ourGlobals->serverLuaSL = reachOut("127.0.0.1", 8211, ourGlobals, (Ecore_Event_Handler_Cb) _addLuaSL, (Ecore_Event_Handler_Cb) _dataLuaSL, (Ecore_Event_Handler_Cb) _delLuaSL); - return ECORE_CALLBACK_CANCEL; -} + ourGlobals->serverLuaSL = NULL; -static Eina_Bool _delLuaSL(void *data, int type, Ecore_Con_Event_Server_Del *ev) -{ - gameGlobals *ourGlobals = data; + // Let it fail a couple of times during startup, then try to start our own script server. + count++; + if (1 < count) + { + char buf[PATH_MAX]; - if (ev->server) - { - ecore_con_server_del(ev->server); - ourGlobals->serverLuaSL = NULL; - if (!ourGlobals->ui) - ecore_main_loop_quit(); - else - { - PW("Server dropped out, trying to reconnect."); - ecore_timer_add(1.0, _serverDelTimer, ourGlobals); - } - } + PW("Failed to connect to a script server, starting our own."); + sprintf(buf, "%s/LuaSL &", PACKAGE_BIN_DIR); + system(buf); + count = 0; + } + // TODO - May want to renew even if it's not running the GUI, but then we still need some sort of "shut down" signal, which we don't need during testing. +// if (ourGlobals->ui) return ECORE_CALLBACK_RENEW; -} +// ecore_main_loop_quit(); + +// return ECORE_CALLBACK_CANCEL; +} static Eina_Bool _addClient(void *data, int type, Ecore_Con_Event_Client_Add *ev) { @@ -606,10 +602,6 @@ int main(int argc, char **argv) char *programName = argv[0]; boolean badArgs = FALSE; int result = EXIT_FAILURE; - char buf[PATH_MAX]; - - sprintf(buf, "%s/LuaSL &", PACKAGE_BIN_DIR); - system(buf); memset(&ourGlobals, 0, sizeof(gameGlobals)); ourGlobals.address = "127.0.0.1"; -- cgit v1.1