summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/LinkLocal/LinkLocalConnector.cpp')
-rw-r--r--Swiften/LinkLocal/LinkLocalConnector.cpp34
1 files changed, 21 insertions, 13 deletions
diff --git a/Swiften/LinkLocal/LinkLocalConnector.cpp b/Swiften/LinkLocal/LinkLocalConnector.cpp
index 18b5d6a..fba4a4e 100644
--- a/Swiften/LinkLocal/LinkLocalConnector.cpp
+++ b/Swiften/LinkLocal/LinkLocalConnector.cpp
@@ -12,22 +12,22 @@
namespace Swift {
LinkLocalConnector::LinkLocalConnector(
- const JID& remoteJID,
- const String& hostname,
- int interfaceIndex,
- int port,
+ const LinkLocalService& service,
boost::shared_ptr<DNSSDQuerier> querier,
boost::shared_ptr<Connection> connection) :
- remoteJID(remoteJID),
- hostname(hostname),
- interfaceIndex(interfaceIndex),
- port(port),
+ service(service),
querier(querier),
connection(connection) {
}
+LinkLocalConnector::~LinkLocalConnector() {
+ assert(!resolveQuery);
+}
+
void LinkLocalConnector::connect() {
- resolveQuery = querier->createResolveHostnameQuery(hostname, interfaceIndex);
+ resolveQuery = querier->createResolveHostnameQuery(
+ service.getHostname(),
+ service.getID().getNetworkInterfaceID());
resolveQuery->onHostnameResolved.connect(boost::bind(
&LinkLocalConnector::handleHostnameResolved,
boost::dynamic_pointer_cast<LinkLocalConnector>(shared_from_this()),
@@ -35,16 +35,24 @@ void LinkLocalConnector::connect() {
resolveQuery->run();
}
+void LinkLocalConnector::cancel() {
+ if (resolveQuery) {
+ resolveQuery->finish();
+ }
+ resolveQuery.reset();
+ connection->disconnect();
+}
+
void LinkLocalConnector::handleHostnameResolved(const boost::optional<HostAddress>& address) {
+ resolveQuery->finish();
+ resolveQuery.reset();
if (address) {
- resolveQuery->finish();
- resolveQuery.reset();
connection->onConnectFinished.connect(
boost::bind(boost::ref(onConnectFinished), _1));
- connection->connect(HostAddressPort(*address, port));
+ connection->connect(HostAddressPort(*address, service.getPort()));
}
else {
- onConnectFinished(false);
+ onConnectFinished(true);
}
}