From fb9708cbb37e0454196f262a75122f986fffa62e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Mon, 4 Apr 2011 20:58:15 +0200 Subject: Fixed assertion failure in Sluift. diff --git a/Sluift/Examples/Wonderland.lua b/Sluift/Examples/Wonderland.lua new file mode 100755 index 0000000..cf79371 --- /dev/null +++ b/Sluift/Examples/Wonderland.lua @@ -0,0 +1,52 @@ +-- +-- Copyright (c) 2011 Remko Tronçon +-- Licensed under the GNU General Public License v3. +-- See Documentation/Licenses/GPLv3.txt for more information. +-- + +-- This script creates the wonderland world example. +-- + +require "sluift" +--sluift.debug = true + +characters = { + {jid = "alice@wonderland.lit", name = "Alice", groups = {}, presence = ""}, + {jid = "hatter@wonderland.lit", name = "Mad Hatter", groups = {}, presence = "awayAt the Tea Party"}, + {jid ="queen@wonderland.lit", name = "Queen of Hearts", groups = {}, presence = "dndExecuting"}, + {jid = "rabbit@wonderland.lit", name = "White Rabbit", groups = {"Animals"}, presence = "Oh dear!"}, + {jid = "turtle@wonderland.lit", name = "Mock Turtle", groups = {"Animals"}, presence = ""}, +} + +clients = {} +for _, character in ipairs(characters) do + print("Connecting " .. character["name"] .. "...") + client = sluift.new_client(character["jid"], os.getenv("SLUIFT_PASS")) + client:set_options({compress = false, tls = false}) + client:connect() + client:get_contacts() + client:send(character["presence"]) + table.insert(clients, client) + for _, contact in ipairs(characters) do + if contact["jid"] ~= character["jid"] then + client:add_contact(contact) + end + end +end + +print("Confirming subscriptions") +for _, client in ipairs(clients) do + for _, contact in ipairs(characters) do + client:confirm_subscription(contact["jid"]) + end +end + +print("Done. Waiting ...") +while true do + for _, client in ipairs(clients) do + client:for_event(function(e) + if e["type"] == "message" then client:send_message(e["from"], "Off with their heads!") end + end, 1000) + end + sluift.sleep(1000) +end diff --git a/Sluift/sluift.cpp b/Sluift/sluift.cpp index 0545089..49cfec4 100644 --- a/Sluift/sluift.cpp +++ b/Sluift/sluift.cpp @@ -137,11 +137,14 @@ class SluiftClient { if (watchdog.getTimedOut() || !client->isActive()) { return Stanza::ref(); } - else { + else if (!pendingEvents.empty()) { Stanza::ref event = pendingEvents.front(); pendingEvents.pop_front(); return event; } + else { + return Stanza::ref(); + } } std::vector getRoster() { -- cgit v0.10.2-6-g49f6