summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-06-18 16:34:04 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-06-18 16:34:04 (GMT)
commitc31ab7f87ea33b4e1de2ae28c3c9e5263de23b77 (patch)
treed849f6bf26774e08601c860801a815bdf31c5bfe /Swiften
parented0dbffeb8a3b36965d359c8a689bdb41372e481 (diff)
parent7d0e9c3d963ffcb3f7d6d313dfa55466beb742b9 (diff)
downloadswift-contrib-c31ab7f87ea33b4e1de2ae28c3c9e5263de23b77.zip
swift-contrib-c31ab7f87ea33b4e1de2ae28c3c9e5263de23b77.tar.bz2
Merge branch 'swift-1.x'
* swift-1.x: Small tweaks to the previous patch. Added ConnectionServerFactory. Conflicts: Swiften/Network/SConscript
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Network/BoostConnectionServer.cpp11
-rw-r--r--Swiften/Network/BoostConnectionServer.h10
-rw-r--r--Swiften/Network/BoostConnectionServerFactory.cpp23
-rw-r--r--Swiften/Network/BoostConnectionServerFactory.h29
-rw-r--r--Swiften/Network/BoostNetworkFactories.cpp3
-rw-r--r--Swiften/Network/BoostNetworkFactories.h5
-rw-r--r--Swiften/Network/ConnectionServer.h4
-rw-r--r--Swiften/Network/ConnectionServerFactory.cpp14
-rw-r--r--Swiften/Network/ConnectionServerFactory.h23
-rw-r--r--Swiften/Network/NetworkFactories.h2
-rw-r--r--Swiften/Network/SConscript2
11 files changed, 123 insertions, 3 deletions
diff --git a/Swiften/Network/BoostConnectionServer.cpp b/Swiften/Network/BoostConnectionServer.cpp
index 9b2ed0d..eccffc6 100644
--- a/Swiften/Network/BoostConnectionServer.cpp
+++ b/Swiften/Network/BoostConnectionServer.cpp
@@ -17,13 +17,22 @@ namespace Swift {
BoostConnectionServer::BoostConnectionServer(int port, boost::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) : port_(port), ioService_(ioService), eventLoop(eventLoop), acceptor_(NULL) {
}
+BoostConnectionServer::BoostConnectionServer(const HostAddress &address, int port, boost::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) : address_(address), port_(port), ioService_(ioService), eventLoop(eventLoop), acceptor_(NULL) {
+}
void BoostConnectionServer::start() {
try {
assert(!acceptor_);
- acceptor_ = new boost::asio::ip::tcp::acceptor(
+ if (address_.isValid()) {
+ acceptor_ = new boost::asio::ip::tcp::acceptor(
+ *ioService_,
+ boost::asio::ip::tcp::endpoint(address_.getRawAddress(), port_));
+ }
+ else {
+ acceptor_ = new boost::asio::ip::tcp::acceptor(
*ioService_,
boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port_));
+ }
acceptNextConnection();
}
catch (const boost::system::system_error& e) {
diff --git a/Swiften/Network/BoostConnectionServer.h b/Swiften/Network/BoostConnectionServer.h
index 3e9e1e0..56dc8bd 100644
--- a/Swiften/Network/BoostConnectionServer.h
+++ b/Swiften/Network/BoostConnectionServer.h
@@ -30,8 +30,12 @@ namespace Swift {
return ref(new BoostConnectionServer(port, ioService, eventLoop));
}
- void start();
- void stop();
+ static ref create(const HostAddress &address, int port, boost::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) {
+ return ref(new BoostConnectionServer(address, port, ioService, eventLoop));
+ }
+
+ virtual void start();
+ virtual void stop();
virtual HostAddressPort getAddressPort() const;
@@ -39,12 +43,14 @@ namespace Swift {
private:
BoostConnectionServer(int port, boost::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop);
+ BoostConnectionServer(const HostAddress &address, int port, boost::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop);
void stop(boost::optional<Error> e);
void acceptNextConnection();
void handleAccept(boost::shared_ptr<BoostConnection> newConnection, const boost::system::error_code& error);
private:
+ HostAddress address_;
int port_;
boost::shared_ptr<boost::asio::io_service> ioService_;
EventLoop* eventLoop;
diff --git a/Swiften/Network/BoostConnectionServerFactory.cpp b/Swiften/Network/BoostConnectionServerFactory.cpp
new file mode 100644
index 0000000..04c614e
--- /dev/null
+++ b/Swiften/Network/BoostConnectionServerFactory.cpp
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2011 Jan Kaluza
+ * Licensed under the Simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swiften/Network/BoostConnectionServerFactory.h>
+#include <Swiften/Network/BoostConnectionServer.h>
+
+namespace Swift {
+
+BoostConnectionServerFactory::BoostConnectionServerFactory(boost::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop) : ioService(ioService), eventLoop(eventLoop) {
+}
+
+boost::shared_ptr<ConnectionServer> BoostConnectionServerFactory::createConnectionServer(int port) {
+ return BoostConnectionServer::create(port, ioService, eventLoop);
+}
+
+boost::shared_ptr<ConnectionServer> BoostConnectionServerFactory::createConnectionServer(const Swift::HostAddress &hostAddress, int port) {
+ return BoostConnectionServer::create(hostAddress, port, ioService, eventLoop);
+}
+
+}
diff --git a/Swiften/Network/BoostConnectionServerFactory.h b/Swiften/Network/BoostConnectionServerFactory.h
new file mode 100644
index 0000000..9132b5c
--- /dev/null
+++ b/Swiften/Network/BoostConnectionServerFactory.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2011 Jan Kaluza
+ * Licensed under the Simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <boost/asio/io_service.hpp>
+
+#include <Swiften/Network/ConnectionServerFactory.h>
+#include <Swiften/Network/BoostConnectionServer.h>
+
+namespace Swift {
+ class ConnectionServer;
+
+ class BoostConnectionServerFactory : public ConnectionServerFactory {
+ public:
+ BoostConnectionServerFactory(boost::shared_ptr<boost::asio::io_service>, EventLoop* eventLoop);
+
+ virtual boost::shared_ptr<ConnectionServer> createConnectionServer(int port);
+
+ virtual boost::shared_ptr<ConnectionServer> createConnectionServer(const Swift::HostAddress &hostAddress, int port);
+
+ private:
+ boost::shared_ptr<boost::asio::io_service> ioService;
+ EventLoop* eventLoop;
+ };
+}
diff --git a/Swiften/Network/BoostNetworkFactories.cpp b/Swiften/Network/BoostNetworkFactories.cpp
index 92cbdb8..cc80197 100644
--- a/Swiften/Network/BoostNetworkFactories.cpp
+++ b/Swiften/Network/BoostNetworkFactories.cpp
@@ -8,6 +8,7 @@
#include <Swiften/Network/BoostTimerFactory.h>
#include <Swiften/Network/BoostConnectionFactory.h>
#include <Swiften/Network/PlatformDomainNameResolver.h>
+#include <Swiften/Network/BoostConnectionServerFactory.h>
namespace Swift {
@@ -15,9 +16,11 @@ BoostNetworkFactories::BoostNetworkFactories(EventLoop* eventLoop) {
timerFactory = new BoostTimerFactory(ioServiceThread.getIOService(), eventLoop);
connectionFactory = new BoostConnectionFactory(ioServiceThread.getIOService(), eventLoop);
domainNameResolver = new PlatformDomainNameResolver(eventLoop);
+ connectionServerFactory = new BoostConnectionServerFactory(ioServiceThread.getIOService(), eventLoop);
}
BoostNetworkFactories::~BoostNetworkFactories() {
+ delete connectionServerFactory;
delete domainNameResolver;
delete connectionFactory;
delete timerFactory;
diff --git a/Swiften/Network/BoostNetworkFactories.h b/Swiften/Network/BoostNetworkFactories.h
index abb155c..96bcc6c 100644
--- a/Swiften/Network/BoostNetworkFactories.h
+++ b/Swiften/Network/BoostNetworkFactories.h
@@ -33,10 +33,15 @@ namespace Swift {
return domainNameResolver;
}
+ ConnectionServerFactory* getConnectionServerFactory() const {
+ return connectionServerFactory;
+ }
+
private:
BoostIOServiceThread ioServiceThread;
TimerFactory* timerFactory;
ConnectionFactory* connectionFactory;
DomainNameResolver* domainNameResolver;
+ ConnectionServerFactory* connectionServerFactory;
};
}
diff --git a/Swiften/Network/ConnectionServer.h b/Swiften/Network/ConnectionServer.h
index b19dbf6..00703a4 100644
--- a/Swiften/Network/ConnectionServer.h
+++ b/Swiften/Network/ConnectionServer.h
@@ -19,6 +19,10 @@ namespace Swift {
virtual HostAddressPort getAddressPort() const = 0;
+ virtual void start() = 0;
+
+ virtual void stop() = 0;
+
boost::signal<void (boost::shared_ptr<Connection>)> onNewConnection;
};
}
diff --git a/Swiften/Network/ConnectionServerFactory.cpp b/Swiften/Network/ConnectionServerFactory.cpp
new file mode 100644
index 0000000..3c59001
--- /dev/null
+++ b/Swiften/Network/ConnectionServerFactory.cpp
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2011 Jan Kaluza
+ * Licensed under the Simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swiften/Network/ConnectionServerFactory.h>
+
+namespace Swift {
+
+ConnectionServerFactory::~ConnectionServerFactory() {
+}
+
+}
diff --git a/Swiften/Network/ConnectionServerFactory.h b/Swiften/Network/ConnectionServerFactory.h
new file mode 100644
index 0000000..df5f912
--- /dev/null
+++ b/Swiften/Network/ConnectionServerFactory.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2011 Jan Kaluza
+ * Licensed under the Simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+namespace Swift {
+ class ConnectionServer;
+ class HostAddress;
+
+ class ConnectionServerFactory {
+ public:
+ virtual ~ConnectionServerFactory();
+
+ virtual boost::shared_ptr<ConnectionServer> createConnectionServer(int port) = 0;
+
+ virtual boost::shared_ptr<ConnectionServer> createConnectionServer(const Swift::HostAddress& hostAddress, int port) = 0;
+ };
+}
diff --git a/Swiften/Network/NetworkFactories.h b/Swiften/Network/NetworkFactories.h
index b4400bd..d0d2299 100644
--- a/Swiften/Network/NetworkFactories.h
+++ b/Swiften/Network/NetworkFactories.h
@@ -10,6 +10,7 @@ namespace Swift {
class TimerFactory;
class ConnectionFactory;
class DomainNameResolver;
+ class ConnectionServerFactory;
/**
* An interface collecting network factories.
@@ -21,5 +22,6 @@ namespace Swift {
virtual TimerFactory* getTimerFactory() const = 0;
virtual ConnectionFactory* getConnectionFactory() const = 0;
virtual DomainNameResolver* getDomainNameResolver() const = 0;
+ virtual ConnectionServerFactory* getConnectionServerFactory() const = 0;
};
}
diff --git a/Swiften/Network/SConscript b/Swiften/Network/SConscript
index 183d09c..965361b 100644
--- a/Swiften/Network/SConscript
+++ b/Swiften/Network/SConscript
@@ -13,9 +13,11 @@ sourceList = [
"BoostConnection.cpp",
"BoostConnectionFactory.cpp",
"BoostConnectionServer.cpp",
+ "BoostConnectionServerFactory.cpp",
"BoostIOServiceThread.cpp",
"ConnectionFactory.cpp",
"ConnectionServer.cpp",
+ "ConnectionServerFactory.cpp",
"DummyConnection.cpp",
"FakeConnection.cpp",
"ChainedConnector.cpp",