summaryrefslogtreecommitdiffstats
path: root/Sluift
diff options
context:
space:
mode:
Diffstat (limited to 'Sluift')
-rw-r--r--Sluift/sluift.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/Sluift/sluift.cpp b/Sluift/sluift.cpp
index 0223556..458c44d 100644
--- a/Sluift/sluift.cpp
+++ b/Sluift/sluift.cpp
@@ -29,7 +29,8 @@ using namespace Swift;
* Forward declarations
******************************************************************************/
-bool debug = false;
+static bool debug = false;
+static int globalTimeout = 30000;
/*******************************************************************************
* Helper classes
@@ -68,9 +69,14 @@ class SluiftClient {
}
void waitConnected() {
- while (client->isActive() && !client->isAvailable()) {
+ Watchdog watchdog(globalTimeout, networkFactories.getTimerFactory());
+ while (!watchdog.getTimedOut() && client->isActive() && !client->isAvailable()) {
eventLoop.runUntilEvents();
}
+ if (watchdog.getTimedOut()) {
+ client->disconnect();
+ throw SluiftException("Timeout while connecting");
+ }
}
bool isConnected() const {
@@ -694,22 +700,30 @@ static int sluift_sleep(lua_State *L) {
}
static int sluift_index(lua_State *L) {
- luaL_checkstring(L, 2);
- if (std::string(lua_tostring(L, 2)) == "debug") {
+ std::string key(luaL_checkstring(L, 2));
+ if (key == "debug") {
lua_pushboolean(L, debug);
return 1;
}
+ else if (key == "timeout") {
+ lua_pushnumber(L, globalTimeout);
+ return 1;
+ }
else {
return luaL_error(L, "Invalid index");
}
}
static int sluift_newindex(lua_State *L) {
- luaL_checkstring(L, 2);
- if (std::string(lua_tostring(L, 2)) == "debug") {
+ std::string key(luaL_checkstring(L, 2));
+ if (key == "debug") {
debug = lua_toboolean(L, 3);
return 0;
}
+ else if (key == "timeout") {
+ globalTimeout = luaL_checknumber(L, 3);
+ return 0;
+ }
else {
return luaL_error(L, "Invalid index");
}