summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-03-17 18:45:13 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-03-17 18:45:13 (GMT)
commit45b3444328fc495c4a5a7d05d3dcaa6116585e41 (patch)
tree9439fbb1342f48985f276b287522cb5a401aeb87
parentb8d6b9483febcb2cd76e685e23754fc346e9ef52 (diff)
downloadswift-contrib-45b3444328fc495c4a5a7d05d3dcaa6116585e41.zip
swift-contrib-45b3444328fc495c4a5a7d05d3dcaa6116585e41.tar.bz2
Sluift: Spin the event loop on send events.
-rw-r--r--Sluift/sluift.cpp43
1 files changed, 32 insertions, 11 deletions
diff --git a/Sluift/sluift.cpp b/Sluift/sluift.cpp
index 66167b3..0223556 100644
--- a/Sluift/sluift.cpp
+++ b/Sluift/sluift.cpp
@@ -117,10 +117,10 @@ class SluiftClient {
return event;
}
Watchdog watchdog(timeout, networkFactories.getTimerFactory());
- while (!watchdog.getTimedOut() && pendingEvents.empty()) {
+ while (!watchdog.getTimedOut() && pendingEvents.empty() && !client->isActive()) {
eventLoop.runUntilEvents();
}
- if (watchdog.getTimedOut()) {
+ if (watchdog.getTimedOut() || !client->isActive()) {
return Stanza::ref();
}
else {
@@ -317,15 +317,29 @@ static int sluift_client_get_version(lua_State *L) {
}
static int sluift_client_send_message(lua_State *L) {
- getClient(L)->sendMessage(std::string(luaL_checkstring(L, 2)), luaL_checkstring(L, 3));
- lua_pushvalue(L, 1);
- return 1;
+ try {
+ eventLoop.runOnce();
+
+ getClient(L)->sendMessage(std::string(luaL_checkstring(L, 2)), luaL_checkstring(L, 3));
+ lua_pushvalue(L, 1);
+ return 1;
+ }
+ catch (const SluiftException& e) {
+ return luaL_error(L, e.getReason().c_str());
+ }
}
static int sluift_client_send_presence(lua_State *L) {
- getClient(L)->sendPresence(std::string(luaL_checkstring(L, 2)));
- lua_pushvalue(L, 1);
- return 0;
+ try {
+ eventLoop.runOnce();
+
+ getClient(L)->sendPresence(std::string(luaL_checkstring(L, 2)));
+ lua_pushvalue(L, 1);
+ return 0;
+ }
+ catch (const SluiftException& e) {
+ return luaL_error(L, e.getReason().c_str());
+ }
}
static int sluift_client_get(lua_State *L) {
@@ -371,9 +385,16 @@ static int sluift_client_set(lua_State *L) {
}
static int sluift_client_send(lua_State *L) {
- getClient(L)->getClient()->sendData(std::string(luaL_checkstring(L, 2)));
- lua_pushvalue(L, 1);
- return 0;
+ try {
+ eventLoop.runOnce();
+
+ getClient(L)->getClient()->sendData(std::string(luaL_checkstring(L, 2)));
+ lua_pushvalue(L, 1);
+ return 0;
+ }
+ catch (const SluiftException& e) {
+ return luaL_error(L, e.getReason().c_str());
+ }
}
static int sluift_client_set_options(lua_State* L) {