summaryrefslogtreecommitdiffstats
path: root/Sluift
diff options
context:
space:
mode:
Diffstat (limited to 'Sluift')
-rw-r--r--Sluift/SluiftClient.cpp18
-rw-r--r--Sluift/SluiftClient.h4
-rw-r--r--Sluift/client.cpp6
3 files changed, 18 insertions, 10 deletions
diff --git a/Sluift/SluiftClient.cpp b/Sluift/SluiftClient.cpp
index 9db8969..d2b1beb 100644
--- a/Sluift/SluiftClient.cpp
+++ b/Sluift/SluiftClient.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013-2014 Isode Limited.
+ * Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -125,13 +125,21 @@ boost::optional<SluiftClient::Event> SluiftClient::getNextEvent(
}
}
-std::vector<XMPPRosterItem> SluiftClient::getRoster() {
+std::vector<XMPPRosterItem> SluiftClient::getRoster(int timeout) {
+ Watchdog watchdog(timeout, networkFactories->getTimerFactory());
if (!rosterReceived) {
// If we haven't requested it yet, request it for the first time
client->requestRoster();
- }
- while (!rosterReceived) {
- eventLoop->runUntilEvents();
+
+ // Wait for new events
+ while (!watchdog.getTimedOut() && !rosterReceived) {
+ eventLoop->runUntilEvents();
+ }
+
+ // Throw an error if we're timed out
+ if (watchdog.getTimedOut()) {
+ throw Lua::Exception("Timeout while requesting roster");
+ }
}
return client->getRoster()->getItems();
}
diff --git a/Sluift/SluiftClient.h b/Sluift/SluiftClient.h
index b7a6578..68c4b61 100644
--- a/Sluift/SluiftClient.h
+++ b/Sluift/SluiftClient.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013 Isode Limited.
+ * Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -103,7 +103,7 @@ namespace Swift {
void setSoftwareVersion(const std::string& name, const std::string& version, const std::string& os);
boost::optional<SluiftClient::Event> getNextEvent(int timeout,
boost::function<bool (const Event&)> condition = 0);
- std::vector<XMPPRosterItem> getRoster();
+ std::vector<XMPPRosterItem> getRoster(int timeout);
private:
Sluift::Response doSendRequest(boost::shared_ptr<Request> request, int timeout);
diff --git a/Sluift/client.cpp b/Sluift/client.cpp
index 8f6ff3a..6373a20 100644
--- a/Sluift/client.cpp
+++ b/Sluift/client.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013-2015 Isode Limited.
+ * Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -186,7 +186,7 @@ SLUIFT_LUA_FUNCTION_WITH_HELP(
SluiftClient* client = getClient(L);
Lua::Table contactsTable;
- foreach(const XMPPRosterItem& item, client->getRoster()) {
+ foreach(const XMPPRosterItem& item, client->getRoster(getGlobalTimeout(L))) {
std::string subscription;
switch(item.getSubscription()) {
case RosterItemPayload::None: subscription = "none"; break;
@@ -636,7 +636,7 @@ SLUIFT_LUA_FUNCTION_WITH_HELP(
item.setJID(Lua::checkString(L, 2));
}
- client->getRoster();
+ client->getRoster(timeout);
if (!client->getClient()->getRoster()->containsJID(item.getJID())) {
RosterPayload::ref roster = boost::make_shared<RosterPayload>();
roster->addItem(item);